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