當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。