本文整理匯總了PHP中Zend\Mvc\MvcEvent::getMvcEvent方法的典型用法代碼示例。如果您正苦於以下問題:PHP MvcEvent::getMvcEvent方法的具體用法?PHP MvcEvent::getMvcEvent怎麽用?PHP MvcEvent::getMvcEvent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Mvc\MvcEvent
的用法示例。
在下文中一共展示了MvcEvent::getMvcEvent方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: onBootstrap
public function onBootstrap(MvcEvent $event)
{
$eventManager = $event->getApplication()->getEventManager();
$oauth2Closure = $event->getApplication()->getServiceManager()->get(\ZF\OAuth2\Service\OAuth2Server::class);
$logger = $event->getApplication()->getServiceManager()->get('logger');
$eventManager->attach(MvcAuthEvent::EVENT_AUTHENTICATION_POST, function (MvcAuthEvent $event) use($oauth2Closure) {
// Manipulating Identity Data
$identity = $event->getIdentity();
if (!!$identity) {
if ($identity instanceof AuthenticatedIdentity) {
$userData = $oauth2Closure()->getStorage('user_credentials')->getUser($identity->getName());
if (is_array($identity->getAuthenticationIdentity())) {
$userData = array_merge($userData, $identity->getAuthenticationIdentity());
}
$identity = new AuthenticatedIdentity($userData);
$event->setIdentity($identity);
}
//MvcEvent did not understand when manipulated MvcAuthEvent identity
$event->getMvcEvent()->setParam('ZF\\MvcAuth\\Identity', $identity);
}
return $event;
}, 900);
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$event->getApplication()->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function (MvcEvent $event) use($logger) {
$problem = null;
if ($event->isError()) {
$exception = $event->getParam("exception");
// There are some other errors like that :
// "error-controller-cannot-dispatch",
// "error-controller-invalid",
// "error-controller-not-found",
// "error-router-no-match",
if ($event->getError() === 'error-controller-not-found') {
$problem = new ApiProblem(404, "Endpoint controller not found!");
} elseif ($event->getError() === 'error-router-no-match') {
$problem = new ApiProblem(404, "Not found!");
} elseif ($exception instanceof \Exception) {
$className = explode('\\', get_class($exception));
$problem = new ApiProblem($exception->getCode(), end($className) . ' error.');
$logger->err($exception->getMessage(), array('controller' => $event->getControllerClass()));
}
} else {
$problem = new ApiProblem(500, "Unknown Error!");
}
$response = new ApiProblemResponse($problem);
$event->stopPropagation();
return $response;
}, 9000);
}