本文整理匯總了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
});
}