瀏覽代碼

Merge remote branch 'Chekote/xmlfileloader_overload_refactor'

* Chekote/xmlfileloader_overload_refactor:
  Refactored the processing of each individual node into it's own method, enabling easier overloading of behavior for Bundles such as FriendsOfSymfony/RestBundle
Fabien Potencier 14 年之前
父節點
當前提交
1c0dfad979
共有 1 個文件被更改,包括 26 次插入14 次删除
  1. 26 14
      src/Symfony/Component/Routing/Loader/XmlFileLoader.php

+ 26 - 14
src/Symfony/Component/Routing/Loader/XmlFileLoader.php

@@ -48,25 +48,37 @@ class XmlFileLoader extends FileLoader
                 continue;
             }
 
-            switch ($node->tagName) {
-                case 'route':
-                    $this->parseRoute($collection, $node, $path);
-                    break;
-                case 'import':
-                    $resource = (string) $node->getAttribute('resource');
-                    $type = (string) $node->getAttribute('type');
-                    $prefix = (string) $node->getAttribute('prefix');
-                    $this->setCurrentDir(dirname($path));
-                    $collection->addCollection($this->import($resource, ('' !== $type ? $type : null), false, $file), $prefix);
-                    break;
-                default:
-                    throw new \InvalidArgumentException(sprintf('Unable to parse tag "%s"', $node->tagName));
-            }
+            $this->parseNode($collection, $node, $path);
         }
 
         return $collection;
     }
 
+    /**
+     * Parses a node from a loaded XML file.
+     *
+     * @param RouteCollection $collection the collection to associate with the node
+     * @param DOMElement $node the node to parse
+     * @param string $path the path of the XML file being processed
+     */
+    protected function parseNode(RouteCollection $collection, \DOMElement $node, $path)
+    {
+      switch ($node->tagName) {
+          case 'route':
+              $this->parseRoute($collection, $node, $path);
+              break;
+          case 'import':
+              $resource = (string) $node->getAttribute('resource');
+              $type = (string) $node->getAttribute('type');
+              $prefix = (string) $node->getAttribute('prefix');
+              $this->setCurrentDir(dirname($path));
+              $collection->addCollection($this->import($resource, ('' !== $type ? $type : null), false, $file), $prefix);
+              break;
+          default:
+              throw new \InvalidArgumentException(sprintf('Unable to parse tag "%s"', $node->tagName));
+      }
+    }
+
     /**
      * Returns true if this class supports the given resource.
      *