[Routing] removed the variable_prefixes and variable_regex Route options
This commit is contained in:
parent
e9d4d990df
commit
a79ed13624
@ -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
|
||||
@ -103,9 +101,7 @@ class Route
|
||||
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);
|
||||
|
@ -131,7 +131,7 @@ class RouteCompiler implements RouteCompilerInterface
|
||||
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]);
|
||||
|
||||
@ -227,7 +227,6 @@ class RouteCompiler implements RouteCompilerInterface
|
||||
|
||||
// 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'])).']+?';
|
||||
|
||||
|
@ -37,9 +37,7 @@ class CompiledRouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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');
|
||||
|
@ -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]);
|
||||
|
||||
|
@ -40,9 +40,8 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$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');
|
||||
|
Reference in New Issue
Block a user