本文整理汇总了PHP中Zend\Mvc\Application::getEventManager方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::getEventManager方法的具体用法?PHP Application::getEventManager怎么用?PHP Application::getEventManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mvc\Application
的用法示例。
在下文中一共展示了Application::getEventManager方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($name = null, array $data = array(), $dataName = '')
{
parent::__construct($name, $data, $dataName);
$this->app = \Bootstrap::$app;
$this->sm = $this->app->getServiceManager();
$this->evm = $this->app->getEventManager();
}
示例2: testOnBootstrap
public function testOnBootstrap()
{
$this->assertFalse($this->app->getEventManager()->getSharedManager()->getListeners('LearnZF2I18n', MvcEvent::EVENT_DISPATCH));
$e = new MvcEvent();
$e->setApplication($this->app);
$this->module->onBootstrap($e);
$this->assertCount(1, $this->app->getEventManager()->getSharedManager()->getListeners('LearnZF2I18n', MvcEvent::EVENT_DISPATCH));
}
示例3: getApplication
/**
* @return \Zend\Mvc\Application
*/
public function getApplication()
{
if ($this->spiffyApplication) {
return $this->spiffyApplication;
}
Console::overrideIsConsole($this->getUseConsoleRequest());
$this->spiffyApplication = SpiffyTest::getInstance()->getApplication();
$events = $this->spiffyApplication->getEventManager();
$events->detach($this->spiffyApplication->getServiceManager()->get('SendResponseListener'));
return $this->spiffyApplication;
}
示例4: testUnlocatableControllerLoaderComposedOfAbstractFactory
public function testUnlocatableControllerLoaderComposedOfAbstractFactory()
{
$this->setupPathController();
$controllerLoader = $this->serviceManager->get('ControllerLoader');
$controllerLoader->addAbstractFactory('ZendTest\\Mvc\\Controller\\TestAsset\\UnlocatableControllerLoaderAbstractFactory');
$log = array();
$this->application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use(&$log) {
$log['error'] = $e->getError();
});
$this->application->run();
$event = $this->application->getMvcEvent();
$dispatchListener = $this->serviceManager->get('DispatchListener');
$return = $dispatchListener->onDispatch($event);
$this->assertArrayHasKey('error', $log);
$this->assertSame('error-controller-not-found', $log['error']);
}
示例5: testEventPropagationStatusIsClearedBetweenEventsDuringRun
/**
* @dataProvider eventPropagation
*/
public function testEventPropagationStatusIsClearedBetweenEventsDuringRun($events)
{
$event = new MvcEvent();
$event->setTarget($this->application);
$event->setApplication($this->application)->setRequest($this->application->getRequest())->setResponse($this->application->getResponse())->setRouter($this->serviceManager->get('Router'));
$event->stopPropagation(true);
// Intentionally not calling bootstrap; setting mvc event
$r = new ReflectionObject($this->application);
$eventProp = $r->getProperty('event');
$eventProp->setAccessible(true);
$eventProp->setValue($this->application, $event);
// Setup listeners that stop propagation, but do nothing else
$marker = array();
foreach ($events as $event) {
$marker[$event] = true;
}
$marker = (object) $marker;
$listener = function ($e) use($marker) {
$marker->{$e->getName()} = $e->propagationIsStopped();
$e->stopPropagation(true);
};
$this->application->getEventManager()->attach($events, $listener);
$this->application->run();
foreach ($events as $event) {
$this->assertFalse($marker->{$event}, sprintf('Assertion failed for event "%s"', $event));
}
}
示例6: it_aborts_bootstrap_on_console
public function it_aborts_bootstrap_on_console(MvcEvent $event, Application $application, ServiceLocatorInterface $serviceLocator, AccessListener $listener, EventManager $eventManager)
{
Console::overrideIsConsole(true);
$application->getEventManager()->willReturn($eventManager);
$serviceLocator->get(AccessListener::class)->willReturn($listener);
$application->getServiceManager()->willReturn($serviceLocator);
$event->getApplication()->willReturn($application);
$listener->attach($eventManager)->shouldNotBeCalled();
$this->onBootstrap($event);
}
示例7: getApplication
/**
* Get the application object
* @return \Zend\Mvc\Application
*/
public static function getApplication()
{
if (self::$application instanceof \Zend\Mvc\ApplicationInterface) {
return self::$application;
}
self::$application = \Zend\Mvc\Application::init(self::getApplicationConfig());
$oEventManager = self::$application->getEventManager();
$oEventManager->detach(self::$application->getServiceManager()->get('SendResponseListener'));
return self::$application;
}
示例8: setUp
public function setUp()
{
parent::setUp();
$this->application = \Zend\Mvc\Application::init(include TEST_APP_ROOT . '/config/application.config.php');
$this->em = $this->application->getServiceManager()->get('doctrine.entitymanager.orm_default');
$this->request = null;
$this->response = null;
$this->routeMatch = null;
$this->viewModel = null;
$this->event = $this->application->getMvcEvent();
$this->eventManager = $this->application->getEventManager();
$this->request = $this->event->getRequest();
if (!empty($this->entities)) {
$tool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
foreach ($this->entities as $entity) {
$this->doctrineEntities[] = $this->em->getClassMetadata($entity);
}
$tool->dropSchema($this->doctrineEntities);
$tool->createSchema($this->doctrineEntities);
$this->em->getConfiguration()->getResultCacheImpl()->flushAll();
$this->em->getConfiguration()->getResultCacheImpl()->deleteAll();
}
}
示例9: getApplication
/**
* When application is not available, one will be initialized to respond to
* the esi request.
*
* @param Uri $uri
* @return \Zend\Mvc\Application
*/
public function getApplication(Uri $uri)
{
if (!$this->application instanceof Application) {
$applicationConfig = $this->getEsiApplicationConfigProvider()->getEsiApplicationConfig($uri);
$this->application = Application::init($applicationConfig);
// Remove the finish listeners so response header and content is not automatically echo'd
$this->application->getEventManager()->clearListeners(MvcEvent::EVENT_FINISH);
}
// The request needs to be augmented with the URI passed in
$request = $this->application->getRequest();
$request->setUri($uri);
$request->setRequestUri($uri->getPath() . '?' . $uri->getQuery());
$request->setQuery(new Parameters($uri->getQueryAsArray()));
return $this->application;
}
示例10: setApplication
/**
* Set the Zend\Mvc\Application and attach the event listeners.
*
* @param \Zend\Mvc\Application $application
* @return ZendHttpKernel
*/
public function setApplication(Application $application)
{
if ($this->application === $application) {
// Application unchanged.
return $this;
}
// Unregister from previous application.
if ($this->application !== null) {
// Detach from old application.
$this->detach($this->application->getEventManager());
}
// Set the application.
$this->application = $application;
$this->attach($application->getEventManager());
return $this;
}
示例11: testReturnsResponseFromListenerWhenDispatchEventShortCircuits
/**
* @group 2981
*/
public function testReturnsResponseFromListenerWhenDispatchEventShortCircuits()
{
$this->application->bootstrap();
$testResponse = new Response();
$response = $this->application->getResponse();
$events = $this->application->getEventManager();
$events->clearListeners(MvcEvent::EVENT_ROUTE);
$events->attach(MvcEvent::EVENT_DISPATCH, function ($e) use($testResponse) {
$testResponse->setContent('triggered');
return $testResponse;
}, 100);
$self = $this;
$triggered = false;
$events->attach(MvcEvent::EVENT_FINISH, function ($e) use($self, $testResponse, &$triggered) {
$self->assertSame($testResponse, $e->getResponse());
$triggered = true;
});
$this->application->run();
$this->assertTrue($triggered);
}
示例12: marshallBadControllerEvent
/**
* Marshall a bad controller exception event
*
* @param string $controllerName
* @param MvcEvent $event
* @param Application $application
* @param \Exception $exception
* @return mixed
*/
protected function marshallBadControllerEvent($controllerName, MvcEvent $event, Application $application, \Exception $exception)
{
$event->setError($application::ERROR_EXCEPTION)->setController($controllerName)->setParam('exception', $exception);
$events = $application->getEventManager();
$results = $events->trigger(MvcEvent::EVENT_DISPATCH_ERROR, $event);
$return = $results->last();
if (!$return) {
$return = $event->getResult();
}
return $return;
}
示例13: marshalMiddlewareNotCallable
/**
* Marshal a middleware not callable exception event
*
* @param string $type
* @param string $middlewareName
* @param MvcEvent $event
* @param Application $application
* @param \Exception $exception
* @return mixed
*/
protected function marshalMiddlewareNotCallable($type, $middlewareName, MvcEvent $event, Application $application, \Exception $exception = null)
{
$event->setName(MvcEvent::EVENT_DISPATCH_ERROR);
$event->setError($type);
$event->setController($middlewareName);
$event->setControllerClass('Middleware not callable: ' . $middlewareName);
if ($exception !== null) {
$event->setParam('exception', $exception);
}
$events = $application->getEventManager();
$results = $events->triggerEvent($event);
$return = $results->last();
if (!$return) {
$return = $event->getResult();
}
return $return;
}
示例14: it_dispatches_unauthorized
/**
* Valid route but with no login with no login
*/
public function it_dispatches_unauthorized(MvcEvent $event, RouteMatch $match, EventManagerInterface $eventManager, Application $application, $accessService)
{
$application->getEventManager()->willReturn($eventManager);
$accessService->requiresAuthentication(self::CONTROLLER_ADMIN, 'index')->willReturn(true);
$accessService->hasUser()->willReturn(false);
$event->getTarget()->willReturn($application);
$match->getParam('controller')->willReturn(self::CONTROLLER_ADMIN);
$match->getParam('action')->willReturn('index');
$match->getMatchedRouteName()->willReturn('admin');
$event->getRouteMatch()->willReturn($match);
$accessService->getRoles()->willReturn([]);
$eventManager->triggerEvent($event)->shouldBeCalled();
$event->setError(AccessService::ACCESS_UNAUTHORIZED)->shouldBeCalled();
$event->setParam('route', 'admin')->shouldBeCalled();
$event->setParam('controller', self::CONTROLLER_ADMIN)->shouldBeCalled();
$event->setParam('action', 'index')->shouldBeCalled();
$event->setParam('roles', 'none')->shouldBeCalled();
$event->setName(MvcEvent::EVENT_DISPATCH_ERROR)->shouldBeCalled();
$this->verifyAccess($event);
}