瀏覽代碼

[Foundation] moved some Kernel initializations in the boot() method to speed up creation of Kernel instances

Fabien Potencier 15 年之前
父節點
當前提交
a9d8f39382
共有 2 個文件被更改,包括 20 次插入24 次删除
  1. 10 12
      src/Symfony/Foundation/Kernel.php
  2. 10 12
      src/Symfony/Foundation/bootstrap.php

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

@@ -50,28 +50,23 @@ abstract class Kernel implements RequestHandlerInterface, \Serializable
    */
   public function __construct($environment, $debug)
   {
+    $this->environment = $environment;
     $this->debug = (Boolean) $debug;
+    $this->booted = false;
+    $this->rootDir = realpath($this->registerRootDir());
+    $this->name = basename($this->rootDir);
+
     if ($this->debug)
     {
       ini_set('display_errors', 1);
       error_reporting(-1);
+
+      $this->startTime = microtime(true);
     }
     else
     {
       ini_set('display_errors', 0);
     }
-
-    if ($this->debug)
-    {
-      $this->startTime = microtime(true);
-    }
-
-    $this->booted = false;
-    $this->environment = $environment;
-    $this->bundles = $this->registerBundles();
-    $this->bundleDirs = $this->registerBundleDirs();
-    $this->rootDir = realpath($this->registerRootDir());
-    $this->name = basename($this->rootDir);
   }
 
   abstract public function registerRootDir();
@@ -111,6 +106,9 @@ abstract class Kernel implements RequestHandlerInterface, \Serializable
       throw new \LogicException('The kernel is already booted.');
     }
 
+    $this->bundles = $this->registerBundles();
+    $this->bundleDirs = $this->registerBundleDirs();
+
     // initialize the container
     $this->container = $this->initializeContainer();
     $this->container->setService('kernel', $this);

+ 10 - 12
src/Symfony/Foundation/bootstrap.php

@@ -390,28 +390,23 @@ abstract class Kernel implements RequestHandlerInterface, \Serializable
   
   public function __construct($environment, $debug)
   {
+    $this->environment = $environment;
     $this->debug = (Boolean) $debug;
+    $this->booted = false;
+    $this->rootDir = realpath($this->registerRootDir());
+    $this->name = basename($this->rootDir);
+
     if ($this->debug)
     {
       ini_set('display_errors', 1);
       error_reporting(-1);
+
+      $this->startTime = microtime(true);
     }
     else
     {
       ini_set('display_errors', 0);
     }
-
-    if ($this->debug)
-    {
-      $this->startTime = microtime(true);
-    }
-
-    $this->booted = false;
-    $this->environment = $environment;
-    $this->bundles = $this->registerBundles();
-    $this->bundleDirs = $this->registerBundleDirs();
-    $this->rootDir = realpath($this->registerRootDir());
-    $this->name = basename($this->rootDir);
   }
 
   abstract public function registerRootDir();
@@ -438,6 +433,9 @@ abstract class Kernel implements RequestHandlerInterface, \Serializable
       throw new \LogicException('The kernel is already booted.');
     }
 
+    $this->bundles = $this->registerBundles();
+    $this->bundleDirs = $this->registerBundleDirs();
+
         $this->container = $this->initializeContainer();
     $this->container->setService('kernel', $this);