當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Application::getMvcEvent方法代碼示例

本文整理匯總了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;
 }
開發者ID:idwsdta,項目名稱:ZF2_resftFull_mobile_frameworks,代碼行數:12,代碼來源:RedirectCallback.php

示例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');
 }
開發者ID:Belcebur,項目名稱:BelceburBasic,代碼行數:10,代碼來源:BTools.php

示例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']);
 }
開發者ID:pnaq57,項目名稱:zf2demo,代碼行數:16,代碼來源:DispatchListenerTest.php

示例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());
 }
開發者ID:pnaq57,項目名稱:zf2demo,代碼行數:29,代碼來源:ApplicationTest.php

示例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);
 }
開發者ID:reenl,項目名稱:stack-zf2,代碼行數:15,代碼來源:ZendHttpKernel.php

示例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);
 }
開發者ID:razvansividra,項目名稱:pnlzf2-1,代碼行數:10,代碼來源:ApplicationTest.php

示例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());
     }
 }
開發者ID:sporkcode,項目名稱:spork,代碼行數:16,代碼來源:TestCaseController.php

示例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);
     }
 }
開發者ID:geeh,項目名稱:snubbed,代碼行數:18,代碼來源:ViewSnubber.php

示例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();
 }
開發者ID:dennesabing,項目名稱:dx,代碼行數:15,代碼來源:BaseTestCase.php

示例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);
 }
開發者ID:navtis,項目名稱:xerxes-pazpar2,代碼行數:43,代碼來源:Bootstrap.php


注:本文中的Zend\Mvc\Application::getMvcEvent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。