20
20
use Symfony \Component \DependencyInjection \Loader \IniFileLoader ;
21
21
use Symfony \Component \DependencyInjection \Lo
8000
ader \PhpFileLoader ;
22
22
use Symfony \Component \DependencyInjection \Loader \ClosureLoader ;
23
+ use Symfony \Component \DependencyInjection \Compiler \PassConfig ;
23
24
use Symfony \Component \HttpFoundation \Request ;
24
25
use Symfony \Component \HttpKernel \HttpKernelInterface ;
25
26
use Symfony \Component \HttpKernel \Bundle \BundleInterface ;
26
27
use Symfony \Component \HttpKernel \Config \FileLocator ;
27
28
use Symfony \Component \HttpKernel \DependencyInjection \MergeExtensionConfigurationPass ;
29
+ use Symfony \Component \HttpKernel \DependencyInjection \AddClassesToCachePass ;
30
+ use Symfony \Component \HttpKernel \DependencyInjection \Extension as DIExtension ;
28
31
use Symfony \Component \Config \Loader \LoaderResolver ;
29
32
use Symfony \Component \Config \Loader \DelegatingLoader ;
30
33
use Symfony \Component \Config \ConfigCache ;
34
+ use Symfony \Component \ClassLoader \ClassCollectionLoader ;
31
35
32
36
/**
33
37
* The Kernel is the heart of the Symfony system.
@@ -47,6 +51,7 @@ abstract class Kernel implements KernelInterface
47
51
protected $ booted ;
48
52
protected $ name ;
49
53
protected $ startTime ;
54
+ protected $ classes ;
50
55
51
56
const VERSION = '2.0.0-DEV ' ;
8000
code>
52
57
@@ -63,6 +68,7 @@ public function __construct($environment, $debug)
63
68
$ this ->booted = false ;
64
69
$ this ->rootDir = $ this ->getRootDir ();
65
70
$ this ->name = preg_replace ('/[^a-zA-Z0-9_]+/ ' , '' , basename ($ this ->rootDir ));
71
+ $ this ->classes = array ();
66
72
67
73
if ($ this ->debug ) {
68
74
ini_set ('display_errors ' , 1 );
@@ -332,6 +338,28 @@ public function getContainer()
332
338
return $ this ->container ;
333
339
}
334
340
341
+ /**
342
+ * Loads the PHP class cache.
343
+ *
344
+ * @param string $name The cache name prefix
345
+ * @param string $extension File extension of the resulting file
346
+ */
347
+ public function loadClassCache ($ name = 'classes ' , $ extension = '.php ' )
348
+ {
349
+ if (!$
3269
this ->booted ) {
350
+ $ this ->boot ();
351
+ }
352
+
353
+ if ($ this ->classes ) {
354
+ ClassCollectionLoader::load ($ this ->classes , $ this ->getCacheDir (), $ name , $ this ->debug , true , $ extension );
355
+ }
356
+ }
357
+
358
+ public function addClassesToCache (array $ classes )
359
+ {
360
+ $ this ->classes = array_unique (array_merge ($ this ->classes , $ classes ));
361
+ }
362
+
335
363
/**
336
364
* Gets the request start time (not available if debug is disabled).
337
365
*
@@ -563,8 +591,11 @@ protected function buildContainer()
563
591
}
564
592
}
565
593
594
+ $ container ->addCompilerPass (new AddClassesToCachePass ($ this ));
566
595
$ container ->compile ();
567
596
597
+ $ this ->addClassesToCache ($ container ->getParameter ('kernel.compiled_classes ' ));
598
+
568
599
return $ container ;
569
600
}
570
601
0 commit comments