Skip to content

Commit 43585d8

Browse files
committed
Merge pull request symfony#51 from symfony-cmf/support-2.2-routepattern
symfony 2.2 can have any string as route name
2 parents 72df1da + 79111ff commit 43585d8

File tree

5 files changed

+6
-42
lines changed

5 files changed

+6
-42
lines changed

ChainRouter.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,9 @@ public function generate($name, $parameters = array(), $absolute = false)
199199
/** @var $router RouterInterface */
200200
foreach ($this->all() as $router) {
201201

202-
// if $name and $router does not implement ChainedRouterInterface and $name is not a string, continue
203-
// if $name and $router does not implement ChainedRouterInterface and $name is string but does not match a default Symfony2 route name, continue
202+
// if $router does not implement ChainedRouterInterface and $name is not a string, continue
204203
if ($name && !$router instanceof ChainedRouterInterface) {
205-
if (!is_string($name) || !preg_match(VersatileGeneratorInterface::CORE_NAME_PATTERN, $name)) {
204+
if (! is_string($name)) {
206205
continue;
207206
}
208207
}

DynamicRouter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function supports($name)
141141
return $this->generator->supports($name);
142142
}
143143

144-
return (!is_string($name) || !preg_match(VersatileGeneratorInterface::CORE_NAME_PATTERN, $name));
144+
return is_string($name);
145145
}
146146

147147
/**

NestedMatcher/ConfigurableUrlMatcher.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* A final matcher that can proxy any matcher having the right constructor
1515
* signature, the same way the symfony core Router class does.
1616
*
17+
* SYMFONY 2.1 COMPATIBILITY only. With 2.2 we could use the extending UrlMatcher class
18+
*
1719
* @author DavidBuchmann
1820
*/
1921
class ConfigurableUrlMatcher implements FinalMatcherInterface
@@ -35,7 +37,7 @@ public function finalMatch(RouteCollection $collection, Request $request)
3537
$matcher = $this->getMatcher($collection, $context);
3638
$attributes = $matcher->match($request->getPathInfo());
3739

38-
// cleanup route attributes
40+
// SYMFONY 2.1 COMPATIBILITY: cleanup route attributes
3941
if (! isset($attributes[RouteObjectInterface::ROUTE_OBJECT])
4042
|| ! $attributes[RouteObjectInterface::ROUTE_OBJECT] instanceof Route
4143
) {

Tests/Routing/ChainRouterTest.php

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -488,37 +488,6 @@ public function testGenerateObjectName()
488488
$this->assertEquals($name, $result);
489489
}
490490

491-
public function testGenerateNonDefaultStringName()
492-
{
493-
$name = '/test/this';
494-
$parameters = array('test' => 'value');
495-
496-
$defaultRouter = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
497-
$chainedRouter = $this->getMock('Symfony\\Cmf\\Component\\Routing\\ChainedRouterInterface');
498-
499-
$defaultRouter
500-
->expects($this->never())
501-
->method('generate')
502-
;
503-
$chainedRouter
504-
->expects($this->once())
505-
->method('supports')
506-
->will($this->returnValue(true))
507-
;
508-
$chainedRouter
509-
->expects($this->once())
510-
->method('generate')
511-
->with($name, $parameters, false)
512-
->will($this->returnValue($name))
513-
;
514-
515-
$this->router->add($defaultRouter, 200);
516-
$this->router->add($chainedRouter, 100);
517-
518-
$result = $this->router->generate($name, $parameters);
519-
$this->assertEquals($name, $result);
520-
}
521-
522491
public function testWarmup()
523492
{
524493
$dir = 'test_dir';

VersatileGeneratorInterface.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010
*/
1111
interface VersatileGeneratorInterface extends UrlGeneratorInterface
1212
{
13-
/**
14-
* If $name preg_match this pattern, the name is valid for symfony core
15-
* compatible generators.
16-
*/
17-
const CORE_NAME_PATTERN = '/^[a-z0-9A-Z_.]+$/';
18-
1913
/**
2014
* Whether this generator supports the supplied $name.
2115
*

0 commit comments

Comments
 (0)