mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-14 22:30:27 +08:00
22 lines
376 B
PHP
22 lines
376 B
PHP
<?php
|
|
|
|
$obj = new class () extends \yii\base\Component
|
|
{
|
|
public $foo = 0;
|
|
};
|
|
|
|
$obj->attachBehavior('bar', (new class () extends \yii\base\Behavior
|
|
{
|
|
public function events()
|
|
{
|
|
return [
|
|
'barEventOnce' => function ($event) {
|
|
$this->owner->foo++;
|
|
$this->detach();
|
|
},
|
|
];
|
|
}
|
|
}));
|
|
|
|
return $obj;
|