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


PHP EventManager::trigger方法代碼示例

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


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

示例1: trigger

 protected function trigger(EntityInterface $entity)
 {
     if (!$this->eventManager) {
         return;
     }
     $this->eventManager->trigger('create:post', $this, compact('entity'));
 }
開發者ID:t4web,項目名稱:base,代碼行數:7,代碼來源:Create.php

示例2: trigger

 /**
  * {@inheritDoc}
  */
 public function trigger(EventInterface $event)
 {
     if ($event instanceof ZendEventInterface) {
         $this->eventManager->trigger($event);
     }
     return $this;
 }
開發者ID:amir20202000,項目名稱:penny,代碼行數:10,代碼來源:ZendEvmProxy.php

示例3: trigger

 protected function trigger($event, $values, $nameForReturnValue)
 {
     if (!$this->eventManager) {
         return;
     }
     $this->eventManager->trigger($event, $this, array($nameForReturnValue => $values));
 }
開發者ID:t4web,項目名稱:base,代碼行數:7,代碼來源:Delete.php

示例4: send

 public function send($to, $templateName, array $data = [])
 {
     $template = $this->templateBuilder->get($templateName);
     $message = $this->mailAssembler->assemble($to, $template, $data);
     $this->mailTransport->send($message);
     $event = new Event('mail-send:post', $this, ['to' => $to, 'template' => $template, 'message' => $message, 'data' => $data]);
     $this->eventManager->trigger($event);
 }
開發者ID:t4web,項目名稱:mail,代碼行數:8,代碼來源:Sender.php

示例5: trigger

 /**
  * @param EventInterface    $event
  * @param null|callable     $callback
  * @throws \Exception
  */
 public function trigger($event, $callback = null)
 {
     try {
         $this->manager->trigger($event, null, null, $callback);
     } catch (\Exception $ex) {
         $this->logger->error($ex);
         throw $ex;
     }
 }
開發者ID:qshurick,項目名稱:event,代碼行數:14,代碼來源:Manager.php

示例6: parse

 /**
  * 
  * @param ClassScanner[] $classes
  */
 public function parse($classes)
 {
     $config = array();
     foreach ($classes as $class) {
         $classAnnotationHolder = $this->parseClass($class);
         $event = new ParseEvent(ParseEvent::EVENT_CLASS_PARSED, $classAnnotationHolder, array('config' => $this->config));
         $this->eventManager->trigger($event);
         $config = ArrayUtils::merge($config, $event->getResult());
     }
     return $config;
 }
開發者ID:Okeanrst,項目名稱:zf-annotations,代碼行數:15,代碼來源:ClassParser.php

示例7: inAction

 public function inAction()
 {
     if (!$this->getRequest()->isPost()) {
         // just show the login form
         return array();
     }
     $username = $this->params()->fromPost('username');
     $password = $this->params()->fromPost('password');
     $auth = $this->serviceLocator->get('auth');
     $authAdapter = $auth->getAdapter();
     // below we pass the username and the password to the authentication adapter for verification
     $authAdapter->setIdentity($username);
     $authAdapter->setCredential($password);
     // here we do the actual verification
     $result = $auth->authenticate();
     $isValid = $result->isValid();
     if ($isValid) {
         // upon successful validation the getIdentity method returns
         // the user entity for the provided credentials
         $user = $result->getIdentity();
         // @todo: upon successful validation store additional information about him in the auth storage
         $this->flashmessenger()->addSuccessMessage(sprintf('Welcome %s. You are now logged in.', $user->getName()));
         return $this->redirect()->toRoute('user/default', array('controller' => 'account', 'action' => 'me'));
     } else {
         $event = new EventManager('user');
         $event->trigger('log-fail', $this, array('username' => $username));
         return array('errors' => $result->getMessages());
     }
 }
開發者ID:gioeleminardi,項目名稱:learnzf2,代碼行數:29,代碼來源:LogController.php

示例8: addAction

 public function addAction()
 {
     // The annotation builder help us create a form from the annotations in the user entity.
     $builder = new AnnotationBuilder();
     $entity = $this->serviceLocator->get('user-entity');
     $form = $builder->createForm($entity);
     $form->add(array('name' => 'password_verify', 'type' => 'Zend\\Form\\Element\\Password', 'attributes' => array('placeholder' => 'Verify Password Here...', 'required' => 'required'), 'options' => array('label' => 'Verify Password')), array('priority' => $form->get('password')->getOption('priority')));
     // This is the special code that protects our form being submitted from automated scripts
     $form->add(array('name' => 'csrf', 'type' => 'Zend\\Form\\Element\\Csrf'));
     // This is the submit button
     $form->add(array('name' => 'submit', 'type' => 'Zend\\Form\\Element\\Submit', 'attributes' => array('value' => 'Submit', 'required' => 'false')));
     // We bind the entity to the user. If the form tries to read/write data from/to the entity
     // it will use the hydrator specified in the entity to achieve this. In our case we use ClassMethods
     // hydrator which means that reading will happen calling the getter methods and writing will happen by
     // calling the setter methods.
     $form->bind($entity);
     if ($this->getRequest()->isPost()) {
         $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
         $form->setData($data);
         if ($form->isValid()) {
             // We use now the Doctrine 2 entity manager to save user data to the database
             $entityManager = $this->serviceLocator->get('entity-manager');
             $entityManager->persist($entity);
             $entityManager->flush();
             $this->flashmessenger()->addSuccessMessage('User was added successfully.');
             $event = new EventManager('user');
             $event->trigger('register', $this, array('user' => $entity));
             // redirect the user to the view user action
             return $this->redirect()->toRoute('user/default', array('controller' => 'account', 'action' => 'view', 'id' => $entity->getId()));
         }
     }
     // pass the data to the view for visualization
     return array('form1' => $form);
 }
開發者ID:gsokolowski,項目名稱:learnzf2,代碼行數:34,代碼來源:AccountController.php

示例9: testOnFailure

 /**
  * 測試AuthLoggerListener::onFailure()
  */
 public function testOnFailure()
 {
     $e = new Event();
     $e->setFailure(new Failure('Test', array('result' => '123456')));
     $this->events->trigger(Event::EVENT_FAILURE, $e);
     $this->assertStringMatchesFormat('%s WARN (4): Test {"result":"123456"}%w', file_get_contents($this->destfile));
 }
開發者ID:starflash,項目名稱:MobilePf-ZF2-Example,代碼行數:10,代碼來源:AuthLoggerListenerTest.php

示例10: it_should_handle_valid_data

 /**
  * @param \Phpro\SmartCrud\Gateway\CrudGatewayInterface $gateway
  * @param \Zend\EventManager\EventManager               $eventManager
  * @param \Zend\Form\Form                               $form
  * @param \Phpro\SmartCrud\Service\SmartServiceResult   $result
  */
 public function it_should_handle_valid_data($gateway, $eventManager, $form, $result)
 {
     $entity = new \StdClass();
     $postData = $this->getMockPostData();
     $gateway->loadEntity('entityKey', null)->shouldBecalled()->willReturn($entity);
     $gateway->delete($entity, $postData)->shouldBecalled()->willReturn(true);
     $result->setSuccess(true)->shouldBeCalled();
     $result->setEntity($entity)->shouldBeCalled();
     $this->setEntityKey('entityKey');
     $this->setGateway($gateway);
     $this->setResult($result);
     $this->setForm($form);
     $this->run(null, $this->getMockPostData())->shouldReturn($result);
     $eventManager->trigger(Argument::which('getName', CrudEvent::INVALID_DELETE))->shouldNotBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DELETE))->shouldBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::AFTER_DELETE))->shouldBeCalled();
 }
開發者ID:phpro,項目名稱:zf-smartcrud,代碼行數:23,代碼來源:DeleteServiceSpec.php

示例11: it_should_return_a_result

 /**
  * @param \Phpro\SmartCrud\Gateway\CrudGatewayInterface $gateway
  * @param \Zend\EventManager\EventManager               $eventManager
  * @param \Phpro\SmartCrud\Service\SmartServiceResult   $result
  */
 public function it_should_return_a_result($gateway, $eventManager, $result)
 {
     $entity = new \StdClass();
     $entity->id = 1;
     $postData = null;
     $gateway->loadEntity('entityKey', $entity->id)->shouldBecalled()->willReturn($entity);
     $result->setSuccess(Argument::any())->shouldBeCalled();
     $result->setForm(Argument::any())->shouldNotBeCalled();
     $result->setEntity($entity)->shouldBeCalled();
     $this->setEntityKey('entityKey');
     $this->setGateway($gateway);
     $this->setResult($result);
     $this->run($entity->id, $postData)->shouldReturn($result);
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_VALIDATION))->shouldNotBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_READ))->shouldBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::AFTER_READ))->shouldBeCalled();
 }
開發者ID:phpro,項目名稱:zf-smartcrud,代碼行數:22,代碼來源:ReadServiceSpec.php

示例12: it_should_trigger_events_during_form_configuration

 /**
  * @param \Zend\EventManager\EventManager $eventManager
  * @param \Zend\Form\FormInterface $form
  * @param \ArrayAccess $spec
  */
 public function it_should_trigger_events_during_form_configuration($eventManager, $form, $spec)
 {
     $this->configureForm($form, $spec);
     $triggeredEvents = array(FormEvent::EVENT_CONFIGURE_ELEMENT_PRE, FormEvent::EVENT_CONFIGURE_ELEMENT_POST);
     $eventManager->trigger(Argument::that(function ($event) use($form, $spec, $triggeredEvents) {
         return $event instanceof FormEvent && in_array($event->getName(), $triggeredEvents) && $event->getTarget() == $form->getWrappedObject() && $event->getParam('spec') == $spec->getWrappedObject();
     }))->shouldBeCalledTimes(count($triggeredEvents));
 }
開發者ID:phpro,項目名稱:zf-annotated-forms,代碼行數:13,代碼來源:FactorySpec.php

示例13: it_should_trigger_events_while_creating_form

 /**
  * @param \Zend\EventManager\EventManager $eventManager
  */
 public function it_should_trigger_events_while_creating_form($eventManager)
 {
     $this->mockConfiguration();
     $this->createForm('stdClass');
     $eventManager->trigger(Argument::that(function ($event) {
         $validEvents = array(FormEvent::EVENT_FORM_CREATE_PRE, FormEvent::EVENT_FORM_CREATE_POST);
         return $event instanceof FormEvent && in_array($event->getName(), $validEvents);
     }))->shouldBeCalledTimes(2);
 }
開發者ID:phpro,項目名稱:zf-annotated-forms,代碼行數:12,代碼來源:BuilderSpec.php

示例14: testFirewallOn

 /**
  * Test if firewall is on
  */
 public function testFirewallOn()
 {
     self::setUpFirewallOn();
     $spyListener = new SpyingFirewallListener();
     $spyListener->setServiceLocator($this->getServiceManager());
     $eventManager = new EventManager();
     $eventManager->attach($spyListener);
     $eventManager->trigger(FirewallEvent::EVENT_FIREWALL_DISPATCH);
     $this->assertTrue($spyListener->isFirewallEnabled());
 }
開發者ID:dollyaswin,項目名稱:pyro,代碼行數:13,代碼來源:FirewallListenerTest.php

示例15: triggerEvent

 /**
  * Trigger an event
  *
  * @param  string             $event Event name
  * @param  array|\ArrayAccess $argv  Array of arguments; typically, should be associative
  */
 protected function triggerEvent($event, $argv = [])
 {
     if (null === $this->events) {
         if (class_exists('\\Zend\\EventManager\\EventManager')) {
             $this->events = new EventManager(__CLASS__);
         } else {
             return;
         }
     }
     $this->events->trigger($event, $this, $argv);
 }
開發者ID:GeeH,項目名稱:zend-ldap,代碼行數:17,代碼來源:Node.php


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