This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Routing/Matcher/ApacheUrlMatcher.php
2011-03-11 10:40:38 +01:00

76 lines
1.9 KiB
PHP

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Routing\Matcher;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
/**
* ApacheUrlMatcher matches URL based on Apache mod_rewrite matching (see ApacheMatcherDumper).
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class ApacheUrlMatcher extends UrlMatcher
{
protected $defaults;
protected $context;
/**
* Constructor.
*
* @param array $context The context
* @param array $defaults The default values
*/
public function __construct(array $context = array(), array $defaults = array())
{
$this->context = $context;
$this->defaults = $defaults;
}
/**
* Sets the request context.
*
* @param array $context The context
*/
public function setContext(array $context = array())
{
$this->context = $context;
}
/**
* Tries to match a URL based on Apache mod_rewrite matching.
*
* Returns false if no route matches the URL.
*
* @param string $pathinfo The pathinfo to be parsed
*
* @return array|false An array of parameters or false if no route matches
*/
public function match($pathinfo)
{
if (!isset($_SERVER['_ROUTING__route'])) {
// fall-back to the default UrlMatcher
return parent::match($pathinfo);
}
$parameters = array();
foreach ($_SERVER as $key => $value) {
if ('_ROUTING_' === substr($key, 0, 9)) {
$parameters[substr($key, 9)] = $value;
unset($_SERVER[$key]);
}
}
return $parameters;
}
}