Kaynağa Gözat

[Foundation] made the Kernel serializable (to avoid weird error messages when used with PHPUnit)

Fabien Potencier 15 yıl önce
ebeveyn
işleme
77f56a61f6

+ 13 - 1
src/Symfony/Foundation/Kernel.php

@@ -25,7 +25,7 @@ use Symfony\Components\RequestHandler\RequestInterface;
  * @package Symfony
  * @author  Fabien Potencier <fabien.potencier@symfony-project.org>
  */
-abstract class Kernel
+abstract class Kernel implements \Serializable
 {
   protected $bundles;
   protected $bundleDirs;
@@ -380,4 +380,16 @@ abstract class Kernel
     @rename($tmpFile, $file);
     chmod($file, 0644);
   }
+
+  public function serialize()
+  {
+    return serialize(array($this->environment, $this->debug));
+  }
+
+  public function unserialize($data)
+  {
+    list($environment, $debug) = unserialize($data);
+
+    $this->__construct($environment, $debug);
+  }
 }

+ 13 - 1
src/Symfony/Foundation/bootstrap.php

@@ -320,7 +320,7 @@ use Symfony\Components\DependencyInjection\FileResource;
 use Symfony\Components\RequestHandler\RequestInterface;
 
 
-abstract class Kernel
+abstract class Kernel implements \Serializable
 {
   protected $bundles;
   protected $bundleDirs;
@@ -649,6 +649,18 @@ abstract class Kernel
     @rename($tmpFile, $file);
     chmod($file, 0644);
   }
+
+  public function serialize()
+  {
+    return serialize(array($this->environment, $this->debug));
+  }
+
+  public function unserialize($data)
+  {
+    list($environment, $debug) = unserialize($data);
+
+    $this->__construct($environment, $debug);
+  }
 }