當前位置: 首頁>>代碼示例>>PHP>>正文


PHP MvcEvent::getIdentity方法代碼示例

本文整理匯總了PHP中Zend\Mvc\MvcEvent::getIdentity方法的典型用法代碼示例。如果您正苦於以下問題:PHP MvcEvent::getIdentity方法的具體用法?PHP MvcEvent::getIdentity怎麽用?PHP MvcEvent::getIdentity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend\Mvc\MvcEvent的用法示例。


在下文中一共展示了MvcEvent::getIdentity方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     // Short-circuit ZfcUser's inbuilt user session storage mechanism
     // as we're relying solely on zf-mvc-auth to handle that for us
     $storage = new \Zend\Authentication\Storage\NonPersistent();
     $sm = $e->getApplication()->getServiceManager();
     $sm->get('ZfcUser\\Authentication\\Storage\\Db')->setStorage($storage);
     $sm->get('ZfcUser\\Authentication\\Adapter\\Db')->setStorage($storage);
     // Inject authenticated user from zf-mvc-auth into ZfcUser so it's
     // built-in session and user checking still function properly
     $zfcUserService = $sm->get('zfcuser_user_service');
     $em = $e->getApplication()->getEventManager();
     $em->attach(MvcAuthEvent::EVENT_AUTHENTICATION_POST, function (MvcAuthEvent $e) use($zfcUserService, $storage) {
         $identity = $e->getIdentity();
         if (!$identity instanceof AuthenticatedIdentity) {
             return;
         }
         $token = $identity->getAuthenticationIdentity();
         $uid = $token['user_id'];
         $user = $zfcUserService->getUserMapper()->findById($uid);
         if (!$user instanceof ZfcUserEntity) {
             return;
         }
         $storage->write($user->getId());
     });
 }
開發者ID:Ellipizle,項目名稱:LdcZfcUserOAuth2,代碼行數:26,代碼來源:Module.php

示例2: 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);
 }
開發者ID:biberlabs,項目名稱:zf2-boilerplate,代碼行數:50,代碼來源:Module.php


注:本文中的Zend\Mvc\MvcEvent::getIdentity方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。