1 | <?php |
||
23 | class Behavior extends Object |
||
24 | { |
||
25 | /** |
||
26 | * @var Component the owner of this behavior |
||
27 | */ |
||
28 | public $owner; |
||
29 | |||
30 | |||
31 | /** |
||
32 | * Declares event handlers for the [[owner]]'s events. |
||
33 | * |
||
34 | * Child classes may override this method to declare what PHP callbacks should |
||
35 | * be attached to the events of the [[owner]] component. |
||
36 | * |
||
37 | * The callbacks will be attached to the [[owner]]'s events when the behavior is |
||
38 | * attached to the owner; and they will be detached from the events when |
||
39 | * the behavior is detached from the component. |
||
40 | * |
||
41 | * The callbacks can be any of the following: |
||
42 | * |
||
43 | * - method in this behavior: `'handleClick'`, equivalent to `[$this, 'handleClick']` |
||
44 | * - object method: `[$object, 'handleClick']` |
||
45 | * - static method: `['Page', 'handleClick']` |
||
46 | * - anonymous function: `function ($event) { ... }` |
||
47 | * |
||
48 | * The following is an example: |
||
49 | * |
||
50 | * ```php |
||
51 | * [ |
||
52 | * Model::EVENT_BEFORE_VALIDATE => 'myBeforeValidate', |
||
53 | * Model::EVENT_AFTER_VALIDATE => 'myAfterValidate', |
||
54 | * ] |
||
55 | * ``` |
||
56 | * |
||
57 | * @return array events (array keys) and the corresponding event handler methods (array values). |
||
58 | */ |
||
59 | 14 | public function events() |
|
63 | |||
64 | /** |
||
65 | * Attaches the behavior object to the component. |
||
66 | * The default implementation will set the [[owner]] property |
||
67 | * and attach event handlers as declared in [[events]]. |
||
68 | * Make sure you call the parent implementation if you override this method. |
||
69 | * @param Component $owner the component that this behavior is to be attached to. |
||
70 | */ |
||
71 | 35 | public function attach($owner) |
|
78 | |||
79 | /** |
||
80 | * Detaches the behavior object from the component. |
||
81 | * The default implementation will unset the [[owner]] property |
||
82 | * and detach event handlers declared in [[events]]. |
||
83 | * Make sure you call the parent implementation if you override this method. |
||
84 | */ |
||
85 | 9 | public function detach() |
|
94 | } |
||
95 |