Navigation Menu

Skip to content

Commit

Permalink
[Routing] removed the variable_prefixes and variable_regex Route options
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Nov 22, 2010
1 parent e9d4d99 commit a79ed13
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 12 deletions.
6 changes: 1 addition & 5 deletions src/Symfony/Component/Routing/Route.php
Expand Up @@ -31,10 +31,8 @@ class Route
*
* Available options:
*
* * variable_prefixes: An array of characters that starts a variable name (: by default)
* * segment_separators: An array of allowed characters for segment separators (/ by default)
* * variable_regex: A regex that match a valid variable name ([\w\d_]+ by default)
* * text_regex: A regex that match a valid text name (.+? by default)
* * text_regex: A regex that match a valid text name (.+? by default)
* * compiler_class: A class name able to compile this route instance (RouteCompiler by default)
*
* @param string $pattern The pattern to match
Expand Down Expand Up @@ -103,9 +101,7 @@ public function getOptions()
public function setOptions(array $options)
{
$this->options = array_merge(array(
'variable_prefixes' => array(':'),
'segment_separators' => array('/', '.'),
'variable_regex' => '[\w\d_]+',
'text_regex' => '.+?',
'compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler',
), $options);
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Routing/RouteCompiler.php
Expand Up @@ -131,7 +131,7 @@ protected function tokenize()
if (false !== $this->tokenizeBufferBefore($buffer, $tokens, $afterASeparator, $currentSeparator)) {
// a custom token
$this->customToken = true;
} else if ($afterASeparator && preg_match('#^'.$this->options['variable_prefix_regex'].'('.$this->options['variable_regex'].')#', $buffer, $match)) {
} else if ($afterASeparator && preg_match('#^\:([\w\d_]+)#', $buffer, $match)) {
// a variable
$this->tokens[] = array('variable', $currentSeparator, $match[0], $match[1]);

Expand Down Expand Up @@ -227,7 +227,6 @@ protected function getOptions()

// compute some regexes
$quoter = function ($a) { return preg_quote($a, '#'); };
$options['variable_prefix_regex'] = '(?:'.implode('|', array_map($quoter, $options['variable_prefixes'])).')';
$options['segment_separators_regex'] = '(?:'.implode('|', array_map($quoter, $options['segment_separators'])).')';
$options['variable_content_regex'] = '[^'.implode('', array_map($quoter, $options['segment_separators'])).']+?';

Expand Down
2 changes: 0 additions & 2 deletions tests/Symfony/Tests/Component/Routing/CompiledRouteTest.php
Expand Up @@ -37,9 +37,7 @@ public function testgetPatterngetDefaultsgetOptionsgetRequirements()
$this->assertEquals(array('foo' => 'bar'), $compiled->getDefaults(), '->getDefaults() returns the route defaults');
$this->assertEquals(array('foo' => '\d+'), $compiled->getRequirements(), '->getRequirements() returns the route requirements');
$this->assertEquals(array_merge(array(
'variable_prefixes' => array(':'),
'segment_separators' => array('/', '.'),
'variable_regex' => '[\w\d_]+',
'text_regex' => '.+?',
'compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler',
), array('foo' => 'bar')), $compiled->getOptions(), '->getOptions() returns the route options');
Expand Down
2 changes: 1 addition & 1 deletion tests/Symfony/Tests/Component/Routing/RouteCompiler.php
Expand Up @@ -9,7 +9,7 @@ class RouteCompiler extends BaseRouteCompiler
{
protected function tokenizeBufferBefore(&$buffer, &$tokens, &$afterASeparator, &$currentSeparator)
{
if ($afterASeparator && preg_match('#^=('.$this->options['variable_regex'].')#', $buffer, $match)) {
if ($afterASeparator && preg_match('#^=([\w\d_]+)#', $buffer, $match)) {
// a labelled variable
$this->tokens[] = array('label', $currentSeparator, $match[0], $match[1]);

Expand Down
3 changes: 1 addition & 2 deletions tests/Symfony/Tests/Component/Routing/RouteTest.php
Expand Up @@ -40,9 +40,8 @@ public function testOptions()
{
$route = new Route('/:foo');
$route->setOptions(array('foo' => 'bar'));
$this->assertEquals(array_merge(array('variable_prefixes' => array(':'),
$this->assertEquals(array_merge(array(
'segment_separators' => array('/', '.'),
'variable_regex' => '[\w\d_]+',
'text_regex' => '.+?',
'compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler',
), array('foo' => 'bar')), $route->getOptions(), '->setOptions() sets the options');
Expand Down

0 comments on commit a79ed13

Please sign in to comment.