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