8000 [FrameworkBundle] Compute list of early-declared classes in ClassCach… · symfony/symfony@66cc465 · GitHub
[go: up one dir, main page]

Skip to content

Commit 66cc465

Browse files
[FrameworkBundle] Compute list of early-declared classes in ClassCacheCacheWarmer
1 parent cc3f44b commit 66cc465

File tree

7 files changed

+96
-2
lines changed

7 files changed

+96
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/CacheWarmer/ClassCacheCacheWarmer.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
*/
2222
class ClassCacheCacheWarmer implements CacheWarmerInterface
2323
{
24+
private $declaredClasses;
25+
26+
public function __construct(array $declaredClasses = null)
27+
{
28+
$this->declaredClasses = $declaredClasses;
29+
}
30 8000 +
2431
/**
2532
* Warms up the cache.
2633
*
@@ -37,8 +44,9 @@ public function warmUp($cacheDir)
3744
if (file_exists($cacheDir.'/classes.php')) {
3845
return;
3946
}
47+
$declared = null !== $this->declaredClasses ? $this->declaredClasses : array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits());
4048

41-
ClassCollectionLoader::load(include($classmap), $cacheDir, 'classes', false);
49+
ClassCollectionLoader::inline(include($classmap), $cacheDir.'/classes.php', $declared);
4250
}
4351

4452
/**

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,23 @@ public function load(array $configs, ContainerBuilder $container)
170170
}
171171

172172
$this->addClassesToCompile(array(
173+
'Symfony\\Component\\Config\\ConfigCache',
173174
'Symfony\\Component\\Config\\FileLocator',
174175

175176
'Symfony\\Component\\Debug\\ErrorHandler',
176177

178+
'Symfony\\Component\\DependencyInjection\\ContainerAwareInterface',
179+
'Symfony\\Component\\DependencyInjection\\Container',
180+
177181
'Symfony\\Component\\EventDispatcher\\Event',
178182
'Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher',
179183

184+
'Symfony\\Component\\HttpFoundation\\Response',
185+
'Symfony\\Component\\HttpFoundation\\ResponseHeaderBag',
186+
180187
'Symfony\\Component\\HttpKernel\\EventListener\\ResponseListener',
181188
'Symfony\\Component\\HttpKernel\\EventListener\\RouterListener',
189+
'Symfony\\Component\\HttpKernel\\Bundle\\Bundle',
182190
'Symfony\\Component\\HttpKernel\\Controller\\ControllerResolver',
183191
'Symfony\\Component\\HttpKernel\\Controller\\ArgumentResolver',
184192
'Symfony\\Component\\HttpKernel\\ControllerMetadata\\ArgumentMetadata',
@@ -189,13 +197,18 @@ public function load(array $configs, ContainerBuilder $container)
189197
'Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent',
190198
'Symfony\\Component\\HttpKernel\\Event\\GetResponseForControllerResultEvent',
191199
'Symfony\\Component\\HttpKernel\\Event\\GetResponseForExceptionEvent',
200+
'Symfony\\Component\\HttpKernel\\HttpKernel',
192201
'Symfony\\Component\\HttpKernel\\KernelEvents',
193202
'Symfony\\Component\\HttpKernel\\Config\\FileLocator',
194203

195204
'Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerNameParser',
196205
'Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerResolver',
206+
197207
// Cannot be included because annotations will parse the big compiled class file
198208
// 'Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller',
209+
210+
// cannot be included as commands are discovered based on the path to this class via Reflection
211+
// 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle',
199212
));
200213
}
201214

src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@
2424

2525
<service id="kernel.class_cache.cache_warmer" class="Symfony\Bundle\FrameworkBundle\CacheWarmer\ClassCacheCacheWarmer">
2626
<tag name="kernel.cache_warmer" />
27+
<argument type="collection">
28+
<argument>Doctrine\Common\Annotations\AnnotationRegistry</argument>
29+
<argument>Symfony\Component\HttpFoundation\ParameterBag</argument>
30+
<argument>Symfony\Component\HttpFoundation\HeaderBag</argument>
31+
<argument>Symfony\Component\HttpFoundation\FileBag</argument>
32+
<argument>Symfony\Component\HttpFoundation\ServerBag</argument>
33+
<argument>Symfony\Component\HttpFoundation\Request</argument>
34+
<argument>Symfony\Component\HttpKernel\Kernel</argument>
35+
<argument>Symfony\Component\ClassLoader\ClassCollectionLoader</argument>
36+
<argument>Symfony\Component\ClassLoader\ApcClassLoader</argument>
37+
</argument>
2738
</service>
2839

2940
<service id="cache_clearer" class="Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer">
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\CacheWarmer;
13+
14+
use Symfony\Bundle\FrameworkBundle\CacheWarmer\ClassCacheCacheWarmer;
15+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\DeclaredClass;
16+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\WarmedClass;
17+
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
18+
19+
class ClassCacheCacheWarmerTest extends TestCase
20+
{
21+
public function testWithDeclaredClasses()
22+
{
23+
$this->assertTrue(class_exists(WarmedClass::class, true));
24+
25+
$dir = sys_get_temp_dir();
26+
@unlink($dir.'/classes.php');
27+
file_put_contents($dir.'/classes.map', sprintf('<?php return %s;', var_export(array(WarmedClass::class), true)));
28+
29+
$warmer = new ClassCacheCacheWarmer(array(DeclaredClass::class));
30+
31+
$warmer->warmUp($dir);
32+
33+
$this->assertSame(<<<'EOTXT'
34+
<?php
35+
namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures
36+
{
37+
class WarmedClass extends DeclaredClass
38+
{
39+
}
40+
}
41+
EOTXT
42+
, file_get_contents($dir.'/classes.php')
43+
);
44+
45+
@unlink($dir.'/classes.map');
46+
@unlink($dir.'/classes.php');
47+
}
48+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures;
4+
5+
class DeclaredClass
6+
{
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures;
4+
5+
class WarmedClass extends DeclaredClass
6+
{
7+
}

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": ">=5.5.9",
2020
"symfony/asset": "~2.8|~3.0",
2121
"symfony/cache": "~3.1",
22-
"symfony/class-loader": "~2.8|~3.0",
22+
"symfony/class-loader": "~3.2",
2323
"symfony/dependency-injection": "~3.2",
2424
"symfony/config": "~2.8|~3.0",
2525
" 3A64 ;symfony/event-dispatcher": "~2.8|~3.0",

0 commit comments

Comments
 (0)
0