當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Event::setTarget方法代碼示例

本文整理匯總了PHP中Zend\EventManager\Event::setTarget方法的典型用法代碼示例。如果您正苦於以下問題:PHP Event::setTarget方法的具體用法?PHP Event::setTarget怎麽用?PHP Event::setTarget使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend\EventManager\Event的用法示例。


在下文中一共展示了Event::setTarget方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setTarget

 /**
  * {@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);
 }
開發者ID:matryoshka-model,項目名稱:matryoshka,代碼行數:11,代碼來源:ModelEvent.php

示例2: setTarget

 public function setTarget($target)
 {
     if ($target instanceof FormInterface || $target instanceof Container) {
         $this->setForm($target);
     }
     return parent::setTarget($target);
 }
開發者ID:cross-solution,項目名稱:yawik,代碼行數:7,代碼來源:FormEvent.php

示例3: setTarget

 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);
 }
開發者ID:ralfeggert,項目名稱:zftool,代碼行數:8,代碼來源:RunEvent.php

示例4: createAnnotation

 /**
  * 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;
 }
開發者ID:Baft,項目名稱:Zend-Form,代碼行數:18,代碼來源:AnnotationManager.php

示例5: triggerEvent

 /**
  * 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;
 }
開發者ID:rikaix,項目名稱:ZeTwig,代碼行數:23,代碼來源:Extension.php

示例6: __invoke

 /**
  * 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;
 }
開發者ID:2eye-studios,項目名稱:development,代碼行數:30,代碼來源:Trigger.php

示例7: testTriggerCanTakeAnOptionalCallbackArgumentToEmulateTriggerUntil

 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());
 }
開發者ID:pnaq57,項目名稱:zf2demo,代碼行數:33,代碼來源:EventManagerTest.php

示例8: isValid

 /**
  * 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;
 }
開發者ID:zendframework,項目名稱:zend-session,代碼行數:26,代碼來源:SessionManager.php

示例9: testOnBootstrap

 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);
 }
開發者ID:rwoverdijk,項目名稱:assetmanager,代碼行數:12,代碼來源:ModuleTest.php

示例10: checkForExclude

 /**
  * 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();
 }
開發者ID:vbryan,項目名稱:Zend,代碼行數:17,代碼來源:AnnotationBuilder.php

示例11: testOnBootstrap

 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);
     }
 }
開發者ID:gstearmit,項目名稱:EshopVegeTable,代碼行數:26,代碼來源:ModuleTest.php

示例12: parsePage

 /**
  * 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;
 }
開發者ID:i-MSCP,項目名稱:EnsembleKernel,代碼行數:18,代碼來源:Navigation.php


注:本文中的Zend\EventManager\Event::setTarget方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。