Skip to content

Commit 07f1ff5

Browse files
committed
Merge branch '3.3' into 3.4
* 3.3: [Security] added more tests [Security] fixed default target path when referer contains a query string [Security] simplified tests [Security] refactored tests [WebProfilerBundle][TwigBundle] Fix infinite js loop on exception pages [FrameworkBundle] fix ValidatorCacheWarmer: use serializing ArrayAdapter Change "this" to "that" to avoid confusion [VarDumper] Move locale sniffing to dump() time [VarDumper] Use "C" locale when using "comma" flags [Config] Make ClassExistenceResource throw on invalid parents
2 parents 4e5b421 + 3bbfe51 commit 07f1ff5

File tree

6 files changed

+19
-13
lines changed

6 files changed

+19
-13
lines changed

Compiler/AutowirePass.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ private function doProcessValue($value, $isRoot = false)
124124
if (!$value instanceof Definition || !$value->isAutowired() || $value->isAbstract() || !$value->getClass()) {
125125
return $value;
126126
}
127-
if (!$reflectionClass = $this->container->getReflectionClass($value->getClass())) {
128-
$this->container->log($this, sprintf('Skipping service "%s": Class or interface "%s" does not exist.', $this->currentId, $value->getClass()));
127+
if (!$reflectionClass = $this->container->getReflectionClass($value->getClass(), false)) {
128+
$this->container->log($this, sprintf('Skipping service "%s": Class or interface "%s" cannot be loaded.', $this->currentId, $value->getClass()));
129129

130130
return $value;
131131
}
@@ -388,7 +388,7 @@ private function populateAvailableType($id, Definition $definition)
388388
unset($this->ambiguousServiceTypes[$type]);
389389
}
390390

391-
if ($definition->isDeprecated() || !$reflectionClass = $this->container->getReflectionClass($definition->getClass())) {
391+
if ($definition->isDeprecated() || !$reflectionClass = $this->container->getReflectionClass($definition->getClass(), false)) {
392392
return;
393393
}
394394

@@ -444,7 +444,7 @@ private function set($type, $id)
444444
*/
445445
private function createAutowiredDefinition($type)
446446
{
447-
if (!($typeHint = $this->container->getReflectionClass($type)) || !$typeHint->isInstantiable()) {
447+
if (!($typeHint = $this->container->getReflectionClass($type, false)) || !$typeHint->isInstantiable()) {
448448
return;
449449
}
450450

@@ -478,8 +478,8 @@ private function createAutowiredDefinition($type)
478478

479479
private function createTypeNotFoundMessage(TypedReference $reference, $label)
480480
{
481-
if (!$r = $this->container->getReflectionClass($type = $reference->getType())) {
482-
$message = sprintf('has type "%s" but this class does not exist.', $type);
481+
if (!$r = $this->container->getReflectionClass($type = $reference->getType(), false)) {
482+
$message = sprintf('has type "%s" but this class cannot be loaded.', $type);
483483
} else {
484484
$message = $this->container->has($type) ? 'this service is abstract' : 'no such service exists';
485485
$message = sprintf('references %s "%s" but %s.%s', $r->isInterface() ? 'interface' : 'class', $type, $message, $this->createTypeAlternatives($reference));

Compiler/FactoryReturnTypePass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private function updateDefinition(ContainerBuilder $container, $id, Definition $
8181
$class = $factory[0];
8282
}
8383

84-
if (!$m = $container->getReflectionClass($class)) {
84+
if (!$m = $container->getReflectionClass($class, false)) {
8585
return;
8686
}
8787
try {

Compiler/PriorityTaggedServiceTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ trait PriorityTaggedServiceTrait
2626
*
2727
* The order of additions must be respected for services having the same priority,
2828
* and knowing that the \SplPriorityQueue class does not respect the FIFO method,
29-
* we should not use this class.
29+
* we should not use that class.
3030
*
3131
* @see https://bugs.php.net/bug.php?id=53710
3232
* @see https://bugs.php.net/bug.php?id=60926

Compiler/ResolveInstanceofConditionalsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private function processDefinition(ContainerBuilder $container, $id, Definition
6666
$instanceofTags = array();
6767

6868
foreach ($conditionals as $interface => $instanceofDefs) {
69-
if ($interface !== $class && (!$container->getReflectionClass($class))) {
69+
if ($interface !== $class && (!$container->getReflectionClass($class, false))) {
7070
continue;
7171
}
7272

ContainerBuilder.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,15 @@ public function addClassResource(\ReflectionClass $class)
337337
* Retrieves the requested reflection class and registers it for resource tracking.
338338
*
339339
* @param string $class
340+
* @param bool $throw
340341
*
341342
* @return \ReflectionClass|null
342343
*
344+
* @throws \ReflectionException when a parent class/interface/trait is not found and $throw is true
345+
*
343346
* @final
344347
*/
345-
public function getReflectionClass($class)
348+
public function getReflectionClass($class, $throw = true)
346349
{
347350
if (!$class = $this->getParameterBag()->resolveValue($class)) {
348351
return;
@@ -357,6 +360,9 @@ public function getReflectionClass($class)
357360
$classReflector = $resource->isFresh(0) ? false : new \ReflectionClass($class);
358361
}
359362
} catch (\ReflectionException $e) {
363+
if ($throw) {
364+
throw $e;
365+
}
360366
$classReflector = false;
361367
}
362368

Tests/Compiler/AutowirePassTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ public function testDontTriggerAutowiring()
359359

360360
/**
361361
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
362-
* @expectedExceptionMessage Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class does not exist.
362+
* @expectedExceptionMessage Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class cannot be loaded.
363363
*/
364364
public function testClassNotFoundThrowsException()
365365
{
@@ -374,7 +374,7 @@ public function testClassNotFoundThrowsException()
374374

375375
/**
376376
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
377-
* @expectedExceptionMessage Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadParentTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\OptionalServiceClass" but this class does not exist.
377+
* @expectedExceptionMessage Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadParentTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\OptionalServiceClass" but this class cannot be loaded.
378378
*/
379379
public function testParentClassNotFoundThrowsException()
380380
{
@@ -744,7 +744,7 @@ public function testNotWireableCalls($method, $expectedMsg)
744744
public function provideNotWireableCalls()
745745
{
746746
return array(
747-
array('setNotAutowireable', 'Cannot autowire service "foo": argument "$n" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setNotAutowireable()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class does not exist.'),
747+
array('setNotAutowireable', 'Cannot autowire service "foo": argument "$n" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setNotAutowireable()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class cannot be loaded.'),
748748
array('setDifferentNamespace', 'Cannot autowire service "foo": argument "$n" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setDifferentNamespace()" references class "stdClass" but no such service exists. It cannot be auto-registered because it is from a different root namespace.'),
749749
array(null, 'Cannot autowire service "foo": method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setProtectedMethod()" must be public.'),
750750
);

0 commit comments

Comments
 (0)