vendor/symfony/routing/Matcher/RedirectableUrlMatcher.php line 28

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Routing\Matcher;
  11. use Symfony\Component\Routing\Exception\ResourceNotFoundException;
  12. use Symfony\Component\Routing\Route;
  13. /**
  14.  * @author Fabien Potencier <fabien@symfony.com>
  15.  */
  16. abstract class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatcherInterface
  17. {
  18.     /**
  19.      * {@inheritdoc}
  20.      */
  21.     public function match($pathinfo)
  22.     {
  23.         try {
  24.             $parameters parent::match($pathinfo);
  25.         } catch (ResourceNotFoundException $e) {
  26.             if ('/' === substr($pathinfo, -1) || !\in_array($this->context->getMethod(), ['HEAD''GET'])) {
  27.                 throw $e;
  28.             }
  29.             try {
  30.                 $parameters parent::match($pathinfo.'/');
  31.                 return array_replace($parameters$this->redirect($pathinfo.'/', isset($parameters['_route']) ? $parameters['_route'] : null));
  32.             } catch (ResourceNotFoundException $e2) {
  33.                 throw $e;
  34.             }
  35.         }
  36.         return $parameters;
  37.     }
  38.     /**
  39.      * {@inheritdoc}
  40.      */
  41.     protected function handleRouteRequirements($pathinfo$nameRoute $route)
  42.     {
  43.         // expression condition
  44.         if ($route->getCondition() && !$this->getExpressionLanguage()->evaluate($route->getCondition(), ['context' => $this->context'request' => $this->request ?: $this->createRequest($pathinfo)])) {
  45.             return [self::REQUIREMENT_MISMATCHnull];
  46.         }
  47.         // check HTTP scheme requirement
  48.         $scheme $this->context->getScheme();
  49.         $schemes $route->getSchemes();
  50.         if ($schemes && !$route->hasScheme($scheme)) {
  51.             return [self::ROUTE_MATCH$this->redirect($pathinfo$namecurrent($schemes))];
  52.         }
  53.         return [self::REQUIREMENT_MATCHnull];
  54.     }
  55. }