Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 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\ExceptionInterface;
15
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
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(string $pathinfo)
26
    {
27
        try {
28
            return parent::match($pathinfo);
29
        } catch (ResourceNotFoundException $e) {
30
            if (!\in_array($this->context->getMethod(), ['HEAD', 'GET'], true)) {
31
                throw $e;
32
            }
33
 
34
            if ($this->allowSchemes) {
35
                redirect_scheme:
36
                $scheme = $this->context->getScheme();
37
                $this->context->setScheme(current($this->allowSchemes));
38
                try {
39
                    $ret = parent::match($pathinfo);
40
 
41
                    return $this->redirect($pathinfo, $ret['_route'] ?? null, $this->context->getScheme()) + $ret;
42
                } catch (ExceptionInterface $e2) {
43
                    throw $e;
44
                } finally {
45
                    $this->context->setScheme($scheme);
46
                }
47
            } elseif ('/' === $trimmedPathinfo = rtrim($pathinfo, '/') ?: '/') {
48
                throw $e;
49
            } else {
50
                try {
51
                    $pathinfo = $trimmedPathinfo === $pathinfo ? $pathinfo.'/' : $trimmedPathinfo;
52
                    $ret = parent::match($pathinfo);
53
 
54
                    return $this->redirect($pathinfo, $ret['_route'] ?? null) + $ret;
55
                } catch (ExceptionInterface $e2) {
56
                    if ($this->allowSchemes) {
57
                        goto redirect_scheme;
58
                    }
59
                    throw $e;
60
                }
61
            }
62
        }
63
    }
64
}