bourse stock
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.2 KiB

If you need to write plugin only for simple task, write a **script** using ScriptsPlugin.
## Using plugins
Plugins are loaded using **plugin** method from phpQueryObject or phpQuery static namespace.
```
// all calls to plugin below are equal
phpQuery::plugin('example')
phpQuery::plugin('example', 'example.php')
pq('ul')->plugin('example')
pq('ul')->plugin('example', 'example.php')
```
## Writing plugins
Plugin consist from 2 classes - first extending **phpQueryObjects** (result of pq(); function) and second, extending static **phpQuery::$plugins** namespace. Plugin classes are never intialized, just method calls are forwarded in static way from phpQuery.
#### Extending phpQueryObject
```
/**
* phpQuery plugin class extending phpQuery object.
* Methods from this class are callable on every phpQuery object.
*
* Class name prefix 'phpQueryObjectPlugin_' must be preserved.
*/
abstract class phpQueryObjectPlugin_example {
/**
* Limit binded methods.
*
* null means all public.
* array means only specified ones.
*
* @var array|null
*/
public static $phpQueryMethods = null;
/**
* Enter description here...
*
* @param phpQueryObject $self
*/
public static function example($self, $arg1) {
// this method can be called on any phpQuery object, like this:
// pq('div')->example('$arg1 Value')
// do something
$self->append('Im just an example !');
// change stack of result object
return $self->find('div');
}
protected static function helperFunction() {
// this method WONT be avaible as phpQuery method,
// because it isn't publicly callable
}
}
```
#### Extending phpQuery
```
/**
* phpQuery plugin class extending phpQuery static namespace.
* Methods from this class are callable as follows:
* phpQuery::$plugins->staticMethod()
*
* Class name prefix 'phpQueryPlugin_' must be preserved.
*/
abstract class phpQueryPlugin_example {
/**
* Limit binded methods.
*
* null means all public.
* array means only specified ones.
*
* @var array|null
*/
public static $phpQueryMethods = null;
public static function staticMethod() {
// this method can be called within phpQuery class namespace, like this:
// phpQuery::$plugins->staticMethod()
}
}
```