本文整理汇总了PHP中Zend\Mvc\Application::events方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::events方法的具体用法?PHP Application::events怎么用?PHP Application::events使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mvc\Application
的用法示例。
在下文中一共展示了Application::events方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testEventManagerIsLazyLoaded
public function testEventManagerIsLazyLoaded()
{
$app = new Application();
$events = $app->events();
$this->assertInstanceOf('Zend\\EventManager\\EventCollection', $events);
$this->assertInstanceOf('Zend\\EventManager\\EventManager', $events);
}
示例2: testFinishShouldRunEvenIfDispatchEventReturnsResponse
/**
* @group ZF2-171
*/
public function testFinishShouldRunEvenIfDispatchEventReturnsResponse()
{
$app = new Application();
$response = $app->getResponse();
$events = $app->events();
$events->clearListeners('route');
$events->attach('dispatch', function ($e) use($response) {
return $response;
}, 100);
$token = new stdClass();
$events->attach('finish', function ($e) use($token) {
$token->foo = 'bar';
});
$app->run();
$this->assertTrue(isset($token->foo));
$this->assertEquals('bar', $token->foo);
}
示例3: 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);
}