|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Example of PhpQuery plugin. |
|
4
|
|
|
* |
|
5
|
|
|
* Load it like this: |
|
6
|
|
|
* PhpQuery::plugin('example') |
|
7
|
|
|
* PhpQuery::plugin('example', 'example.php') |
|
8
|
|
|
* pq('ul')->plugin('example') |
|
9
|
|
|
* pq('ul')->plugin('example', 'example.php') |
|
10
|
|
|
* |
|
11
|
|
|
* Plugin classes are never intialized, just method calls are forwarded |
|
12
|
|
|
* in static way from PhpQuery. |
|
13
|
|
|
* |
|
14
|
|
|
* Have fun writing plugins :) |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* PhpQuery plugin class extending PhpQuery object. |
|
19
|
|
|
* Methods from this class are callable on every PhpQuery object. |
|
20
|
|
|
* |
|
21
|
|
|
* Class name prefix '\PhpQuery\Plugin\' must be preserved. |
|
22
|
|
|
*/ |
|
23
|
|
|
abstract class PhpQuery_Plugin_example { |
|
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Limit binded methods. |
|
26
|
|
|
* |
|
27
|
|
|
* null means all public. |
|
28
|
|
|
* array means only specified ones. |
|
29
|
|
|
* |
|
30
|
|
|
* @var array|null |
|
31
|
|
|
*/ |
|
32
|
|
|
public static $PhpQueryMethods = null; |
|
33
|
|
|
/** |
|
34
|
|
|
* Enter description here... |
|
35
|
|
|
* |
|
36
|
|
|
* @param \PhpQueryObject $self |
|
37
|
|
|
*/ |
|
38
|
|
|
public static function example($self, $arg1) { |
|
|
|
|
|
|
39
|
|
|
// this method can be called on any PhpQuery object, like this: |
|
40
|
|
|
// pq('div')->example('$arg1 Value') |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
// do something |
|
43
|
|
|
$self->append('Im just an example !'); |
|
44
|
|
|
// change stack of result object |
|
45
|
|
|
return $self->find('div'); |
|
46
|
|
|
} |
|
47
|
|
|
protected static function helperFunction() { |
|
48
|
|
|
// this method WONT be avaible as PhpQuery method, |
|
49
|
|
|
// because it isn't publicly callable |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* PhpQuery plugin class extending PhpQuery static namespace. |
|
55
|
|
|
* Methods from this class are callable as follows: |
|
56
|
|
|
* PhpQuery::$plugins->staticMethod() |
|
57
|
|
|
* |
|
58
|
|
|
* Class name prefix 'PhpQueryPlugin_' must be preserved. |
|
59
|
|
|
*/ |
|
60
|
|
|
abstract class PhpQueryPlugin_example { |
|
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Limit binded methods. |
|
63
|
|
|
* |
|
64
|
|
|
* null means all public. |
|
65
|
|
|
* array means only specified ones. |
|
66
|
|
|
* |
|
67
|
|
|
* @var array|null |
|
68
|
|
|
*/ |
|
69
|
|
|
public static $PhpQueryMethods = null; |
|
70
|
|
|
public static function staticMethod() { |
|
71
|
|
|
// this method can be called within PhpQuery class namespace, like this: |
|
72
|
|
|
// PhpQuery::$plugins->staticMethod() |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.