2010-02-17 13:53:31 +00:00
|
|
|
<?php
|
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
namespace Symfony\Component\Routing\Matcher;
|
2010-02-17 13:53:31 +00:00
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\Routing\Route;
|
|
|
|
use Symfony\Component\Routing\RouteCollection;
|
2010-02-17 13:53:31 +00:00
|
|
|
|
|
|
|
/*
|
2010-04-07 01:51:29 +01:00
|
|
|
* This file is part of the Symfony framework.
|
2010-02-17 13:53:31 +00:00
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*
|
|
|
|
* This source file is subject to the MIT license that is bundled
|
|
|
|
* with this source code in the file LICENSE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ApacheUrlMatcher matches URL based on Apache mod_rewrite matching (see ApacheMatcherDumper).
|
|
|
|
*
|
2010-10-17 12:45:15 +01:00
|
|
|
* @author Fabien Potencier <fabien.potencier@symfony-project.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
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* @param string $url URL to be parsed
|
|
|
|
*
|
|
|
|
* @return array|false An array of parameters or false if no route matches
|
|
|
|
*/
|
|
|
|
public function match($url)
|
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
|
|
|
}
|