/** * @dataProvider validLocators */ public function testCanRetrieveLocatorOnceSet($locator) { $app = new Application(); $app->setLocator($locator); $this->assertSame($locator, $app->getLocator()); }
/** * 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); }