예제 #1
0
 /**
  * {@inheritDoc}
  */
 public function match(Request $request)
 {
     if ($this->matcher->matches($request)) {
         return $this->router->match($request);
     }
     return null;
 }
 /**
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!$this->matcher->matches($event->getRequest())) {
         return;
     }
     $this->exceptionListener->onKernelException($event);
 }
 /**
  * @test
  */
 public function it_does_match_the_method_when_provided()
 {
     $this->requestMatcher = new MultiPathRequestMatcher(['^/some/path', '^/some/other/path'], ['GET', 'DELETE']);
     $matchingRequest = Request::create('/some/path', 'GET');
     $matches = $this->requestMatcher->matches($matchingRequest);
     $this->assertTrue($matches);
     $nonMatchingRequest = Request::create('/some/other/path', 'GET');
     $matches = $this->requestMatcher->matches($nonMatchingRequest);
     $this->assertFalse($matches);
 }
예제 #4
0
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!$event->getRequest()->attributes->has('_api_result') && !$this->requestMatcher->matches($event->getRequest())) {
         return;
     }
     $errorFactory = $this->errorFactory;
     /** @var ErrorInterface $error */
     $error = $errorFactory($event->getException());
     // Tell Symfony to not use 500 as status code.
     $response = new JsonResponse(array_merge(['ok' => false, 'error' => $error->getName()], $error->getData()), 200, ['x-status-code' => 200]);
     $event->setResponse($response);
 }
예제 #5
0
    /**
     * Return the response to the context hash request with a header containing
     * the generated hash.
     *
     * If the ttl is bigger than 0, cache headers will be set for this response.
     *
     * @param GetResponseEvent $event
     */
    public function onKernelRequest(GetResponseEvent $event)
    {
        if ($event->getRequestType() != HttpKernelInterface::MASTER_REQUEST) {
            return;
        }

        if (!$this->requestMatcher->matches($event->getRequest())) {
            return;
        }

        $hash = $this->hashGenerator->generateHash();

        // status needs to be 200 as otherwise varnish will not cache the response.
        $response = new Response('', 200, array(
            $this->hashHeader => $hash,
            'Content-Type'    => 'application/vnd.fos.user-context-hash'
        ));

        if ($this->ttl > 0) {
            $response->setClientTtl($this->ttl);
            $response->setVary($this->userIdentifierHeaders);
            $response->setPublic();
        } else {
            $response->setClientTtl(0);
            $response->headers->addCacheControlDirective('no-cache');
        }

        $event->setResponse($response);
    }
 /**
  * Check to see if a tag invlidation request has been made and invalidate
  * the tags in that case.
  *
  * Will return a Response object if the calling class should return a
  * premature response rather than continue.
  *
  * @param Request $request
  *
  * @return Response|null
  */
 public function handleRequest(Request $request)
 {
     if ($request->getMethod() !== $this->options['purge_method']) {
         return;
     }
     if (false === $request->headers->has($this->options['header_invalidate_tags'])) {
         return;
     }
     if (false === $this->requestMatcher->matches($request)) {
         $response = new Response('', 400);
         return $response;
     }
     $tags = $this->decodeTags($request->headers->get($this->options['header_invalidate_tags']));
     $this->manager->invalidateTags($tags);
     $response = new Response(sprintf('Tags processed: "%s"', implode('", "', $tags)));
     $response->setStatusCode(200, 'Invalidated');
     return $response;
 }
 /**
  * @param Request              $request
  * @param FlattenException     $exception
  * @param DebugLoggerInterface $logger
  * @param string               $_format
  * @return Response
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $_format = 'html')
 {
     $code = $exception->getStatusCode();
     if (404 !== $code || $this->exclusionRequestMatcher->matches($request)) {
         return parent::showAction($request, $exception, $logger, $_format);
     }
     $templateForSuggestion = $this->getTemplateForSuggestions($_format);
     if (null === $templateForSuggestion) {
         return parent::showAction($request, $exception, $logger, $_format);
     }
     $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
     $groupedSuggestions = array();
     foreach ($this->suggestionProviders as $item) {
         $suggestions = $item['provider']->create($request);
         $groupedSuggestions[$item['group']] = isset($groupedSuggestions[$item['group']]) ? array_merge($groupedSuggestions[$item['group']], $suggestions) : $suggestions;
     }
     return new Response($this->twig->render($templateForSuggestion, array('status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'message' => $exception->getMessage(), 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent, 'best_matches' => $groupedSuggestions)), $code);
 }
예제 #8
0
 /**
  * {@inheritdoc}
  */
 public function canEnable(Request $request)
 {
     $config = $this->configFactory->get('xhprof.config');
     if ($this->isLoaded() && $config->get('enabled') && $this->requestMatcher->matches($request)) {
         $interval = $config->get('interval');
         if ($interval && mt_rand(1, $interval) % $interval != 0) {
             return FALSE;
         }
         return TRUE;
     }
     return FALSE;
 }
 /**
  * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     // Don't try to match when it's a user hash request. SiteAccess is irrelevant in this case.
     if ($this->userContextRequestMatcher->matches($request) && !$request->attributes->has('_ez_original_request')) {
         return;
     }
     // We have a serialized siteaccess object from a fragment (sub-request), we need to get it back.
     if ($request->attributes->has('serialized_siteaccess')) {
         $request->attributes->set('siteaccess', unserialize($request->attributes->get('serialized_siteaccess')));
         $request->attributes->remove('serialized_siteaccess');
     } elseif (!$request->attributes->has('siteaccess')) {
         // Get SiteAccess from original request if present ("_ez_original_request" attribute), or current request otherwise.
         // "_ez_original_request" attribute is present in the case of user context hash generation (aka "user hash request").
         $request->attributes->set('siteaccess', $this->getSiteAccessFromRequest($request->attributes->get('_ez_original_request', $request)));
     }
     $siteaccess = $request->attributes->get('siteaccess');
     if ($siteaccess instanceof SiteAccess) {
         $siteAccessEvent = new PostSiteAccessMatchEvent($siteaccess, $request, $event->getRequestType());
         $this->eventDispatcher->dispatch(MVCEvents::SITEACCESS, $siteAccessEvent);
     }
 }
예제 #10
0
 /**
  * Collects data for the given Request and Response.
  *
  * @param Request    $request   A Request instance
  * @param Response   $response  A Response instance
  * @param \Exception $exception An Exception instance
  *
  * @api
  */
 public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     if ($this->matcher->matches($request)) {
         $this->data = array('bootstrap' => function_exists('drupal_get_bootstrap_phase') ? drupal_get_bootstrap_phase() : -1, 'base_url' => $GLOBALS['base_url'], 'base_path' => $GLOBALS['base_path'], 'base_root' => $GLOBALS['base_root'], 'conf_path' => conf_path(), 'queries' => array());
         // Load .install files
         include_once DRUPAL_ROOT . '/includes/install.inc';
         drupal_load_updates();
         // Check run-time requirements and status information.
         $requirements = module_invoke_all('requirements', 'runtime');
         usort($requirements, '_system_sort_requirements');
         $this->data['requirements'] = $requirements;
         $this->data['severity'] = drupal_requirements_severity($requirements);
         $this->data['status_report'] = theme('status_report', array('requirements' => $requirements));
         if (isset($GLOBALS['databases']) && is_array($GLOBALS['databases'])) {
             foreach (array_keys($GLOBALS['databases']) as $key) {
                 $this->data['queries'][$key] = \Database::getLog('devel', $key);
             }
         }
     } else {
         $this->data = false;
     }
 }
예제 #11
0
 /**
  * {@inheritDoc}
  */
 public function matches(Request $request, Response $response)
 {
     if (!$this->requestMatcher->matches($request)) {
         return false;
     }
     if (!empty($this->criteria['match_response'])) {
         if (!$this->getExpressionLanguage()->evaluate($this->criteria['match_response'], array('response' => $response))) {
             return false;
         }
     } else {
         /* We can't use Response::isCacheable because that also checks if cache
          * headers are already set. As we are about to set them, that would
          * always return false.
          */
         $status = array(200, 203, 300, 301, 302, 404, 410);
         if (!empty($this->criteria['additional_cacheable_status'])) {
             $status = array_merge($status, $this->criteria['additional_cacheable_status']);
         }
         if (!in_array($response->getStatusCode(), $status)) {
             return false;
         }
     }
     return true;
 }
예제 #12
0
 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $request = $event->getRequest();
     if (!$this->requestMatcher->matches($request)) {
         return;
     }
     /** @var OrderInterface $order */
     $order = $this->cartContext->getCart();
     if ($order->isEmpty()) {
         $event->setResponse(new RedirectResponse($this->urlGenerator->generate('sylius_shop_cart_summary')));
     }
     $stateMachine = $this->stateMachineFactory->get($order, OrderCheckoutTransitions::GRAPH);
     if ($stateMachine->can($this->getRequestedTransition($request))) {
         return;
     }
     if (null !== ($referer = $this->getReferer($request))) {
         $event->setResponse(new RedirectResponse($referer));
         return;
     }
     $event->setResponse(new RedirectResponse($this->urlGenerator->generateForOrderCheckoutState($order)));
 }
예제 #13
0
 /**
  * Try to find a route & controller for the request
  *
  * @param GetResponseEvent $event
  */
 public function onMatchRequest(GetResponseEvent $event)
 {
     $this->matcher->matches($event->getRequest());
 }