Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 33e78ce

Browse filesBrowse files
committed
[Routing] Fix BC break in AnnotationClassLoader defaults attributes handling
1 parent 9ef4271 commit 33e78ce
Copy full SHA for 33e78ce

File tree

8 files changed

+127
-3
lines changed
Filter options

8 files changed

+127
-3
lines changed

‎composer.json

Copy file name to clipboardExpand all lines: composer.json
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
"ircmaxell/password-compat": "~1.0",
8080
"ocramius/proxy-manager": "~0.4|~1.0|~2.0",
8181
"symfony/phpunit-bridge": "~3.2",
82-
"egulias/email-validator": "~1.2,>=1.2.1"
82+
"egulias/email-validator": "~1.2,>=1.2.1",
83+
"sensio/framework-extra-bundle": "^3.0.2"
8384
},
8485
"autoload": {
8586
"psr-4": {
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
13+
14+
class AnnotatedControllerTest extends WebTestCase
15+
{
16+
/**
17+
* @dataProvider getRoutes
18+
*/
19+
public function testAnnotatedController($path, $expectedValue)
20+
{
21+
$client = $this->createClient(array('test_case' => 'AnnotatedController', 'root_config' => 'config.yml'));
22+
$client->request('GET', '/annotated'.$path);
23+
24+
$this->assertSame(200, $client->getResponse()->getStatusCode());
25+
$this->assertSame($expectedValue, $client->getResponse()->getContent());
26+
}
27+
28+
public function getRoutes()
29+
{
30+
return array(
31+
array('/null_request', 'Symfony\Component\HttpFoundation\Request'),
32+
array('/null_argument', ''),
33+
array('/null_argument_with_route_param', ''),
34+
array('/null_argument_with_route_param/value', 'value'),
35+
array('/argument_with_route_param_and_default', 'value'),
36+
array('/argument_with_route_param_and_default/custom', 'custom'),
37+
);
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller;
13+
14+
use Symfony\Component\DependencyInjection\ContainerAware;
15+
use Symfony\Component\HttpFoundation\Request;
16+
use Symfony\Component\HttpFoundation\Response;
17+
use Symfony\Component\Routing\Annotation\Route;
18+
19+
class AnnotatedController extends ContainerAware
20+
{
21+
/**
22+
* @Route("/null_request", name="null_request")
23+
*/
24+
public function requestDefaultNullAction(Request $request = null)
25+
{
26+
return new Response($request ? get_class($request) : null);
27+
}
28+
29+
/**
30+
* @Route("/null_argument", name="null_argument")
31+
*/
32+
public function argumentDefaultNullWithoutRouteParamAction($value = null)
33+
{
34+
return new Response($value);
35+
}
36+
37+
/**
38+
* @Route("/null_argument_with_route_param/{value}", name="null_argument_with_route_param")
39+
*/
40+
public function argumentDefaultNullWithRouteParamAction($value = null)
41+
{
42+
return new Response($value);
43+
}
44+
45+
/**
46+
* @Route("/argument_with_route_param_and_default/{value}", defaults={"value": "value"}, name="argument_with_route_param_and_default")
47+
*/
48+
public function argumentWithoutDefaultWithRouteParamAndDefaultAction($value)
49+
{
50+
return new Response($value);
51+
}
52+
}
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle;
13+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
14+
use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle;
15+
16+
return array(
17+
new FrameworkBundle(),
18+
new TestBundle(),
19+
new SensioFrameworkExtraBundle(),
20+
);
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
imports:
2+
- { resource: ../config/default.yml }
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
annotated_controller:
2+
prefix: /annotated
3+
resource: "@TestBundle/Controller/AnnotatedController.php"
4+
type: annotation

‎src/Symfony/Bundle/FrameworkBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/composer.json
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"symfony/http-foundation": "~2.7",
2626
"symfony/http-kernel": "~2.7.23|~2.8.16",
2727
"symfony/filesystem": "~2.3",
28-
"symfony/routing": "~2.6,>2.6.4",
28+
"symfony/routing": "^2.7.24|^2.8.17",
2929
"symfony/security-core": "~2.6.13|~2.7.9|~2.8",
3030
"symfony/security-csrf": "~2.6",
3131
"symfony/stopwatch": "~2.3",
@@ -45,7 +45,8 @@
4545
"symfony/expression-language": "~2.6",
4646
"symfony/process": "~2.0,>=2.0.5",
4747
"symfony/validator": "~2.5",
48-
"symfony/yaml": "~2.0,>=2.0.5"
48+
"symfony/yaml": "~2.0,>=2.0.5",
49+
"sensio/framework-extra-bundle": "^3.0.2"
4950
},
5051
"suggest": {
5152
"symfony/console": "For using the console commands",

‎src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ protected function addRoute(RouteCollection $collection, $annot, $globals, \Refl
138138
}
139139

140140
$defaults = array_replace($globals['defaults'], $annot->getDefaults());
141+
foreach ($method->getParameters() as $param) {
142+
if (false !== strpos($globals['path'].$annot->getPath(), sprintf('{%s}', $param->getName())) && !isset($defaults[$param->getName()]) && $param->isDefaultValueAvailable()) {
143+
$defaults[$param->getName()] = $param->getDefaultValue();
144+
}
145+
}
141146
$requirements = array_replace($globals['requirements'], $annot->getRequirements());
142147
$options = array_replace($globals['options'], $annot->getOptions());
143148
$schemes = array_merge($globals['schemes'], $annot->getSchemes());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.