Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f799b6c

Browse files
[DI] Fix AutowirePass fatal error with classes that have non-existing parents
1 parent 1735b85 commit f799b6c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ private function completeDefinition($id, Definition $definition)
107107
}
108108
}
109109
}
110-
} catch (\ReflectionException $reflectionException) {
110+
} catch (\ReflectionException $e) {
111111
// Typehint against a non-existing class
112112

113113
if (!$parameter->isDefaultValueAvailable()) {
114-
throw new RuntimeException(sprintf('Cannot autowire argument %s for %s because the type-hinted class does not exist (%s).', $index + 1, $definition->getClass(), $reflectionException->getMessage()), 0, $reflectionException);
114+
throw new RuntimeException(sprintf('Cannot autowire argument %s for %s because the type-hinted class does not exist (%s).', $index + 1, $definition->getClass(), $e->getMessage()), 0, $e);
115115
}
116116

117117
$value = $parameter->getDefaultValue();
@@ -242,12 +242,16 @@ private function getReflectionClass($id, Definition $definition)
242242
}
243243

244244
$class = $this->container->getParameterBag()->resolveValue($class);
245+
$throwingAutoloader = function () { throw new \ReflectionException(); };
246+
$reflector = false;
245247

246248
try {
249+
spl_autoload_register($throwingAutoloader);
247250
$reflector = new \ReflectionClass($class);
248-
} catch (\ReflectionException $reflectionException) {
249-
$reflector = false;
251+
} catch (\Error $e) {
252+
} catch (\Exception $e) {
250253
}
254+
spl_autoload_unregister($throwingAutoloader);
251255

252256
return $this->reflectionClasses[$id] = $reflector;
253257
}

0 commit comments

Comments
 (0)