ソースを参照

removed the automatic loading of the compiled classes (should be done explicitely by the end user now)

Fabien Potencier 14 年 前
コミット
4cbc33a785

+ 0 - 12
src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

@@ -17,7 +17,6 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass;
 use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RegisterKernelListenersPass;
 use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass;
 use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
-use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddClassesToCachePass;
 use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslatorPass;
 use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass;
 use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass;
@@ -27,7 +26,6 @@ use Symfony\Component\DependencyInjection\Compiler\PassConfig;
 use Symfony\Component\DependencyInjection\Scope;
 use Symfony\Component\HttpFoundation\File\File;
 use Symfony\Component\HttpKernel\Bundle\Bundle;
-use Symfony\Component\ClassLoader\ClassCollectionLoader;
 
 /**
  * Bundle.
@@ -41,15 +39,6 @@ class FrameworkBundle extends Bundle
      */
     public function boot()
     {
-        // load core classes
-        ClassCollectionLoader::load(
-            $this->container->getParameter('kernel.compiled_classes'),
-            $this->container->getParameter('kernel.cache_dir'),
-            'classes',
-            $this->container->getParameter('kernel.debug'),
-            true
-        );
-
         if ($this->container->has('error_handler')) {
             $this->container->get('error_handler');
         }
@@ -67,7 +56,6 @@ class FrameworkBundle extends Bundle
         $container->addCompilerPass(new TemplatingPass());
         $container->addCompilerPass(new AddConstraintValidatorsPass());
         $container->addCompilerPass(new FormPass());
-        $container->addCompilerPass(new AddClassesToCachePass());
         $container->addCompilerPass(new TranslatorPass());
         $container->addCompilerPass(new AddCacheWarmerPass());
 

+ 6 - 6
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddClassesToCachePass.php

@@ -1,11 +1,5 @@
 <?php
 
-namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
-
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
-use Symfony\Component\HttpKernel\DependencyInjection\Extension;
-
 /*
  * This file is part of the Symfony framework.
  *
@@ -15,6 +9,12 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension;
  * with this source code in the file LICENSE.
  */
 
+namespace Symfony\Component\HttpKernel\DependencyInjection;
+
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+use Symfony\Component\HttpKernel\DependencyInjection\Extension;
+
 /**
  * Sets the classes to compile in the cache for the container.
  *

+ 31 - 0
src/Symfony/Component/HttpKernel/Kernel.php

@@ -20,14 +20,18 @@ use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
 use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
 use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
 use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
+use Symfony\Component\DependencyInjection\Compiler\PassConfig;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpKernel\HttpKernelInterface;
 use Symfony\Component\HttpKernel\Bundle\BundleInterface;
 use Symfony\Component\HttpKernel\Config\FileLocator;
 use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
+use Symfony\Component\HttpKernel\DependencyInjection\AddClassesToCachePass;
+use Symfony\Component\HttpKernel\DependencyInjection\Extension as DIExtension;
 use Symfony\Component\Config\Loader\LoaderResolver;
 use Symfony\Component\Config\Loader\DelegatingLoader;
 use Symfony\Component\Config\ConfigCache;
+use Symfony\Component\ClassLoader\ClassCollectionLoader;
 
 /**
  * The Kernel is the heart of the Symfony system.
@@ -47,6 +51,7 @@ abstract class Kernel implements KernelInterface
     protected $booted;
     protected $name;
     protected $startTime;
+    protected $classes;
 
     const VERSION = '2.0.0-DEV';
 
@@ -63,6 +68,7 @@ abstract class Kernel implements KernelInterface
         $this->booted = false;
         $this->rootDir = $this->getRootDir();
         $this->name = preg_replace('/[^a-zA-Z0-9_]+/', '', basename($this->rootDir));
+        $this->classes = array();
 
         if ($this->debug) {
             ini_set('display_errors', 1);
@@ -332,6 +338,28 @@ abstract class Kernel implements KernelInterface
         return $this->container;
     }
 
+    /**
+     * Loads the PHP class cache.
+     *
+     * @param string  $name      The cache name prefix
+     * @param string  $extension File extension of the resulting file
+     */
+    public function loadClassCache($name = 'classes', $extension = '.php')
+    {
+        if (!$this->booted) {
+            $this->boot();
+        }
+
+        if ($this->classes) {
+            ClassCollectionLoader::load($this->classes, $this->getCacheDir(), $name, $this->debug, true, $extension);
+        }
+    }
+
+    public function addClassesToCache(array $classes)
+    {
+        $this->classes = array_unique(array_merge($this->classes, $classes));
+    }
+
     /**
      * Gets the request start time (not available if debug is disabled).
      *
@@ -563,8 +591,11 @@ abstract class Kernel implements KernelInterface
             }
         }
 
+        $container->addCompilerPass(new AddClassesToCachePass($this));
         $container->compile();
 
+        $this->addClassesToCache($container->getParameter('kernel.compiled_classes'));
+
         return $container;
     }