瀏覽代碼

[DependencyInjection] make base class of generated container configurable

Johannes M. Schmitt 14 年之前
父節點
當前提交
30bac46e1b
共有 1 個文件被更改,包括 16 次插入3 次删除
  1. 16 3
      src/Symfony/Component/HttpKernel/Kernel.php

+ 16 - 3
src/Symfony/Component/HttpKernel/Kernel.php

@@ -435,6 +435,18 @@ abstract class Kernel implements KernelInterface
         return $this->name.ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer';
     }
 
+    /**
+     * Gets the container's base class.
+     *
+     * All names except Container must be fully qualified.
+     *
+     * @return string
+     */
+    protected function getContainerBaseClass()
+    {
+        return 'Container';
+    }
+
     /**
      * Initializes the service container.
      *
@@ -448,7 +460,7 @@ abstract class Kernel implements KernelInterface
         $fresh = true;
         if (!$cache->isFresh()) {
             $container = $this->buildContainer();
-            $this->dumpContainer($cache, $container, $class);
+            $this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
 
             $fresh = false;
         }
@@ -556,12 +568,13 @@ abstract class Kernel implements KernelInterface
      * @param ConfigCache       $cache      The config cache
      * @param ContainerBuilder  $container  The service container
      * @param string            $class      The name of the class to generate
+     * @param string            $baseClass  The name of the container's base class
      */
-    protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class)
+    protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass)
     {
         // cache the container
         $dumper = new PhpDumper($container);
-        $content = $dumper->dump(array('class' => $class));
+        $content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass));
         if (!$this->debug) {
             $content = self::stripComments($content);
         }