/**
  * Triggers the listeners of an event.
  *
  * This method can be overridden to add functionality that is executed
  * for each listener.
  *
  * @param callable[] $listeners The event listeners.
  * @param string     $eventName The name of the event to dispatch.
  * @param Event      $event     The event object to pass to the event handlers/listeners.
  */
 protected function doDispatch($listeners, $eventName, BaseEvent $event)
 {
     $dispatcher = $this;
     foreach ($listeners as $listener) {
         $parameters = $this->getEventParameters($event);
         $parameters = array_merge(compact('eventName', 'event', 'dispatcher'), $parameters);
         $this->invoker->invoke($listener, $parameters);
         if ($event->isPropagationStopped()) {
             break;
         }
     }
 }
Example #2
0
 /**
  * @dataProvider provideTestInvoke
  */
 public function testInvoke($callable, $parameters = array(), $expectedResult = null, $expectExceptionOnParameter = null)
 {
     try {
         $result = $this->invoker->invoke($callable, $parameters);
     } catch (UnableToMatchParameterException $e) {
         if (!$expectExceptionOnParameter) {
             throw $e;
         }
         $this->assertEquals(UnableToMatchParameterException::formatMessage($callable, $expectExceptionOnParameter), $e->getMessage());
         return;
     }
     if ($expectExceptionOnParameter) {
         $this->fail('A exception of type [\\Nucleus\\Invoker\\UnableToMatchParameterException] should have been thrown');
     }
     $this->assertEquals($expectedResult, $result);
 }
 /**
  * This method should not be called directly
  * 
  * @param string $rule
  * @param array $parameters
  *
  * @return boolean
  */
 public function verifyRule($ruleSpecification, array $parameters)
 {
     list($ruleName, $defaultParameters) = $this->extractRuleNameAndParameters($ruleSpecification);
     $ruleObject = $this->ruleProvider->getRule($ruleName);
     return $this->invoker->invoke($ruleObject, array_merge($defaultParameters, $parameters));
 }