当前位置: 首页>>代码示例>>PHP>>正文


PHP EventManager\EventManager类代码示例

本文整理汇总了PHP中Zend\EventManager\EventManager的典型用法代码示例。如果您正苦于以下问题:PHP EventManager类的具体用法?PHP EventManager怎么用?PHP EventManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了EventManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: createPrivateEventManager

 /**
  * @return EventManagerInterface
  */
 private function createPrivateEventManager($eventClazz)
 {
     $events = new EventManager();
     $events->setIdentifiers(array('ZfcUserAdmin', $eventClazz));
     $events->setEventClass($eventClazz);
     return $events;
 }
开发者ID:evilband7,项目名称:ZfcUserAdmin,代码行数:10,代码来源:UserAdminController.php

示例3: setUp

 public function setUp()
 {
     // Store original autoloaders
     $this->loaders = spl_autoload_functions();
     if (!is_array($this->loaders)) {
         // spl_autoload_functions does not return empty array when no
         // autoloaders registered...
         $this->loaders = array();
     }
     // Store original include_path
     $this->includePath = get_include_path();
     $autoloader = new ModuleAutoloader(array(dirname(__DIR__) . '/TestAsset'));
     $autoloader->register();
     $this->sharedEvents = new SharedEventManager();
     $this->moduleManager = new ModuleManager(array('ListenerTestModule'));
     $this->moduleManager->getEventManager()->setSharedManager($this->sharedEvents);
     $this->moduleManager->getEventManager()->attach('loadModule.resolve', new ModuleResolverListener(), 1000);
     $this->application = new MockApplication();
     $events = new EventManager(array('Zend\\Mvc\\Application', 'ZendTest\\Module\\TestAsset\\MockApplication', 'application'));
     $events->setSharedManager($this->sharedEvents);
     $this->application->setEventManager($events);
     $this->serviceManager = new ServiceManager();
     $this->serviceManager->setService('ModuleManager', $this->moduleManager);
     $this->application->setServiceManager($this->serviceManager);
 }
开发者ID:haoyanfei,项目名称:zf2,代码行数:25,代码来源:LocatorRegistrationListenerTest.php

示例4: 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

示例5: getEventManager

 private function getEventManager()
 {
     if (!$this->eventManager) {
         $this->eventManager = new EventManager();
         $this->eventManager->setIdentifiers(get_class($this));
     }
     return $this->eventManager;
 }
开发者ID:t4web,项目名称:cron,代码行数:8,代码来源:Executor.php

示例6: 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

示例7: testEventManagerHasDefaultListeners

 /**
  * 测试能正常注册身份验证过程中的事件监听器。
  */
 public function testEventManagerHasDefaultListeners()
 {
     $eventManager = new EventManager();
     $eventManager->attach($this->stub);
     $this->assertFalse($eventManager->getListeners(Event::EVENT_VERIFY_POST)->isEmpty());
     $this->assertFalse($eventManager->getListeners(Event::EVENT_TOKEN_POST)->isEmpty());
     $this->assertFalse($eventManager->getListeners(Event::EVENT_FAILURE)->isEmpty());
 }
开发者ID:starflash,项目名称:MobilePf-ZF2-Example,代码行数:11,代码来源:AuthLoggerListenerAbstractTest.php

示例8: testCanDetachListenersFromEventManager

 public function testCanDetachListenersFromEventManager()
 {
     $events = new EventManager();
     $events->attachAggregate($this->strategy);
     $this->assertEquals(1, count($events->getListeners(MvcEvent::EVENT_RENDER)));
     $events->detachAggregate($this->strategy);
     $this->assertEquals(0, count($events->getListeners(MvcEvent::EVENT_RENDER)));
 }
开发者ID:razvansividra,项目名称:pnlzf2-1,代码行数:8,代码来源:DefaultRenderingStrategyTest.php

示例9: testAttach

 public function testAttach()
 {
     $eventManager = new EventManager();
     $eventManager->getSharedManager()->clearListeners('ConLayout\\Updater\\LayoutUpdater');
     $this->listener->attach($eventManager);
     $listeners = $eventManager->getSharedManager()->getListeners('ConLayout\\Updater\\LayoutUpdater', 'getLayoutStructure.pre');
     $this->assertCount(1, $listeners);
 }
开发者ID:adamdyson,项目名称:ConLayout,代码行数:8,代码来源:LayoutUpdateListenerTest.php

示例10: createService

 /**
  * Create an instance of EventManagerProxy
  * 
  * @param ServiceLocatorInterface $serviceLocator
  * 
  * @return EventManagerProxy
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $proxy = new EventManagerProxy();
     $em = new EventManager();
     $em->setSharedManager($serviceLocator->get('SharedEventManager'));
     $proxy->setEventManager($em);
     return $proxy;
 }
开发者ID:malocher,项目名称:zf2-event-store-module,代码行数:15,代码来源:EventManagerProxyFactory.php

示例11: createService

 /**
  * {@inheritDoc}
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /* @var $logger \OcraServiceManager\ServiceManager\Logger */
     $logger = $serviceLocator->get('OcraServiceManager\\ServiceManager\\Logger');
     $eventManager = new EventManager();
     $eventManager->attach($logger);
     return $eventManager;
 }
开发者ID:rhodium289,项目名称:sandbox,代码行数:11,代码来源:EventManagerFactory.php

示例12: testAttach

 public function testAttach()
 {
     $sharedEvents = new SharedEventManager();
     $events = new EventManager();
     $events->setSharedManager($sharedEvents);
     $listener = new AccessListener();
     $listener->attach($events);
     $this->assertCount(1, $sharedEvents->getListeners('SporkTools', MvcEvent::EVENT_DISPATCH));
 }
开发者ID:sporkcode,项目名称:sporktools,代码行数:9,代码来源:AccessListenerTest.php

示例13: testAttach

 public function testAttach()
 {
     $em = new EventManager();
     $this->assertEmpty($em->getListeners(ViewEvent::EVENT_RENDERER));
     $this->assertEmpty($em->getListeners(ViewEvent::EVENT_RESPONSE));
     $this->strategy->attach($em);
     $this->assertCount(1, $em->getListeners(ViewEvent::EVENT_RENDERER));
     $this->assertCount(1, $em->getListeners(ViewEvent::EVENT_RESPONSE));
 }
开发者ID:acelaya,项目名称:zf2-acyaml,代码行数:9,代码来源:YamlStrategyTest.php

示例14: 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

示例15: setUp

 public function setUp()
 {
     $resourceFactory = new UserRolesResourceFactory();
     /** @var \Zfegg\Admin\V1\Rest\UserRoles\UserRolesResource $resources */
     $resources = $resourceFactory($this->getServices());
     $events = new EventManager();
     $this->listener = $resources;
     $events->attach($this->listener);
 }
开发者ID:zfegg,项目名称:zfegg-admin,代码行数:9,代码来源:UserRolesResourceTest.php


注:本文中的Zend\EventManager\EventManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。