2010-02-17 13:53:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-01-15 13:29:43 +00:00
|
|
|
* This file is part of the Symfony package.
|
2010-02-17 13:53:31 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-02-17 13:53:31 +00:00
|
|
|
*
|
2011-01-15 13:29:43 +00:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
2010-02-17 13:53:31 +00:00
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Component\Routing\Matcher;
|
|
|
|
|
2011-05-17 09:11:27 +01:00
|
|
|
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
|
2011-01-15 13:29:43 +00:00
|
|
|
|
2010-02-17 13:53:31 +00:00
|
|
|
/**
|
|
|
|
* ApacheUrlMatcher matches URL based on Apache mod_rewrite matching (see ApacheMatcherDumper).
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2010-02-17 13:53:31 +00:00
|
|
|
*/
|
|
|
|
class ApacheUrlMatcher extends UrlMatcher
|
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Tries to match a URL based on Apache mod_rewrite matching.
|
|
|
|
*
|
|
|
|
* Returns false if no route matches the URL.
|
|
|
|
*
|
2011-03-21 12:56:53 +00:00
|
|
|
* @param string $pathinfo The pathinfo to be parsed
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
2011-03-21 12:56:53 +00:00
|
|
|
* @return array An array of parameters
|
|
|
|
*
|
|
|
|
* @throws MethodNotAllowedException If the current method is not allowed
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
2011-03-09 16:25:44 +00:00
|
|
|
public function match($pathinfo)
|
2010-02-17 13:53:31 +00:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
$parameters = array();
|
2012-07-12 10:39:38 +01:00
|
|
|
$defaults = array();
|
2011-03-21 12:56:53 +00:00
|
|
|
$allow = array();
|
|
|
|
$match = false;
|
|
|
|
|
2010-05-07 15:09:11 +01:00
|
|
|
foreach ($_SERVER as $key => $value) {
|
2011-03-21 12:56:53 +00:00
|
|
|
$name = $key;
|
|
|
|
|
|
|
|
if (0 === strpos($name, 'REDIRECT_')) {
|
|
|
|
$name = substr($name, 9);
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
2011-03-21 12:56:53 +00:00
|
|
|
|
2012-07-12 10:39:38 +01:00
|
|
|
if (0 === strpos($name, '_ROUTING_DEFAULTS_')) {
|
|
|
|
$name = substr($name, 18);
|
|
|
|
$defaults[$name] = $value;
|
|
|
|
} elseif (0 === strpos($name, '_ROUTING_')) {
|
2011-03-21 12:56:53 +00:00
|
|
|
$name = substr($name, 9);
|
2012-07-12 10:39:38 +01:00
|
|
|
if ('_route' == $name) {
|
|
|
|
$match = true;
|
|
|
|
$parameters[$name] = $value;
|
|
|
|
} elseif (0 === strpos($name, '_allow_')) {
|
|
|
|
$allow[] = substr($name, 7);
|
|
|
|
} else {
|
|
|
|
$parameters[$name] = $value;
|
|
|
|
}
|
2011-03-21 12:56:53 +00:00
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
unset($_SERVER[$key]);
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
2011-03-21 12:56:53 +00:00
|
|
|
if ($match) {
|
2012-07-12 10:39:38 +01:00
|
|
|
return $this->mergeDefaults($parameters, $defaults);
|
2011-03-21 12:56:53 +00:00
|
|
|
} elseif (0 < count($allow)) {
|
|
|
|
throw new MethodNotAllowedException($allow);
|
|
|
|
} else {
|
|
|
|
return parent::match($pathinfo);
|
|
|
|
}
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
2010-02-17 13:53:31 +00:00
|
|
|
}
|