Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitc9f527f

Browse files
committed
Avoid setting request attributes from signature arguments in AnnotationClassLoader
1 parent962370c commitc9f527f

File tree

8 files changed

+9
-62
lines changed

8 files changed

+9
-62
lines changed

‎src/Symfony/Component/HttpKernel/Controller/ArgumentResolver.php‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,7 @@ public function getArguments(Request $request, $controller)
5252
$arguments =array();
5353

5454
foreach ($this->argumentMetadataFactory->createArgumentMetadata($controller)as$metadata) {
55-
$resolvedValue =array();
5655
foreach ($this->argumentValueResolversas$resolver) {
57-
if (array() !==$resolvedValue) {
58-
break;
59-
}
60-
6156
if (!$resolver->supports($request,$metadata)) {
6257
continue;
6358
}
@@ -69,8 +64,11 @@ public function getArguments(Request $request, $controller)
6964
}
7065

7166
foreach ($resolvedas$append) {
72-
$resolvedValue[] =$append;
67+
$arguments[] =$append;
7368
}
69+
70+
// continue to the next controller argument
71+
continue2;
7472
}
7573

7674
$representative =$controller;
@@ -81,11 +79,7 @@ public function getArguments(Request $request, $controller)
8179
$representative =get_class($representative);
8280
}
8381

84-
if (array() ===$resolvedValue && !$metadata->isNullable()) {
85-
thrownew \RuntimeException(sprintf('Controller "%s" requires that you provide a value for the "$%s" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.',$representative,$metadata->getName()));
86-
}
87-
88-
$arguments =array_merge($arguments,$resolvedValue);
82+
thrownew \RuntimeException(sprintf('Controller "%s" requires that you provide a value for the "$%s" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.',$representative,$metadata->getName()));
8983
}
9084

9185
return$arguments;

‎src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/RequestAttributeValueResolver.php‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@ final class RequestAttributeValueResolver implements ArgumentValueResolverInterf
2727
*/
2828
publicfunctionsupports(Request$request,ArgumentMetadata$argument)
2929
{
30-
if ($argument->isVariadic()) {
31-
returnfalse;
32-
}
33-
34-
$argumentName =$argument->getName();
35-
36-
return$request->attributes->has($argumentName) &&null !==$request->attributes->get($argumentName);
30+
return !$argument->isVariadic() &&$request->attributes->has($argument->getName());
3731
}
3832

3933
/**

‎src/Symfony/Component/HttpKernel/ControllerMetadata/ArgumentMetadata.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct($name, $type, $isVariadic, $hasDefaultValue, $defaul
4040
$this->isVariadic =$isVariadic;
4141
$this->hasDefaultValue =$hasDefaultValue;
4242
$this->defaultValue =$defaultValue;
43-
$this->isNullable =$isNullable;
43+
$this->isNullable =$isNullable ||null ===$type || ($hasDefaultValue &&null ===$defaultValue);
4444
}
4545

4646
/**

‎src/Symfony/Component/HttpKernel/ControllerMetadata/ArgumentMetadataFactory.php‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function createArgumentMetadata($controller)
5858
}
5959

6060
foreach ($reflection->getParameters()as$param) {
61-
$arguments[] =newArgumentMetadata($param->getName(),$this->getType($param),$this->isVariadic($param),$this->hasDefaultValue($param),$this->getDefaultValue($param),$this->isDefaultNull($param));
61+
$arguments[] =newArgumentMetadata($param->getName(),$this->getType($param),$this->isVariadic($param),$this->hasDefaultValue($param),$this->getDefaultValue($param),$param->allowsNull());
6262
}
6363

6464
return$arguments;
@@ -126,13 +126,4 @@ private function getType(\ReflectionParameter $parameter)
126126
return$info[1];
127127
}
128128
}
129-
130-
privatefunctionisDefaultNull(\ReflectionParameter$parameter)
131-
{
132-
if ($this->getType($parameter)) {
133-
return$parameter->allowsNull();
134-
}
135-
136-
return$this->hasDefaultValue($parameter) &&null ===$parameter->getDefaultValue();
137-
}
138129
}

‎src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolverTest.php‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,6 @@ public function testGetArgumentsInjectsRequest()
148148
$this->assertEquals(array($request),self::$resolver->getArguments($request,$controller),'->getArguments() injects the request');
149149
}
150150

151-
publicfunctiontestGetArgumentsInjectsRequestEvenIfDefaultNull()
152-
{
153-
$request = Request::create('/');
154-
$controller =array(newself(),'controllerWithRequestDefaultNull');
155-
156-
$this->assertEquals(array($request),self::$resolver->getArguments($request,$controller),'->getArguments() injects the request');
157-
}
158-
159151
publicfunctiontestGetArgumentsInjectsExtendingRequest()
160152
{
161153
$request = ExtendingRequest::create('/');
@@ -248,15 +240,6 @@ public function testGetNullableArgumentsWithDefaults()
248240
$this->assertEquals(array(null,null,'value','mandatory'),self::$resolver->getArguments($request,$controller));
249241
}
250242

251-
publicfunctiontestGetArgumentsWithEquivalentNullAttribute()
252-
{
253-
$request = Request::create('/');
254-
$request->attributes->set('request',null);
255-
$controller =array(newself(),'controllerWithRequest');
256-
257-
$this->assertEquals(array($request),self::$resolver->getArguments($request,$controller),'->getArguments() injects the request');
258-
}
259-
260243
publicfunction__invoke($foo,$bar =null)
261244
{
262245
}
@@ -281,10 +264,6 @@ protected function controllerWithRequest(Request $request)
281264
{
282265
}
283266

284-
protectedfunctioncontrollerWithRequestDefaultNull(Request$request =null)
285-
{
286-
}
287-
288267
protectedfunctioncontrollerWithExtendingRequest(ExtendingRequest$request)
289268
{
290269
}

‎src/Symfony/Component/HttpKernel/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function testNullableTypesSignature()
121121
newArgumentMetadata('foo','string',false,false,null,true),
122122
newArgumentMetadata('bar', \stdClass::class,false,false,null,true),
123123
newArgumentMetadata('baz','string',false,true,'value',true),
124-
newArgumentMetadata('mandatory',null,false,false,null,false),
124+
newArgumentMetadata('mandatory',null,false,false,null,true),
125125
),$arguments);
126126
}
127127

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,6 @@ 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 (!isset($defaults[$param->getName()]) &&$param->isDefaultValueAvailable()) {
143-
$defaults[$param->getName()] =$param->getDefaultValue();
144-
}
145-
}
146141
$requirements =array_replace($globals['requirements'],$annot->getRequirements());
147142
$options =array_replace($globals['options'],$annot->getOptions());
148143
$schemes =array_merge($globals['schemes'],$annot->getSchemes());

‎src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,6 @@ public function testLoad($className, $routeData = array(), $methodArgs = array()
136136
array_intersect_assoc($routeData['options'],$route->getOptions()),
137137
'->load preserves options annotation'
138138
);
139-
$defaults =array_replace($methodArgs,$routeData['defaults']);
140-
$this->assertCount(
141-
count($defaults),
142-
array_intersect_assoc($defaults,$route->getDefaults()),
143-
'->load preserves defaults annotation and merges them with default arguments in method signature'
144-
);
145139
$this->assertEquals($routeData['schemes'],$route->getSchemes(),'->load preserves schemes annotation');
146140
$this->assertEquals($routeData['methods'],$route->getMethods(),'->load preserves methods annotation');
147141
$this->assertSame($routeData['condition'],$route->getCondition(),'->load preserves condition annotation');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp