12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace yii\base;
- class Behavior extends BaseObject
- {
-
- public $owner;
-
- public function events()
- {
- return [];
- }
-
- public function attach($owner)
- {
- $this->owner = $owner;
- foreach ($this->events() as $event => $handler) {
- $owner->on($event, is_string($handler) ? [$this, $handler] : $handler);
- }
- }
-
- public function detach()
- {
- if ($this->owner) {
- foreach ($this->events() as $event => $handler) {
- $this->owner->off($event, is_string($handler) ? [$this, $handler] : $handler);
- }
- $this->owner = null;
- }
- }
- }
|