当前位置: 首页>>代码示例>>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;未经允许,请勿转载。