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


PHP Event::set方法代碼示例

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


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

示例1: handleException

 /**
  * Handles security related exceptions.
  *
  * @param Event $event An Event instance
  */
 public function handleException(Event $event)
 {
     $exception = $event->get('exception');
     $request = $event->get('request');
     if ($exception instanceof AuthenticationException) {
         if (null !== $this->logger) {
             $this->logger->info(sprintf('Authentication exception occurred; redirecting to authentication entry point (%s)', $exception->getMessage()));
         }
         try {
             $response = $this->startAuthentication($request, $exception);
         } catch (\Exception $e) {
             $event->set('exception', $e);
             return;
         }
     } elseif ($exception instanceof AccessDeniedException) {
         $token = $this->context->getToken();
         if (!$this->authenticationTrustResolver->isFullFledged($token)) {
             if (null !== $this->logger) {
                 $this->logger->info('Access denied (user is not fully authenticated); redirecting to authentication entry point');
             }
             try {
                 $response = $this->startAuthentication($request, new InsufficientAuthenticationException('Full authentication is required to access this resource.', $token, 0, $exception));
             } catch (\Exception $e) {
                 $event->set('exception', $e);
                 return;
             }
         } else {
             if (null !== $this->logger) {
                 $this->logger->info('Access is denied (and user is neither anonymous, nor remember-me)');
             }
             if (null === $this->errorPage) {
                 return;
             }
             $subRequest = Request::create($this->errorPage);
             $subRequest->attributes->set(SecurityContext::ACCESS_DENIED_ERROR, $exception->getMessage());
             try {
                 $response = $event->getSubject()->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true);
             } catch (\Exception $e) {
                 if (null !== $this->logger) {
                     $this->logger->err(sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()));
                 }
                 $event->set('exception', new \RuntimeException('Exception thrown when handling an exception.', 0, $e));
                 return;
             }
             $response->setStatusCode(403);
         }
     } else {
         return;
     }
     $event->setReturnValue($response);
     return true;
 }
開發者ID:rosstuck,項目名稱:Pok,代碼行數:57,代碼來源:ExceptionListener.php


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