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;
|
|
|
|
|
|
|
|
use Symfony\Component\Routing\Route;
|
|
|
|
use Symfony\Component\Routing\RouteCollection;
|
|
|
|
|
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
|
|
|
protected $defaults;
|
|
|
|
protected $context;
|
2010-02-17 13:53:31 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @param array $context The context
|
|
|
|
* @param array $defaults The default values
|
|
|
|
*/
|
|
|
|
public function __construct(array $context = array(), array $defaults = array())
|
2010-02-17 13:53:31 +00:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
$this->context = $context;
|
|
|
|
$this->defaults = $defaults;
|
2010-02-17 13:53:31 +00:00
|
|
|
}
|
|
|
|
|
2011-01-24 15:59:32 +00:00
|
|
|
/**
|
|
|
|
* Sets the request context.
|
|
|
|
*
|
|
|
|
* @param array $context The context
|
|
|
|
*/
|
|
|
|
public function setContext(array $context = array())
|
|
|
|
{
|
|
|
|
$this->context = $context;
|
|
|
|
}
|
|
|
|
|
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-09 16:25:44 +00:00
|
|
|
* @param string $pathinfo The pathinfo to be parsed
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
|
|
|
* @return array|false An array of parameters or false if no route matches
|
|
|
|
*/
|
2011-03-09 16:25:44 +00:00
|
|
|
public function match($pathinfo)
|
2010-02-17 13:53:31 +00:00
|
|
|
{
|
2010-05-07 15:09:11 +01:00
|
|
|
if (!isset($_SERVER['_ROUTING__route'])) {
|
2010-05-06 12:25:53 +01:00
|
|
|
// fall-back to the default UrlMatcher
|
|
|
|
return parent::match($url);
|
|
|
|
}
|
2010-02-17 13:53:31 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
$parameters = array();
|
2010-05-07 15:09:11 +01:00
|
|
|
foreach ($_SERVER as $key => $value) {
|
2010-05-08 14:32:30 +01:00
|
|
|
if ('_ROUTING_' === substr($key, 0, 9)) {
|
2010-05-06 12:25:53 +01:00
|
|
|
$parameters[substr($key, 9)] = $value;
|
|
|
|
unset($_SERVER[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $parameters;
|
|
|
|
}
|
2010-02-17 13:53:31 +00:00
|
|
|
}
|