diff --git a/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php
index c61acdf065183..fa8c636edcd1f 100644
--- a/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php
+++ b/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php
@@ -60,11 +60,16 @@ public function registerClasses(Definition $prototype, $namespace, $resource, $e
$interfaces = array();
$singlyImplemented = array();
- foreach ($classes as $class) {
+ foreach ($classes as $class => $errorMessage) {
if (interface_exists($class, false)) {
$interfaces[] = $class;
} else {
- $this->setDefinition($class, unserialize($serializedPrototype));
+ $this->setDefinition($class, $definition = unserialize($serializedPrototype));
+ if (null !== $errorMessage) {
+ $definition->addError($errorMessage);
+
+ continue;
+ }
foreach (class_implements($class, false) as $interface) {
$singlyImplemented[$interface] = isset($singlyImplemented[$interface]) ? false : $class;
}
@@ -139,13 +144,25 @@ private function findClasses($namespace, $pattern, $excludePattern)
if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)*+$/', $class)) {
continue;
}
+
+ try {
+ $r = $this->container->getReflectionClass($class);
+ } catch (\ReflectionException $e) {
+ $classes[$class] = sprintf(
+ 'While discovering services from namespace "%s", an error was thrown when processing the class "%s": "%s".',
+ $namespace,
+ $class,
+ $e->getMessage()
+ );
+ continue;
+ }
// check to make sure the expected class exists
- if (!$r = $this->container->getReflectionClass($class)) {
+ if (!$r) {
throw new InvalidArgumentException(sprintf('Expected to find class "%s" in file "%s" while importing services from resource "%s", but it was not found! Check the namespace prefix used with the resource.', $class, $path, $pattern));
}
if ($r->isInstantiable() || $r->isInterface()) {
- $classes[] = $class;
+ $classes[$class] = null;
}
}
diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/Prototype/BadClasses/MissingParent.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/Prototype/BadClasses/MissingParent.php
new file mode 100644
index 0000000000000..53c97249cf3f2
--- /dev/null
+++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/Prototype/BadClasses/MissingParent.php
@@ -0,0 +1,7 @@
+tag('baz');
$di->load(Prototype::class.'\\', '../Prototype')
->autoconfigure()
- ->exclude('../Prototype/{OtherDir}')
+ ->exclude('../Prototype/{OtherDir,BadClasses}')
->factory('f')
->deprecate('%service_id%')
->args(array(0))
diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_prototype.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_prototype.xml
index 333e71ce57d5a..381f95dd00fa5 100644
--- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_prototype.xml
+++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_prototype.xml
@@ -1,6 +1,6 @@
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: