/** * Tests the event propagation stopping property * * @return void * @triggers fake.event */ public function testPropagation() { $event = new Event('fake.event'); $this->assertFalse($event->isStopped()); $event->stopPropagation(); $this->assertTrue($event->isStopped()); }
/** * Dispatches a new event to all configured listeners * * @param string|\Cake\Event\Event $event the event key name or instance of Event * @return \Cake\Event\Event * @triggers $event */ public function dispatch($event) { if (is_string($event)) { $event = new Event($event); } $listeners = $this->listeners($event->name()); if (empty($listeners)) { return $event; } foreach ($listeners as $listener) { if ($event->isStopped()) { break; } $result = $this->_callListener($listener['callable'], $event); if ($result === false) { $event->stopPropagation(); } if ($result !== null) { $event->result = $result; } } return $event; }
/** * Automatically add the translated validation rules if the event is not stopped * and if the name of the validator is amongst the accepted ones. * * @source http://book.cakephp.org/3.0/en/core-libraries/validation.html#validating-data * * @param \Cake\Event\Event $event Fired when the validator object identified by $name is being built. * @param \Cake\Validation\Validator $validator The validator object * @param string $name The name of the validator oject * @return void */ public function buildValidator(\Cake\Event\Event $event, \Cake\Validation\Validator $validator, $name) { $accepted = $this->config('accepted'); if ($event->isStopped() === false && ($accepted === null || in_array($name, (array) $accepted))) { foreach ($this->getValidationRules() as $validationRule) { call_user_func_array([$validator, 'add'], $validationRule); } } }