本文整理汇总了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());
}
}
示例2: createPrivateEventManager
/**
* @return EventManagerInterface
*/
private function createPrivateEventManager($eventClazz)
{
$events = new EventManager();
$events->setIdentifiers(array('ZfcUserAdmin', $eventClazz));
$events->setEventClass($eventClazz);
return $events;
}
示例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);
}
示例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);
}
示例5: getEventManager
private function getEventManager()
{
if (!$this->eventManager) {
$this->eventManager = new EventManager();
$this->eventManager->setIdentifiers(get_class($this));
}
return $this->eventManager;
}
示例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));
}
示例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());
}
示例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)));
}
示例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);
}
示例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;
}
示例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;
}
示例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));
}
示例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));
}
示例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);
}
示例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);
}