hasHandlers() публичный статический Метод

Note that this method will also check all parent classes to see if there is any handler attached to the named event.
public static hasHandlers ( string | object $class, string $name ) : boolean
$class string | object the object or the fully qualified class name specifying the class-level event.
$name string the event name.
Результат boolean whether there is any handler attached to the event.
 public function test_MigrationEvent()
 {
     try {
         $this->cleanDb();
         $this->mockYiiApplication();
         \Yii::$app->mycfg->system->version = null;
         // to trigger migration event
         $bootstrap = new MyLibraryBootstrap();
         $bootstrap->bootstrap(\Yii::$app);
         $this->assertTrue(\yii\base\Event::hasHandlers(\app\components\Controller::class, \app\components\Controller::EVENT_BEFORE_ACTION), 'migration event for controller was not added');
     } finally {
         $this->resetConnection();
     }
 }
Пример #2
0
 public function testHasHandlers()
 {
     $this->assertFalse(Event::hasHandlers(Post::className(), 'save'));
     $this->assertFalse(Event::hasHandlers(ActiveRecord::className(), 'save'));
     Event::on(Post::className(), 'save', function ($event) {
         $this->counter += 1;
     });
     $this->assertTrue(Event::hasHandlers(Post::className(), 'save'));
     $this->assertFalse(Event::hasHandlers(ActiveRecord::className(), 'save'));
     $this->assertFalse(Event::hasHandlers(User::className(), 'save'));
     Event::on(ActiveRecord::className(), 'save', function ($event) {
         $this->counter += 1;
     });
     $this->assertTrue(Event::hasHandlers(User::className(), 'save'));
     $this->assertTrue(Event::hasHandlers(ActiveRecord::className(), 'save'));
 }
Пример #3
0
 /**
  * Returns a value indicating whether there is any handler attached to the named event.
  * @param string $name the event name
  * @return boolean whether there is any handler attached to the event.
  */
 public function hasEventHandlers($name)
 {
     $this->ensureBehaviors();
     return !empty($this->_events[$name]) || Event::hasHandlers($this, $name);
 }
Пример #4
0
 /**
  * Returns a value indicating whether there is any handler attached to the named event.
  *
  * 判断 _events 中的一个 event 是否具有 handler
  * @param string $name the event name
  * @return boolean whether there is any handler attached to the event.
  */
 public function hasEventHandlers($name)
 {
     $this->ensureBehaviors();
     // _events 中存在 $name 的 event 或者 $name 的 event 是否含有该对象所在的类的 handler
     return !empty($this->_events[$name]) || Event::hasHandlers($this, $name);
 }
Пример #5
0
 /**
  * Returns a value indicating whether there is any handler attached to the named event.
  * @param string $name the event name
  * @return boolean whether there is any handler attached to the event.
  */
 public function hasEventHandlers($name)
 {
     $this->ensureBehaviors();
     if (!empty($this->_events[$name])) {
         return true;
     } else {
         return Event::hasHandlers($this, $name);
     }
 }