4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Routing\Matcher;
14 use Symfony\Component\Routing\Exception\ResourceNotFoundException;
15 use Symfony\Component\Routing\Route;
18 * @author Fabien Potencier <fabien@symfony.com>
20 abstract class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatcherInterface
25 public function match($pathinfo)
28 $parameters = parent::match($pathinfo);
29 } catch (ResourceNotFoundException $e) {
30 if ('/' === substr($pathinfo, -1) || !\in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
35 $parameters = parent::match($pathinfo.'/');
37 return array_replace($parameters, $this->redirect($pathinfo.'/', isset($parameters['_route']) ? $parameters['_route'] : null));
38 } catch (ResourceNotFoundException $e2) {
49 protected function handleRouteRequirements($pathinfo, $name, Route $route)
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);
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)));
63 return array(self::REQUIREMENT_MATCH, null);