/**
  * Invoked directly after the router decides which handler will be used.
  * @param AbstractHandler $handler The handler selected by the router.
  */
 public function afterHandlerSelected(AbstractHandler $handler)
 {
     parent::afterHandlerSelected($handler);
     if (false === $this->isRequestCrossOrigin() || !$handler instanceof AbstractRequestHandler) {
         // since the request isn't cross origin we don't need this plugin to
         // do any processing at all
         return;
     }
     $request = $handler->getRequest();
     if (null === $request) {
         // the CORS plugin only supports handlers with standard requests
         return;
     }
     $requests = array($request);
     if ($handler instanceof BatchRequestHandlerInterface) {
         $requests = $handler->getRequests();
     }
     $this->processRequestsForAccessDenial($requests);
     // let the browser know this domain can make cross origin requests
     @header(self::HEADER_ALLOW_ORIGIN . ': ' . $_SERVER[self::HEADER_CLIENT_ORIGIN]);
     // do not explicitly block requests that pass a cookie
     @header(self::HEADER_ALLOW_CREDENTIALS . ': true');
     if ('OPTIONS' === strtoupper($request->getVerb())) {
         $this->addHeadersForOptionsRequests();
     }
 }
 /**
  * Invoked directly after the router decides which handler will be used.
  * @param AbstractHandler $handler The handler selected by the router.
  */
 public function afterHandlerSelected(AbstractHandler $handler)
 {
     parent::afterHandlerSelected($handler);
     $auth = $this->get($this->authKey);
     if (!$auth instanceof AuthenticatorInterface) {
         throw new InternalErrorException(sprintf("Implementation of AuthenticationInterface required. Please check your %s configuration.", $this->authKey));
     }
     if (!($credentials = $this->getCredentials())) {
         throw new UnauthorizedException("Authentication is required to access this resource.");
     }
     if (!$auth->authenticate($credentials)) {
         throw new UnauthorizedException("Authentication is required to access this resource.");
     }
 }
 /**
  * Invoked directly after the router decides which handler will be used.
  * @param AbstractHandler $handler The handler selected by the router.
  */
 public function afterHandlerSelected(AbstractHandler $handler)
 {
     parent::afterhandlerSelected($handler);
     @header('X-Router: SnappyRouter');
 }