[Routing] added a proper exception when a route pattern references the same variable more than once (closes #3344)

This commit is contained in:
Fabien Potencier 2012-02-14 11:41:45 +01:00
parent 802fe644fb
commit ec7fb0bdd6
2 changed files with 15 additions and 0 deletions

View File

@ -51,6 +51,11 @@ class RouteCompiler implements RouteCompilerInterface
}
$tokens[] = array('variable', $match[0][0][0], $regexp, $var);
if (in_array($var, $variables)) {
throw new \LogicException(sprintf('Route pattern "%s" cannot reference variable name "%s" more than once.', $route->getPattern(), $var));
}
$variables[] = $var;
}

View File

@ -98,4 +98,14 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
)),
);
}
/**
* @expectedException \LogicException
*/
public function testRouteWithSameVariableTwice()
{
$route = new Route('/{name}/{name}');
$compiled = $route->compile();
}
}