2010-06-24 07:46:50 +01:00
|
|
|
<?php
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
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-08-20 22:09:55 +01:00
|
|
|
namespace Symfony\Tests\Component\Routing;
|
2010-06-24 07:46:50 +01:00
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\Routing\RouteCompiler as BaseRouteCompiler;
|
|
|
|
use Symfony\Component\Routing\Route;
|
2010-06-24 07:46:50 +01:00
|
|
|
|
|
|
|
class RouteCompiler extends BaseRouteCompiler
|
|
|
|
{
|
|
|
|
protected function tokenizeBufferBefore(&$buffer, &$tokens, &$afterASeparator, &$currentSeparator)
|
|
|
|
{
|
2010-11-22 09:56:24 +00:00
|
|
|
if ($afterASeparator && preg_match('#^=([\w\d_]+)#', $buffer, $match)) {
|
2010-06-24 07:46:50 +01:00
|
|
|
// a labelled variable
|
|
|
|
$this->tokens[] = array('label', $currentSeparator, $match[0], $match[1]);
|
|
|
|
|
|
|
|
$currentSeparator = '';
|
|
|
|
$buffer = substr($buffer, strlen($match[0]));
|
|
|
|
$afterASeparator = false;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function compileForLabel($separator, $name, $variable)
|
|
|
|
{
|
|
|
|
if (null === $requirement = $this->route->getRequirement($variable)) {
|
|
|
|
$requirement = $this->options['variable_content_regex'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->segments[] = preg_quote($separator, '#').$variable.$separator.'(?P<'.$variable.'>'.$requirement.')';
|
|
|
|
$this->variables[$variable] = $name;
|
|
|
|
|
|
|
|
if (!$this->route->getDefault($variable)) {
|
|
|
|
$this->firstOptional = count($this->segments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function generateForLabel($optional, $tparams, $separator, $name, $variable)
|
|
|
|
{
|
|
|
|
if (!empty($tparams[$variable]) && (!$optional || !isset($this->defaults[$variable]) || $tparams[$variable] != $this->defaults[$variable])) {
|
|
|
|
return $variable.'/'.urlencode($tparams[$variable]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|