本文整理汇总了PHP中Zend\Mvc\Application::getLocator方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::getLocator方法的具体用法?PHP Application::getLocator怎么用?PHP Application::getLocator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mvc\Application
的用法示例。
在下文中一共展示了Application::getLocator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCanRetrieveLocatorOnceSet
/**
* @dataProvider validLocators
*/
public function testCanRetrieveLocatorOnceSet($locator)
{
$app = new Application();
$app->setLocator($locator);
$this->assertSame($locator, $app->getLocator());
}
示例2: 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);
}