Skip to content

Commit 4f3b3b3

Browse files
Merge branch '3.2'
* 3.2: (51 commits) [FrameworkBundle] [Workflow] Fix service marking store configuration Fix merge [Validator] add class name to the cache key [Serializer] Remove AbstractObjectNormalizer::isAttributeToNormalize Throw less misleading exception when property access not found [Twig] Fix deprecations with Twig 1.29 [FrameworkBundle] Fix validation cache warmer with failing or missing classes Fixed typo [FrameworkBundle] Removed the kernel.debug parameter from the cache pool namespace seed Fix email address fix the docblock in regard to the role argument [Bridge\Twig] Trigger deprecation when using FormExtension::$renderer Don't use the "app" global variable in the profiler [VarDumper] fix tests when xdebug is enabled Fix merge FIXED NON EXISTING TYPE DECLARATION [Form] Add failing test for data collector bug [Cache] Fix dumping SplDoublyLinkedList iter mode [Form] Fix FormDataCollector Ignore missing 'debug.file_link_formatter' service in Debug and Twig bundles ...
2 parents f87122d + 59abfc9 commit 4f3b3b3

File tree

7 files changed

+38
-4
lines changed

7 files changed

+38
-4
lines changed

Controller/ArgumentResolver/DefaultValueResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class DefaultValueResolver implements ArgumentValueResolverInterface
2727
*/
2828
public function supports(Request $request, ArgumentMetadata $argument)
2929
{
30-
return $argument->hasDefaultValue() || ($argument->isNullable() && !$argument->isVariadic());
30+
return $argument->hasDefaultValue() || (null !== $argument->getType() && $argument->isNullable() && !$argument->isVariadic());
3131
}
3232

3333
/**

Controller/ControllerResolver.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ class ControllerResolver implements ArgumentResolverInterface, ControllerResolve
3636
*/
3737
private $supportsVariadic;
3838

39+
/**
40+
* If scalar types exists.
41+
*
42+
* @var bool
43+
*/
44+
private $supportsScalarTypes;
45+
3946
/**
4047
* Constructor.
4148
*
@@ -46,6 +53,7 @@ public function __construct(LoggerInterface $logger = null)
4653
$this->logger = $logger;
4754

4855
$this->supportsVariadic = method_exists('ReflectionParameter', 'isVariadic');
56+
$this->supportsScalarTypes = method_exists('ReflectionParameter', 'getType');
4957
}
5058

5159
/**
@@ -140,7 +148,7 @@ protected function doGetArguments(Request $request, $controller, array $paramete
140148
$arguments[] = $request;
141149
} elseif ($param->isDefaultValueAvailable()) {
142150
$arguments[] = $param->getDefaultValue();
143-
} elseif ($param->allowsNull()) {
151+
} elseif ($this->supportsScalarTypes && $param->hasType() && $param->allowsNull()) {
144152
$arguments[] = null;
145153
} else {
146154
if (is_array($controller)) {

DataCollector/RequestDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function collect(Request $request, Response $response, \Exception $except
125125
continue;
126126
}
127127
if ('request_headers' === $key || 'response_headers' === $key) {
128-
$value = array_map(function ($v) { return isset($v[1]) ? $v : $v[0]; }, $value);
128+
$value = array_map(function ($v) { return isset($v[0]) && !isset($v[1]) ? $v[0] : $v; }, $value);
129129
}
130130
if ('request_server' !== $key && 'request_cookies' !== $key) {
131131
$this->data[$key] = array_map(array($this, 'cloneVar'), $value);

DependencyInjection/AddClassesToCachePass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private function getClassesInComposerClassMaps()
101101
}
102102

103103
if (is_array($function) && $function[0] instanceof ClassLoader) {
104-
$classes += $function[0]->getClassMap();
104+
$classes += array_filter($function[0]->getClassMap());
105105
}
106106
}
107107

Tests/Controller/ArgumentResolverTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,17 @@ public function testGetArgumentWithoutArray()
203203
$resolver->getArguments($request, $controller);
204204
}
205205

206+
/**
207+
* @expectedException \RuntimeException
208+
*/
209+
public function testIfExceptionIsThrownWhenMissingAnArgument()
210+
{
211+
$request = Request::create('/');
212+
$controller = array($this, 'controllerWithFoo');
213+
214+
self::$resolver->getArguments($request, $controller);
215+
}
216+
206217
/**
207218
* @requires PHP 7.1
208219
*/

Tests/Controller/ControllerResolverTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,20 @@ public function testCreateControllerCanReturnAnyCallable()
227227
$mock->getController($request);
228228
}
229229

230+
/**
231+
* @expectedException \RuntimeException
232+
* @group legacy
233+
*/
234+
public function testIfExceptionIsThrownWhenMissingAnArgument()
235+
{
236+
$resolver = new ControllerResolver();
237+
$request = Request::create('/');
238+
239+
$controller = array($this, 'controllerMethod1');
240+
241+
$resolver->getArguments($request, $controller);
242+
}
243+
230244
/**
231245
* @requires PHP 7.1
232246
* @group legacy

Tests/DataCollector/RequestDataCollectorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ protected function createResponse()
234234
$response = new Response();
235235
$response->setStatusCode(200);
236236
$response->headers->set('Content-Type', 'application/json');
237+
$response->headers->set('X-Foo-Bar', null);
237238
$response->headers->setCookie(new Cookie('foo', 'bar', 1, '/foo', 'localhost', true, true));
238239
$response->headers->setCookie(new Cookie('bar', 'foo', new \DateTime('@946684800')));
239240
$response->headers->setCookie(new Cookie('bazz', 'foo', '2000-12-12'));

0 commit comments

Comments
 (0)