本文整理汇总了PHP中Zend\EventManager\EventInterface::setResult方法的典型用法代码示例。如果您正苦于以下问题:PHP EventInterface::setResult方法的具体用法?PHP EventInterface::setResult怎么用?PHP EventInterface::setResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\EventManager\EventInterface
的用法示例。
在下文中一共展示了EventInterface::setResult方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onBootstrap
public function onBootstrap(EventInterface $event)
{
/*$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);*/
$application = $event->getTarget();
$serviceManager = $application->getServiceManager();
$translator = $serviceManager->get('translator');
$translator->setLocale(\Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']))->setFallbackLocale('en_US');
$application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH, function (MvcEvent $event) use($serviceManager) {
$request = $event->getRequest();
$response = $event->getResponse();
if (!($request instanceof HttpRequest && $response instanceof HttpResponse)) {
return;
// CLI application maybe?
}
$authAdapter = $serviceManager->get('AuthenticationAdapter');
$authAdapter->setRequest($request);
$authAdapter->setResponse($response);
$result = $authAdapter->authenticate();
if ($result->isValid()) {
return;
// OK
}
$response->setContent('Access denied');
$response->setStatusCode(HttpResponse::STATUS_CODE_401);
$event->setResult($response);
// to end
return false;
// event propagation stop
});
}