Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  * @throws Exception\InvalidArgumentException
  */
 public function setTarget($target)
 {
     if (!$target instanceof ModelInterface) {
         throw new Exception\InvalidArgumentException(sprintf('"%s" works only with ModelInterface targets', __CLASS__));
     }
     return parent::setTarget($target);
 }
Exemplo n.º 2
0
 public function setTarget($target)
 {
     if ($target instanceof FormInterface || $target instanceof Container) {
         $this->setForm($target);
     }
     return parent::setTarget($target);
 }
Exemplo n.º 3
0
 public function setTarget($test)
 {
     if (!$test instanceof TestInterface) {
         $what = is_object($test) ? 'object of class ' . get_class($test) : gettype($test);
         throw new InvalidArgumentException('Cannot use ' . $what . ' as a target for the test');
     }
     return parent::setTarget($test);
 }
Exemplo n.º 4
0
 /**
  * Create Annotation
  *
  * @param  array $annotationData
  * @return false|\stdClass
  */
 public function createAnnotation(array $annotationData)
 {
     $event = new Event();
     $event->setName(self::EVENT_CREATE_ANNOTATION);
     $event->setTarget($this);
     $event->setParams(array('class' => $annotationData[0], 'content' => $annotationData[1], 'raw' => $annotationData[2]));
     $results = $this->getEventManager()->trigger($event, function ($r) {
         return is_object($r);
     });
     $annotation = $results->last();
     return is_object($annotation) ? $annotation : false;
 }
Exemplo n.º 5
0
 /**
  * Triggers the specified event on the defined context and return a concateneted string with the results
  * @param string $eventName
  * @param mixed $target
  * @param array $argv
  * @return string
  */
 public function triggerEvent($eventName, $target, $argv)
 {
     //init the event with the target, params and name
     $event = new Event();
     $event->setTarget($target);
     $event->setParams($argv);
     $event->setName($eventName);
     $content = "";
     //trigger the event listeners
     $responses = $this->events()->trigger($eventName, $event);
     //merge all results and return the response
     foreach ($responses as $response) {
         $content .= $response;
     }
     return $content;
 }
Exemplo n.º 6
0
 /**
  * Triggers the specified event on the defined context and return a concateneted string with the results
  *
  * @param string $eventName
  * @param mixed $target
  * @param array $argv
  * @return string
  */
 public function __invoke($eventName, $target, $argv)
 {
     $alias = 'zfc-twig';
     if (strpos($eventName, ':') !== false) {
         $aux = explode(':', $eventName);
         $alias = $aux[0];
         $eventName = $aux[1];
     }
     //init the event with the target, params and name
     $event = new Event();
     $event->setTarget($target);
     $event->setParams($argv);
     $event->setName($eventName);
     $content = "";
     //trigger the event listeners
     $responses = $this->events($alias)->trigger($eventName, $event);
     //merge all results and return the response
     foreach ($responses as $response) {
         $content .= $response;
     }
     return $content;
 }
Exemplo n.º 7
0
 public function testTriggerCanTakeAnOptionalCallbackArgumentToEmulateTriggerUntil()
 {
     $this->events->attach(__FUNCTION__, function ($e) {
         return $e;
     });
     // Four scenarios:
     // First: normal signature:
     $responses = $this->events->trigger(__FUNCTION__, $this, array(), function ($r) {
         return $r instanceof EventInterface;
     });
     $this->assertTrue($responses->stopped());
     // Second: Event as $argv parameter:
     $event = new Event();
     $responses = $this->events->trigger(__FUNCTION__, $this, $event, function ($r) {
         return $r instanceof EventInterface;
     });
     $this->assertTrue($responses->stopped());
     // Third: Event as $target parameter:
     $event = new Event();
     $event->setTarget($this);
     $responses = $this->events->trigger(__FUNCTION__, $event, function ($r) {
         return $r instanceof EventInterface;
     });
     $this->assertTrue($responses->stopped());
     // Fourth: Event as $event parameter:
     $event = new Event();
     $event->setTarget($this);
     $event->setName(__FUNCTION__);
     $responses = $this->events->trigger($event, function ($r) {
         return $r instanceof EventInterface;
     });
     $this->assertTrue($responses->stopped());
 }
Exemplo n.º 8
0
 /**
  * Is this session valid?
  *
  * Notifies the Validator Chain until either all validators have returned
  * true or one has failed.
  *
  * @return bool
  */
 public function isValid()
 {
     $validator = $this->getValidatorChain();
     $event = new Event();
     $event->setName('session.validate');
     $event->setTarget($this);
     $event->setParams($this);
     $falseResult = function ($test) {
         return false === $test;
     };
     $responses = $validator->triggerEventUntil($falseResult, $event);
     if ($responses->stopped()) {
         // If execution was halted, validation failed
         return false;
     }
     // Otherwise, we're good to go
     return true;
 }
Exemplo n.º 9
0
 public function testOnBootstrap()
 {
     $applicationEventManager = new EventManager();
     $application = $this->getMock(ApplicationInterface::class);
     $application->expects($this->any())->method('getEventManager')->will($this->returnValue($applicationEventManager));
     $event = new Event();
     $event->setTarget($application);
     $module = new Module();
     $module->onBootstrap($event);
     $this->assertListenerAtPriority([$module, 'onDispatch'], -9999999, MvcEvent::EVENT_DISPATCH, $applicationEventManager);
     $this->assertListenerAtPriority([$module, 'onDispatch'], -9999999, MvcEvent::EVENT_DISPATCH_ERROR, $applicationEventManager);
 }
Exemplo n.º 10
0
 /**
  * Determine if an element is marked to exclude from the definitions
  *
  * @param  AnnotationCollection $annotations
  * @return true|false
  */
 protected function checkForExclude($annotations)
 {
     $event = new Event();
     $event->setName(__FUNCTION__);
     $event->setTarget($this);
     $event->setParams(['annotations' => $annotations]);
     $results = $this->getEventManager()->triggerEventUntil(function ($r) {
         return true === $r;
     }, $event);
     return (bool) $results->last();
 }
Exemplo n.º 11
0
 public function testOnBootstrap()
 {
     $applicationEventManager = new EventManager();
     $application = $this->getMock('Zend\\Mvc\\ApplicationInterface');
     $application->expects($this->any())->method('getEventManager')->will($this->returnValue($applicationEventManager));
     $event = new Event();
     $event->setTarget($application);
     $module = new Module();
     $module->onBootstrap($event);
     $dispatchListeners = $applicationEventManager->getListeners(MvcEvent::EVENT_DISPATCH);
     foreach ($dispatchListeners as $listener) {
         $metaData = $listener->getMetadata();
         $callback = $listener->getCallback();
         $this->assertEquals('onDispatch', $callback[1]);
         $this->assertEquals(-9999999, $metaData['priority']);
         $this->assertTrue($callback[0] instanceof Module);
     }
     $dispatchListeners = $applicationEventManager->getListeners(MvcEvent::EVENT_DISPATCH_ERROR);
     foreach ($dispatchListeners as $listener) {
         $metaData = $listener->getMetadata();
         $callback = $listener->getCallback();
         $this->assertEquals('onDispatch', $callback[1]);
         $this->assertEquals(-9999999, $metaData['priority']);
         $this->assertTrue($callback[0] instanceof Module);
     }
 }
Exemplo n.º 12
0
 /**
  * Parse a single page into a navigation configuration
  *
  * @param  Page $page
  * @return array
  * @throws Exception\RuntimeException
  */
 public function parsePage(PageInterface $page)
 {
     $meta = $page->getMetaData();
     $navPage = Page::factory(array('type' => 'mvc', 'route' => (string) $page->getId(), 'label' => $meta->getNavigationTitle(), 'visible' => $page->isVisible()));
     $event = new Event();
     $event->setName(__FUNCTION__ . '.' . $page->getModule());
     $event->setTarget($this);
     $event->setParams(array('page' => $page, 'navigation' => $navPage));
     $this->events->trigger($event);
     return $navPage;
 }