|
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\MethodNotAllowedException; |
|
15 use Symfony\Component\Routing\Route; |
|
16 use Symfony\Component\Routing\RouteCollection; |
|
17 |
|
18 /** |
|
19 * ApacheUrlMatcher matches URL based on Apache mod_rewrite matching (see ApacheMatcherDumper). |
|
20 * |
|
21 * @author Fabien Potencier <fabien@symfony.com> |
|
22 */ |
|
23 class ApacheUrlMatcher extends UrlMatcher |
|
24 { |
|
25 /** |
|
26 * Tries to match a URL based on Apache mod_rewrite matching. |
|
27 * |
|
28 * Returns false if no route matches the URL. |
|
29 * |
|
30 * @param string $pathinfo The pathinfo to be parsed |
|
31 * |
|
32 * @return array An array of parameters |
|
33 * |
|
34 * @throws MethodNotAllowedException If the current method is not allowed |
|
35 */ |
|
36 public function match($pathinfo) |
|
37 { |
|
38 $parameters = array(); |
|
39 $allow = array(); |
|
40 $match = false; |
|
41 |
|
42 foreach ($_SERVER as $key => $value) { |
|
43 $name = $key; |
|
44 |
|
45 if (0 === strpos($name, 'REDIRECT_')) { |
|
46 $name = substr($name, 9); |
|
47 } |
|
48 |
|
49 if (0 === strpos($name, '_ROUTING_')) { |
|
50 $name = substr($name, 9); |
|
51 } else { |
|
52 continue; |
|
53 } |
|
54 |
|
55 if ('_route' == $name) { |
|
56 $match = true; |
|
57 } elseif (0 === strpos($name, '_allow_')) { |
|
58 $allow[] = substr($name, 7); |
|
59 } else { |
|
60 $parameters[$name] = $value; |
|
61 } |
|
62 |
|
63 unset($_SERVER[$key]); |
|
64 } |
|
65 |
|
66 if ($match) { |
|
67 return $parameters; |
|
68 } elseif (0 < count($allow)) { |
|
69 throw new MethodNotAllowedException($allow); |
|
70 } else { |
|
71 return parent::match($pathinfo); |
|
72 } |
|
73 } |
|
74 } |