本文整理汇总了PHP中Zend\Mvc\Application::getMvcEvent方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::getMvcEvent方法的具体用法?PHP Application::getMvcEvent怎么用?PHP Application::getMvcEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mvc\Application
的用法示例。
在下文中一共展示了Application::getMvcEvent方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
/**
* @return Response
*/
public function __invoke()
{
$routeMatch = $this->application->getMvcEvent()->getRouteMatch();
$redirect = $this->getRedirect($routeMatch->getMatchedRouteName(), $this->getRedirectRouteFromRequest());
$response = $this->application->getResponse();
$response->getHeaders()->addHeaderLine('Location', $redirect);
$response->setStatusCode(302);
return $response;
}
示例2: __construct
public function __construct(HelperPluginManager $pluginManager)
{
$this->pluginManager = $pluginManager;
$this->serviceManager = $pluginManager->getServiceLocator();
$this->app = $pluginManager->getServiceLocator()->get('Application');
$this->request = $this->app->getRequest();
$this->event = $this->app->getMvcEvent();
$this->em = $this->serviceManager->get('Doctrine\\ORM\\EntityManager');
$this->translator = $this->serviceManager->get('translator');
}
示例3: 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']);
}
示例4: testCanRecoverFromApplicationError
public function testCanRecoverFromApplicationError()
{
$this->application->bootstrap();
$response = $this->getMock('Zend\\Stdlib\\ResponseInterface');
$errorMock = $this->getMock('stdClass', array('__invoke'));
$finishMock = $this->getMock('stdClass', array('__invoke'));
$routeMock = $this->getMock('stdClass', array('__invoke'));
$dispatchMock = $this->getMock('stdClass', array('__invoke'));
$errorMock->expects($this->once())->method('__invoke')->will($this->returnCallback(function (MvcEvent $event) {
$event->stopPropagation(true);
$event->setRouteMatch(new Router\RouteMatch(array()));
$event->setError('');
}));
$routeMock->expects($this->once())->method('__invoke')->will($this->returnCallback(function (MvcEvent $event) {
$event->stopPropagation(true);
$event->setError(Application::ERROR_ROUTER_NO_MATCH);
return $event->getApplication()->getEventManager()->trigger(MvcEvent::EVENT_DISPATCH_ERROR, $event)->last();
}));
$dispatchMock->expects($this->once())->method('__invoke')->will($this->returnValue($response));
$finishMock->expects($this->once())->method('__invoke')->will($this->returnCallback(function (MvcEvent $event) {
$event->stopPropagation(true);
}));
$this->application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, $errorMock, 100);
$this->application->getEventManager()->attach(MvcEvent::EVENT_ROUTE, $routeMock, 100);
$this->application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH, $dispatchMock, 100);
$this->application->getEventManager()->attach(MvcEvent::EVENT_FINISH, $finishMock, 100);
$this->application->run();
$this->assertSame($response, $this->application->getMvcEvent()->getResponse());
}
示例5: setSymfonyRequest
/**
* Sets the request.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* @return null
*/
protected function setSymfonyRequest(SymfonyRequest $request)
{
$zendRequest = self::createZendRequest($request);
$serviceManager = $this->application->getServiceManager();
$serviceManager->setAllowOverride(true);
$serviceManager->setService('Request', $zendRequest);
$serviceManager->setAllowOverride(false);
$this->application->getMvcEvent()->setRequest($zendRequest);
}
示例6: testCompleteRequestShouldReturnApplicationInstance
public function testCompleteRequestShouldReturnApplicationInstance()
{
$r = new ReflectionObject($this->application);
$method = $r->getMethod('completeRequest');
$method->setAccessible(true);
$this->application->bootstrap();
$event = $this->application->getMvcEvent();
$result = $method->invoke($this->application, $event);
$this->assertSame($this->application, $result);
}
示例7: assertApplicationException
/**
* Assert that the application caught an exception
*
* @param string $class
* @param string $message
*/
protected function assertApplicationException($class = 'Exception', $message = null)
{
$event = $this->application->getMvcEvent();
$this->assertTrue($event->isError());
$exception = $event->getParam('exception');
$this->assertInstanceOf($class, $exception);
if (null !== $message) {
$this->assertEquals($message, $exception->getMessage());
}
}
示例8: createPath
/**
* @param $controllerName
* @param array $controller
*/
private function createPath($controllerName, array $controller)
{
foreach ($controller as $action => $template) {
try {
/** @var AbstractActionController $controllerClass */
$controllerClass = $this->controllerManager->get($controllerName);
$controllerClass->setEvent($this->application->getMvcEvent());
$viewModel = $controllerClass->{$action}();
} catch (\Exception $e) {
$viewModel = null;
}
$this->createPathFromViewModel($viewModel, $controllerName, $action);
}
}
示例9: dispatch
protected function dispatch($controller, $action, $renderView = FALSE)
{
$this->event = $this->application->getMvcEvent();
$this->request = new Request();
// $this->routeMatch = $this->eventManager->trigger(MvcEvent::EVENT_ROUTE, $this->event)->first();
$this->routeMatch = new RouteMatch(array('controller' => $controller));
$this->routeMatch->setParam('action', $action);
$this->event->setRouteMatch($this->routeMatch);
$this->controller->setEvent($this->event);
return $this->controller->dispatch($this->request, $this->response);
// $this->request->setUri($url);
// $this->viewModel = $this->eventManager->trigger(MvcEvent::EVENT_DISPATCH, $this->event)->first();
// $responseEvent = ($renderView ? MvcEvent::EVENT_RENDER : MvcEvent::EVENT_FINISH);
// $this->response = $this->eventManager->trigger($responseEvent, $this->event)->first();
}
示例10: setupView
/**
* Sets up the view integration
*
* Pulls the View object and PhpRenderer strategy from the locator, and
* attaches the former to the latter. Then attaches the
* DefaultRenderingStrategy to the application event manager.
*
* @param Application $application
* @return void
*/
protected function setupView($application)
{
// Basic view strategy
$locator = $application->getLocator();
$events = $application->events();
$staticEvents = StaticEventManager::getInstance();
$view = $locator->get('Zend\\View\\View');
$phpRendererStrategy = $locator->get('Zend\\View\\Strategy\\PhpRendererStrategy');
$defaultViewStrategy = $locator->get('Zend\\Mvc\\View\\DefaultRenderingStrategy');
$view->events()->attachAggregate($phpRendererStrategy);
$events->attachAggregate($defaultViewStrategy);
// Error strategies
$noRouteStrategy = $locator->get('Zend\\Mvc\\View\\RouteNotFoundStrategy');
$exceptionStrategy = $locator->get('Zend\\Mvc\\View\\ExceptionStrategy');
$events->attachAggregate($noRouteStrategy);
$events->attachAggregate($exceptionStrategy);
// Template/ViewModel listeners
$arrayListener = $locator->get('Zend\\Mvc\\View\\CreateViewModelFromArrayListener');
$injectTemplateListener = $locator->get('Zend\\Mvc\\View\\InjectTemplateListener');
$injectViewModelListener = $locator->get('Zend\\Mvc\\View\\InjectViewModelListener');
$staticEvents->attach('Zend\\Stdlib\\Dispatchable', 'dispatch', array($arrayListener, 'createViewModelFromArray'), -80);
$staticEvents->attach('Zend\\Stdlib\\Dispatchable', 'dispatch', array($injectTemplateListener, 'injectTemplate'), -90);
$events->attach('dispatch.error', array($injectViewModelListener, 'injectViewModel'), -100);
$staticEvents->attach('Zend\\Stdlib\\Dispatchable', 'dispatch', array($injectViewModelListener, 'injectViewModel'), -100);
// Inject MVC Event with view model
$mvcEvent = $application->getMvcEvent();
$viewModel = $mvcEvent->getViewModel();
$viewModel->setTemplate($defaultViewStrategy->getLayoutTemplate());
// Inject MVC Event view model as root view model
$renderer = $phpRendererStrategy->getRenderer();
$modelHelper = $renderer->plugin('view_model');
$modelHelper->setRoot($viewModel);
}