瀏覽代碼

modified BundleInterface

Fabien Potencier 15 年之前
父節點
當前提交
c87dd7780f

+ 4 - 5
src/Symfony/Bundle/PropelBundle/PropelBundle.php

@@ -3,18 +3,17 @@
 namespace Symfony\Bundle\PropelBundle;
 
 use Symfony\Framework\Bundle\Bundle;
-use Symfony\Components\DependencyInjection\ContainerInterface;
 
 class PropelBundle extends Bundle
 {
-    public function boot(ContainerInterface $container)
+    public function boot()
     {
-        require_once $container->getParameter('propel.path').'/runtime/lib/Propel.php';
+        require_once $this->container->getParameter('propel.path').'/runtime/lib/Propel.php';
 
         if (0 === strncasecmp(PHP_SAPI, 'cli', 3)) {
-            set_include_path($container->getParameter('propel.phing_path').'/classes'.PATH_SEPARATOR.get_include_path());
+            set_include_path($this->container->getParameter('propel.phing_path').'/classes'.PATH_SEPARATOR.get_include_path());
         }
 
-        $container->getPropelService();
+        $this->container->getPropelService();
     }
 }

+ 13 - 6
src/Symfony/Framework/Bundle/Bundle.php

@@ -24,26 +24,33 @@ use Symfony\Components\Finder\Finder;
  */
 abstract class Bundle implements BundleInterface
 {
+    protected $container;
     protected $name;
     protected $namespacePrefix;
     protected $path;
     protected $reflection;
 
     /**
-     * Boots the Bundle.
+     * Sets the Container associated with this bundle.
      *
      * @param ContainerInterface $container A ContainerInterface instance
      */
-    public function boot(ContainerInterface $container)
+    public function setContainer(ContainerInterface $container = null)
+    {
+        $this->container = $container;
+    }
+
+    /**
+     * Boots the Bundle.
+     */
+    public function boot()
     {
     }
 
     /**
      * Shutdowns the Bundle.
-     *
-     * @param ContainerInterface $container A ContainerInterface instance
      */
-    public function shutdown(ContainerInterface $container)
+    public function shutdown()
     {
     }
 
@@ -111,7 +118,7 @@ abstract class Bundle implements BundleInterface
      * * Extensions are in the 'DependencyInjection/' sub-directory
      * * Extension class names ends with 'Extension'
      *
-     * @param ContainerBuilder A ContainerBuilder instance
+     * @param ContainerBuilder $container A ContainerBuilder instance
      */
     public function registerExtensions(ContainerBuilder $container)
     {

+ 7 - 6
src/Symfony/Framework/Bundle/BundleInterface.php

@@ -3,8 +3,6 @@
 namespace Symfony\Framework\Bundle;
 
 use Symfony\Components\DependencyInjection\ContainerInterface;
-use Symfony\Components\DependencyInjection\ContainerBuilder;
-use Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface;
 
 /*
  * This file is part of the Symfony framework.
@@ -24,15 +22,18 @@ interface BundleInterface
 {
     /**
      * Boots the Bundle.
-     *
-     * @param ContainerInterface $container A ContainerInterface instance
      */
-    public function boot(ContainerInterface $container);
+    public function boot();
 
     /**
      * Shutdowns the Bundle.
+     */
+    public function shutdown();
+
+    /**
+     * Sets the Container associated with this bundle.
      *
      * @param ContainerInterface $container A ContainerInterface instance
      */
-    public function shutdown(ContainerInterface $container);
+    public function setContainer(ContainerInterface $container);
 }

+ 11 - 14
src/Symfony/Framework/Kernel.php

@@ -107,8 +107,6 @@ abstract class Kernel implements HttpKernelInterface, \Serializable
      * This method boots the bundles, which MUST set
      * the DI container.
      *
-     * @return Kernel The current Kernel instance
-     *
      * @throws \LogicException When the Kernel is already booted
      */
     public function boot()
@@ -123,19 +121,14 @@ abstract class Kernel implements HttpKernelInterface, \Serializable
 
         $this->bundles = $this->registerBundles();
         $this->bundleDirs = $this->registerBundleDirs();
-
-        // initialize the container
         $this->container = $this->initializeContainer();
-        $this->container->set('kernel', $this);
 
-        // boot bundles
         foreach ($this->bundles as $bundle) {
-            $bundle->boot($this->container);
+            $bundle->setContainer($this->container);
+            $bundle->boot();
         }
 
         $this->booted = true;
-
-        return $this;
     }
 
     /**
@@ -148,7 +141,8 @@ abstract class Kernel implements HttpKernelInterface, \Serializable
         $this->booted = false;
 
         foreach ($this->bundles as $bundle) {
-            $bundle->shutdown($this->container);
+            $bundle->shutdown();
+            $bundle->setContainer(null);
         }
 
         $this->container = null;
@@ -193,15 +187,15 @@ abstract class Kernel implements HttpKernelInterface, \Serializable
         }
 
         if (null === $request) {
-            $request = $this->container->getRequestService();
+            $request = $this->container->get('request');
+        } else {
+            $this->container->set('request', $request);
         }
 
         if (HttpKernelInterface::MASTER_REQUEST === $type) {
             $this->request = $request;
         }
 
-        $this->container->set('request', $request);
-
         $response = $this->container->getHttpKernelService()->handle($request, $type, $raw);
 
         $this->container->set('request', $this->request);
@@ -305,7 +299,10 @@ abstract class Kernel implements HttpKernelInterface, \Serializable
 
         require_once $location.'.php';
 
-        return new $class();
+        $container = new $class();
+        $container->set('kernel', $this);
+
+        return $container;
     }
 
     public function getKernelParameters()

+ 5 - 8
src/Symfony/Framework/KernelBundle.php

@@ -4,7 +4,6 @@ namespace Symfony\Framework;
 
 use Symfony\Framework\Bundle\Bundle;
 use Symfony\Framework\ClassCollectionLoader;
-use Symfony\Components\DependencyInjection\ContainerInterface;
 
 /*
  * This file is part of the Symfony framework.
@@ -24,18 +23,16 @@ class KernelBundle extends Bundle
 {
     /**
      * Boots the Bundle.
-     *
-     * @param ContainerInterface $container A ContainerInterface instance
      */
-    public function boot(ContainerInterface $container)
+    public function boot()
     {
-        if ($container->has('error_handler')) {
-            $container['error_handler'];
+        if ($this->container->has('error_handler')) {
+            $this->container['error_handler'];
         }
 
         // load core classes
-        if ($container->getParameterBag()->has('kernel.include_core_classes') && $container->getParameter('kernel.include_core_classes')) {
-            ClassCollectionLoader::load($container->getParameter('kernel.compiled_classes'), $container->getParameter('kernel.cache_dir'), 'classes', $container->getParameter('kernel.debug'));
+        if ($this->container->getParameterBag()->has('kernel.include_core_classes') && $this->container->getParameter('kernel.include_core_classes')) {
+            ClassCollectionLoader::load($this->container->getParameter('kernel.compiled_classes'), $this->container->getParameter('kernel.cache_dir'), 'classes', $this->container->getParameter('kernel.debug'));
         }
     }
 }

+ 19 - 12
src/Symfony/Framework/bootstrap.php

@@ -13,18 +13,25 @@ use Symfony\Components\Finder\Finder;
 
 abstract class Bundle implements BundleInterface
 {
+    protected $container;
     protected $name;
     protected $namespacePrefix;
     protected $path;
     protected $reflection;
 
     
-    public function boot(ContainerInterface $container)
+    public function setContainer(ContainerInterface $container = null)
     {
+        $this->container = $container;
     }
 
     
-    public function shutdown(ContainerInterface $container)
+    public function boot()
+    {
+    }
+
+    
+    public function shutdown()
     {
     }
 
@@ -121,8 +128,6 @@ abstract class Bundle implements BundleInterface
 namespace Symfony\Framework\Bundle;
 
 use Symfony\Components\DependencyInjection\ContainerInterface;
-use Symfony\Components\DependencyInjection\ContainerBuilder;
-use Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface;
 
 
 
@@ -130,10 +135,13 @@ use Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface;
 interface BundleInterface
 {
     
-    public function boot(ContainerInterface $container);
+    public function boot();
+
+    
+    public function shutdown();
 
     
-    public function shutdown(ContainerInterface $container);
+    public function setContainer(ContainerInterface $container);
 }
 
 
@@ -141,7 +149,6 @@ namespace Symfony\Framework;
 
 use Symfony\Framework\Bundle\Bundle;
 use Symfony\Framework\ClassCollectionLoader;
-use Symfony\Components\DependencyInjection\ContainerInterface;
 
 
 
@@ -149,14 +156,14 @@ use Symfony\Components\DependencyInjection\ContainerInterface;
 class KernelBundle extends Bundle
 {
     
-    public function boot(ContainerInterface $container)
+    public function boot()
     {
-        if ($container->has('error_handler')) {
-            $container['error_handler'];
+        if ($this->container->has('error_handler')) {
+            $this->container['error_handler'];
         }
 
-                if ($container->getParameterBag()->has('kernel.include_core_classes') && $container->getParameter('kernel.include_core_classes')) {
-            ClassCollectionLoader::load($container->getParameter('kernel.compiled_classes'), $container->getParameter('kernel.cache_dir'), 'classes', $container->getParameter('kernel.debug'));
+                if ($this->container->getParameterBag()->has('kernel.include_core_classes') && $this->container->getParameter('kernel.include_core_classes')) {
+            ClassCollectionLoader::load($this->container->getParameter('kernel.compiled_classes'), $this->container->getParameter('kernel.cache_dir'), 'classes', $this->container->getParameter('kernel.debug'));
         }
     }
 }