本文整理汇总了PHP中Zend\Mvc\MvcEvent::setIdentity方法的典型用法代码示例。如果您正苦于以下问题:PHP MvcEvent::setIdentity方法的具体用法?PHP MvcEvent::setIdentity怎么用?PHP MvcEvent::setIdentity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mvc\MvcEvent
的用法示例。
在下文中一共展示了MvcEvent::setIdentity方法的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);
}