Skip to content

Commit fb46282

Browse files
committed
remove forcing a default format
1 parent b307d60 commit fb46282

File tree

5 files changed

+43
-9
lines changed

5 files changed

+43
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Changelog
44
1.1.0-RC3
55
---------
66

7+
* **2013-09-04**: If the route matched a pattern with a format extension, the format
8+
extension is no longer set as route a default
79
* **2013-09-04**: Marked ContentAwareGenerator as obsolete, use ContentAwareGenerator
810
from the CMF routing component directly instead. This class will be removed in 1.2
911
* **2013-08-09**: dynamic.generic_controller is now defaulting to null instead

Doctrine/Phpcr/RouteProvider.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,11 @@ public function getRouteCollectionForRequest(Request $request)
5656
return $collection;
5757
}
5858

59-
$format = preg_match('/.+\.([a-z]+)$/i', $url, $matches) ? $matches[1] : false;
60-
6159
try {
6260
$routes = $this->getObjectManager()->findMany($this->className, $candidates);
6361
// filter for valid route objects
6462
foreach ($routes as $key => $route) {
6563
if ($route instanceof SymfonyRoute) {
66-
if ($format && null === $route->getDefault('_format')) {
67-
$route->setDefault('_format', $format);
68-
}
6964
$collection->add($key, $route);
7065
}
7166
}
@@ -112,6 +107,7 @@ public function getRouteByName($name, $parameters = array())
112107
if (!$route) {
113108
throw new RouteNotFoundException(sprintf('No route found for path "%s"', $name));
114109
}
110+
115111
if (!$route instanceof SymfonyRoute) {
116112
throw new RouteNotFoundException(sprintf('Document at path "%s" is no route', $name));
117113
}
@@ -125,7 +121,7 @@ public function getRouteByName($name, $parameters = array())
125121
public function getRoutesByNames($names, $parameters = array())
126122
{
127123
$collection = $this->getObjectManager()->findMany($this->className, $names);
128-
foreach($collection as $key => $document) {
124+
foreach ($collection as $key => $document) {
129125
if (!$document instanceof SymfonyRoute) {
130126
// we follow the logic of DocumentManager::findMany and do not throw an exception
131127
unset($collection[$key]);

Tests/Functional/Doctrine/Phpcr/RouteProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function testGetRouteCollectionForRequestFormat()
8686
$this->assertEquals('html', $testroute->getDefault('_format'));
8787
list($key, $root) = each($routes);
8888
$this->assertEquals(self::ROUTE_ROOT, $key);
89-
$this->assertEquals('html', $root->getDefault('_format'));
89+
$this->assertEquals(null, $root->getDefault('_format'));
9090
}
9191

9292
public function testGetRouteCollectionForRequestNophpcrUrl()

Tests/Functional/Routing/DynamicRouterTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ public function setUp()
6060
$formatroute->setDefault(RouteObjectInterface::CONTROLLER_NAME, 'testController');
6161
$this->getDm()->persist($formatroute);
6262

63+
$format2jsonroute = new Route(true);
64+
$format2jsonroute->setPosition($root, 'format2.json');
65+
$format2jsonroute->setDefault('_format', 'json');
66+
$format2jsonroute->setRequirement('_format', 'json');
67+
$format2jsonroute->setDefault(RouteObjectInterface::CONTROLLER_NAME, 'testJsonController');
68+
$this->getDm()->persist($format2jsonroute);
69+
70+
$format2route = new Route(true);
71+
$format2route->setPosition($root, 'format2');
72+
$format2route->setDefault(RouteObjectInterface::CONTROLLER_NAME, 'testController');
73+
$this->getDm()->persist($format2route);
74+
6375
$this->getDm()->flush();
6476
}
6577

@@ -153,6 +165,30 @@ public function testMatchFormat()
153165

154166
$this->assertTrue($request->attributes->has(DynamicRouter::ROUTE_KEY));
155167
$this->assertEquals($expected, $matches);
168+
169+
$expected = array(
170+
'_controller' => 'testController',
171+
'_format' => 'html',
172+
RouteObjectInterface::ROUTE_NAME => '/test/routing/format2',
173+
);
174+
$request = Request::create('/format2.html');
175+
$matches = $this->router->matchRequest($request);
176+
ksort($matches);
177+
178+
$this->assertTrue($request->attributes->has(DynamicRouter::ROUTE_KEY));
179+
$this->assertEquals($expected, $matches);
180+
181+
$expected = array(
182+
'_controller' => 'testJsonController',
183+
'_format' => 'json',
184+
RouteObjectInterface::ROUTE_NAME => '/test/routing/format2.json',
185+
);
186+
$request = Request::create('/format2.json');
187+
$matches = $this->router->matchRequest($request);
188+
ksort($matches);
189+
190+
$this->assertTrue($request->attributes->has(DynamicRouter::ROUTE_KEY));
191+
$this->assertEquals($expected, $matches);
156192
}
157193

158194
/**

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"symfony/framework-bundle": "~2.2"
2020
},
2121
"require-dev": {
22-
"symfony-cmf/core-bundle": "~1.0.0-alpha1",
22+
"symfony-cmf/core-bundle": "1.0.*",
2323
"symfony-cmf/testing": "1.0.*",
2424
"sonata-project/doctrine-phpcr-admin-bundle": "1.0.*",
2525
"symfony/monolog-bundle": "2.2.*",
@@ -31,7 +31,7 @@
3131
"doctrine/orm": "To enable support for the ORM entities",
3232

3333
"symfony-cmf/content-bundle": "To optionally use the configured value for 'content_basepath' from the CoreBundle",
34-
"symfony-cmf/core-bundle": "For compatibility with Symfony 2.2",
34+
"symfony-cmf/core-bundle": "For compatibility with Symfony 2.2 and easier configuration",
3535

3636
"sonata-project/doctrine-phpcr-admin-bundle": "To provide an admin interface for the PHPCR ODM documents"
3737
},

0 commit comments

Comments
 (0)