浏览代码

[DependencyInjection] fixed a bug when xpath() returns false

Fabien Potencier 14 年之前
父节点
当前提交
391e00c1de
共有 1 个文件被更改,包括 14 次插入4 次删除
  1. 14 4
      src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

+ 14 - 4
src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

@@ -101,7 +101,10 @@ class XmlFileLoader extends FileLoader
      */
     protected function parseImports(SimpleXMLElement $xml, $file)
     {
-        $imports = $xml->xpath('//container:imports/container:import');
+        if (false === $imports = $xml->xpath('//container:imports/container:import')) {
+            return;
+        }
+
         foreach ($imports as $import) {
             $this->currentDir = dirname($file);
             $this->import((string) $import['resource'], (Boolean) $import->getAttributeAsPhp('ignore-errors'));
@@ -151,7 +154,10 @@ class XmlFileLoader extends FileLoader
      */
     protected function parseDefinitions(SimpleXMLElement $xml, $file)
     {
-        $services = $xml->xpath('//container:services/container:service');
+        if (false === $services = $xml->xpath('//container:services/container:service')) {
+            return;
+        }
+
         foreach ($services as $service) {
             $this->parseDefinition((string) $service['id'], $service, $file);
         }
@@ -264,7 +270,9 @@ class XmlFileLoader extends FileLoader
         $count = 0;
 
         // anonymous services as arguments
-        $nodes = $xml->xpath('//container:argument[@type="service"][not(@id)]');
+        if (false === $nodes = $xml->xpath('//container:argument[@type="service"][not(@id)]')) {
+            return;
+        }
         foreach ($nodes as $node) {
             // give it a unique name
             $node['id'] = sprintf('%s_%d', md5($file), ++$count);
@@ -274,7 +282,9 @@ class XmlFileLoader extends FileLoader
         }
 
         // anonymous services "in the wild"
-        $nodes = $xml->xpath('//container:services/container:service[not(@id)]');
+        if (false === $nodes = $xml->xpath('//container:services/container:service[not(@id)]')) {
+            return;
+        }
         foreach ($nodes as $node) {
             // give it a unique name
             $node['id'] = sprintf('%s_%d', md5($file), ++$count);