Quellcode durchsuchen

[Symfony] Adding isBooted() method so that I can pass an existing kernel to a Console application. Right now it throws an exception otherwise about it already being booted.

Jonathan H. Wage vor 15 Jahren
Ursprung
Commit
b3d8aa414e

+ 10 - 0
src/Symfony/Foundation/Kernel.php

@@ -83,6 +83,16 @@ abstract class Kernel
 
   abstract public function registerRoutes();
 
+  /**
+   * Checks whether the current kernel has been booted or not.
+   *
+   * @return boolean $booted
+   */
+  public function isBooted()
+  {
+    return $this->booted;
+  }
+
   /**
    * Boots the current kernel.
    *

+ 6 - 0
src/Symfony/Foundation/bootstrap.php

@@ -373,6 +373,12 @@ abstract class Kernel
   abstract public function registerRoutes();
 
   
+  public function isBooted()
+  {
+    return $this->booted;
+  }
+
+  
   public function boot()
   {
     if (true === $this->booted)

+ 4 - 1
src/Symfony/Framework/WebBundle/Console/Application.php

@@ -38,7 +38,10 @@ class Application extends BaseApplication
 
     $this->definition->addOption(new InputOption('--shell', '-s', InputOption::PARAMETER_NONE, 'Launch the shell.'));
 
-    $this->kernel->boot();
+    if (!$this->kernel->isBooted())
+    {
+      $this->kernel->boot();
+    }
 
     $this->registerCommands();
   }