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\MethodNotAllowedException
;
17 * ApacheUrlMatcher matches URL based on Apache mod_rewrite matching (see ApacheMatcherDumper).
19 * @author Fabien Potencier <fabien@symfony.com>
20 * @author Arnaud Le Blanc <arnaud.lb@gmail.com>
22 class ApacheUrlMatcher
extends UrlMatcher
25 * Tries to match a URL based on Apache mod_rewrite matching.
27 * Returns false if no route matches the URL.
29 * @param string $pathinfo The pathinfo to be parsed
31 * @return array An array of parameters
33 * @throws MethodNotAllowedException If the current method is not allowed
35 public function match($pathinfo)
37 $parameters = array();
42 foreach ($_SERVER as $key => $value) {
45 // skip non-routing variables
46 // this improves performance when $_SERVER contains many usual
47 // variables like HTTP_*, DOCUMENT_ROOT, REQUEST_URI, ...
48 if (false === strpos($name, '_ROUTING_')) {
52 while (0 === strpos($name, 'REDIRECT_')) {
53 $name = substr($name, 9);
56 // expect _ROUTING_<type>_<name>
59 if (0 !== strpos($name, '_ROUTING_')) {
62 if (false !== $pos = strpos($name, '_', 9)) {
63 $type = substr($name, 9, $pos-9);
64 $name = substr($name, $pos+
1);
66 $type = substr($name, 9);
69 if ('param' === $type) {
71 $parameters[$name] = $value;
73 } elseif ('default' === $type) {
74 $defaults[$name] = $value;
75 } elseif ('route' === $type) {
77 } elseif ('allow' === $type) {
81 unset($_SERVER[$key]);
84 if (null !== $route) {
85 $parameters['_route'] = $route;
87 return $this->mergeDefaults($parameters, $defaults);
88 } elseif (0 < count($allow)) {
89 throw new MethodNotAllowedException($allow);
91 return parent
::match($pathinfo);