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/tests/Symfony/Tests/Component/Routing/RouteCompiler.php
2010-08-20 23:09:55 +02:00

45 lines
1.6 KiB
PHP

<?php
namespace Symfony\Tests\Component\Routing;
use Symfony\Component\Routing\RouteCompiler as BaseRouteCompiler;
use Symfony\Component\Routing\Route;
class RouteCompiler extends BaseRouteCompiler
{
protected function tokenizeBufferBefore(&$buffer, &$tokens, &$afterASeparator, &$currentSeparator)
{
if ($afterASeparator && preg_match('#^=('.$this->options['variable_regex'].')#', $buffer, $match)) {
// 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]);
}
}
}