Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f2d2e05

Browse filesBrowse files
[HttpKernel][FrameworkBundle] Add RebootableInterface, fix and un-deprecate cache:clear with warmup
1 parent fea348c commit f2d2e05
Copy full SHA for f2d2e05

File tree

16 files changed

+197
-54
lines changed
Filter options

16 files changed

+197
-54
lines changed

‎UPGRADE-3.3.md

Copy file name to clipboardExpand all lines: UPGRADE-3.3.md
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,6 @@ Form
167167
FrameworkBundle
168168
---------------
169169

170-
* The `cache:clear` command should always be called with the `--no-warmup` option.
171-
Warmup should be done via the `cache:warmup` command.
172-
173170
* [BC BREAK] The "framework.trusted_proxies" configuration option and the corresponding "kernel.trusted_proxies"
174171
parameter have been removed. Use the Request::setTrustedProxies() method in your front controller instead.
175172

‎UPGRADE-3.4.md

Copy file name to clipboardExpand all lines: UPGRADE-3.4.md
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,40 @@ FrameworkBundle
114114
class has been deprecated and will be removed in 4.0. Use the
115115
`Symfony\Component\Translation\DependencyInjection\TranslatorPass` class instead.
116116

117+
HttpKernel
118+
----------
119+
120+
* The `getCacheDir()` method of your kernel should return the non-empty value
121+
from `Kernel::getWarmupDir()` when one exists; not doing so is deprecated.
122+
123+
Before:
124+
125+
```php
126+
class AppKernel extends Kernel
127+
{
128+
public function getCacheDir()
129+
{
130+
return 'my-cache-dir';
131+
}
132+
133+
// ...
134+
}
135+
```
136+
137+
After:
138+
139+
```php
140+
class AppKernel extends Kernel
141+
{
142+
public function getCacheDir()
143+
{
144+
return $this->getWarmupDir() ?: 'my-cache-dir';
145+
}
146+
147+
// ...
148+
}
149+
```
150+
117151
Process
118152
-------
119153

‎UPGRADE-4.0.md

Copy file name to clipboardExpand all lines: UPGRADE-4.0.md
+31-3Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,6 @@ FrameworkBundle
284284

285285
* The `validator.mapping.cache.doctrine.apc` service has been removed.
286286

287-
* The `cache:clear` command does not warmup the cache anymore. Warmup should
288-
be done via the `cache:warmup` command.
289-
290287
* The "framework.trusted_proxies" configuration option and the corresponding "kernel.trusted_proxies" parameter have been removed. Use the `Request::setTrustedProxies()` method in your front controller instead.
291288

292289
* The default value of the `framework.workflows.[name].type` configuration options is now `state_machine`.
@@ -487,6 +484,37 @@ HttpKernel
487484
by Symfony. Use the `%env()%` syntax to get the value of any environment
488485
variable from configuration files instead.
489486

487+
* The `getCacheDir()` method of your kernel must return the non-empty value
488+
from `Kernel::getWarmupDir()` when one exists.
489+
490+
Before:
491+
492+
```php
493+
class AppKernel extends Kernel
494+
{
495+
public function getCacheDir()
496+
{
497+
return 'my-cache-dir';
498+
}
499+
500+
// ...
501+
}
502+
```
503+
504+
After:
505+
506+
```php
507+
class AppKernel extends Kernel
508+
{
509+
public function getCacheDir()
510+
{
511+
return $this->getWarmupDir() ?: 'my-cache-dir';
512+
}
513+
514+
// ...
515+
}
516+
```
517+
490518
Ldap
491519
----
492520

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ CHANGELOG
3636
the same helpers as the `Controller` class, but does not allow accessing the dependency
3737
injection container, in order to encourage explicit dependency declarations.
3838
* Added support for the `controller.service_arguments` tag, for injecting services into controllers' actions
39-
* Deprecated `cache:clear` with warmup (always call it with `--no-warmup`)
4039
* Changed default configuration for
4140
assets/forms/validation/translation/serialization/csrf from `canBeEnabled()` to
4241
`canBeDisabled()` when Flex is used

‎src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
+49-28Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Filesystem\Filesystem;
2020
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
2121
use Symfony\Component\HttpKernel\KernelInterface;
22+
use Symfony\Component\HttpKernel\RebootableInterface;
2223
use Symfony\Component\Finder\Finder;
2324

2425
/**
@@ -33,6 +34,7 @@ class CacheClearCommand extends ContainerAwareCommand
3334
{
3435
private $cacheClearer;
3536
private $filesystem;
37+
private $warning;
3638

3739
/**
3840
* @param CacheClearerInterface $cacheClearer
@@ -111,13 +113,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
111113
if ($input->getOption('no-warmup')) {
112114
$this->filesystem->rename($realCacheDir, $oldCacheDir);
113115
} else {
114-
$warning = 'Calling cache:clear without the --no-warmup option is deprecated since version 3.3. Cache warmup should be done with the cache:warmup command instead.';
115-
116-
@trigger_error($warning, E_USER_DEPRECATED);
117-
118-
$io->warning($warning);
119-
120116
$this->warmupCache($input, $output, $realCacheDir, $oldCacheDir);
117+
118+
if ($this->warning) {
119+
@trigger_error($this->warning, E_USER_DEPRECATED);
120+
$io->warning($this->warning);
121+
$this->warning = null;
122+
}
121123
}
122124

123125
if ($output->isVerbose()) {
@@ -162,30 +164,45 @@ private function warmupCache(InputInterface $input, OutputInterface $output, $re
162164
sleep(1); // workaround for Windows PHP rename bug
163165
}
164166
$this->filesystem->rename($warmupDir, $realCacheDir);
167+
168+
if ($this->getApplication()->getKernel() instanceof RebootableInterface) {
169+
$this->getApplication()->getKernel()->reboot(null);
170+
}
165171
}
166172

167173
/**
168174
* @param string $warmupDir
169175
* @param string $realCacheDir
170176
* @param bool $enableOptionalWarmers
171-
*
172-
* @internal to be removed in 4.0
173177
*/
174178
protected function warmup($warmupDir, $realCacheDir, $enableOptionalWarmers = true)
175179
{
176180
// create a temporary kernel
177181
$realKernel = $this->getApplication()->getKernel();
178-
$realKernelClass = get_class($realKernel);
179-
$namespace = '';
180-
if (false !== $pos = strrpos($realKernelClass, '\\')) {
181-
$namespace = substr($realKernelClass, 0, $pos);
182-
$realKernelClass = substr($realKernelClass, $pos + 1);
182+
if (!$isRebootable = $realKernel instanceof RebootableInterface) {
183+
$this->warning = 'Calling "cache:clear" with a kernel that does not implement "Symfony\Component\HttpKernel\RebootableInterface" is deprecated since version 3.4 and will be unsupported in 4.0.';
184+
} else {
185+
$realKernel->reboot($warmupDir);
186+
187+
if (!$isRebootable = $realKernel->getCacheDir() !== $realCacheDir) {
188+
$this->warning = 'Calling "cache:clear" with a kernel that ignores the warm-up directory is deprecated since version 3.4 and will be unsupported in 4.0. The "getCacheDir()" method of your kernel should return the non-empty value from "Kernel::getWarmupDir()" when one exists.';
189+
} else {
190+
$tempKernel = $realKernel;
191+
}
183192
}
184-
$tempKernel = $this->getTempKernel($realKernel, $namespace, $realKernelClass, $warmupDir);
185-
$tempKernel->boot();
193+
if (!$isRebootable) {
194+
$realKernelClass = get_class($realKernel);
195+
$namespace = '';
196+
if (false !== $pos = strrpos($realKernelClass, '\\')) {
197+
$namespace = substr($realKernelClass, 0, $pos);
198+
$realKernelClass = substr($realKernelClass, $pos + 1);
199+
}
200+
$tempKernel = $this->getTempKernel($realKernel, $namespace, $realKernelClass, $warmupDir);
201+
$tempKernel->boot();
186202

187-
$tempKernelReflection = new \ReflectionObject($tempKernel);
188-
$tempKernelFile = $tempKernelReflection->getFileName();
203+
$tempKernelReflection = new \ReflectionObject($tempKernel);
204+
$tempKernelFile = $tempKernelReflection->getFileName();
205+
}
189206

190207
// warmup temporary dir
191208
$warmer = $tempKernel->getContainer()->get('cache_warmer');
@@ -194,6 +211,20 @@ protected function warmup($warmupDir, $realCacheDir, $enableOptionalWarmers = tr
194211
}
195212
$warmer->warmUp($warmupDir);
196213

214+
// fix references to cached files with the real cache directory name
215+
$search = array($warmupDir, str_replace('\\', '\\\\', $warmupDir));
216+
$replace = str_replace('\\', '/', $realCacheDir);
217+
foreach (Finder::create()->files()->in($warmupDir) as $file) {
218+
$content = str_replace($search, $replace, file_get_contents($file), $count);
219+
if ($count) {
220+
file_put_contents($file, $content);
221+
}
222+
}
223+
224+
if ($isRebootable) {
225+
return;
226+
}
227+
197228
// fix references to the Kernel in .meta files
198229
$safeTempKernel = str_replace('\\', '\\\\', get_class($tempKernel));
199230
$realKernelFQN = get_class($realKernel);
@@ -206,16 +237,6 @@ protected function warmup($warmupDir, $realCacheDir, $enableOptionalWarmers = tr
206237
));
207238
}
208239

209-
// fix references to cached files with the real cache directory name
210-
$search = array($warmupDir, str_replace('\\', '\\\\', $warmupDir));
211-
$replace = str_replace('\\', '/', $realCacheDir);
212-
foreach (Finder::create()->files()->in($warmupDir) as $file) {
213-
$content = str_replace($search, $replace, file_get_contents($file), $count);
214-
if ($count) {
215-
file_put_contents($file, $content);
216-
}
217-
}
218-
219240
// fix references to container's class
220241
$tempContainerClass = $tempKernel->getContainerClass();
221242
$realContainerClass = $tempKernel->getRealContainerClass();
@@ -279,7 +300,7 @@ class $class extends $parentClass
279300
{
280301
public function getCacheDir()
281302
{
282-
return $cacheDir;
303+
return \$this->getWarmupDir() ?: $cacheDir;
283304
}
284305
285306
public function getRootDir()

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function getRootDir()
5959

6060
public function getCacheDir()
6161
{
62-
return sys_get_temp_dir().'/'.$this->varDir.'/'.$this->testCase.'/cache/'.$this->environment;
62+
return $this->getWarmupDir() ?: sys_get_temp_dir().'/'.$this->varDir.'/'.$this->testCase.'/cache/'.$this->environment;
6363
}
6464

6565
public function getLogDir()

‎src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/ConcreteMicroKernel.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/ConcreteMicroKernel.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function registerBundles()
4040

4141
public function getCacheDir()
4242
{
43-
return $this->cacheDir = sys_get_temp_dir().'/sf_micro_kernel';
43+
return $this->getWarmupDir() ?: $this->cacheDir = sys_get_temp_dir().'/sf_micro_kernel';
4444
}
4545

4646
public function getLogDir()

‎src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function getRootDir()
7171

7272
public function getCacheDir()
7373
{
74-
return sys_get_temp_dir().'/'.$this->varDir.'/'.$this->testCase.'/cache/'.$this->environment;
74+
return $this->getWarmupDir() ?: sys_get_temp_dir().'/'.$this->varDir.'/'.$this->testCase.'/cache/'.$this->environment;
7575
}
7676

7777
public function getLogDir()

‎src/Symfony/Bundle/SecurityBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"ext-xml": "*",
2121
"symfony/security": "~3.4|~4.0",
2222
"symfony/dependency-injection": "~3.4|~4.0",
23-
"symfony/http-kernel": "~3.3|~4.0",
23+
"symfony/http-kernel": "~3.4|~4.0",
2424
"symfony/polyfill-php70": "~1.0"
2525
},
2626
"require-dev": {

‎src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
108108

109109
public function getCacheDir()
110110
{
111-
return sys_get_temp_dir().'/'.Kernel::VERSION.'/CacheWarmingKernel/cache/'.$this->environment;
111+
return $this->getWarmupDir() ?: sys_get_temp_dir().'/'.Kernel::VERSION.'/CacheWarmingKernel/cache/'.$this->environment;
112112
}
113113

114114
public function getLogDir()

‎src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
6969

7070
public function getCacheDir()
7171
{
72-
return sys_get_temp_dir().'/'.Kernel::VERSION.'/NoTemplatingEntryKernel/cache/'.$this->environment;
72+
return $this->getWarmupDir() ?: sys_get_temp_dir().'/'.Kernel::VERSION.'/NoTemplatingEntryKernel/cache/'.$this->environment;
7373
}
7474

7575
public function getLogDir()

‎src/Symfony/Bundle/TwigBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"symfony/config": "~3.2|~4.0",
2121
"symfony/twig-bridge": "^3.3|~4.0",
2222
"symfony/http-foundation": "~2.8|~3.0|~4.0",
23-
"symfony/http-kernel": "^3.3|~4.0",
23+
"symfony/http-kernel": "^3.4|~4.0",
2424
"twig/twig": "~1.34|~2.4"
2525
},
2626
"require-dev": {

‎src/Symfony/Component/HttpKernel/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ CHANGELOG
44
3.4.0
55
-----
66

7+
* the `getCacheDir()` method of your kernel should return the non-empty value
8+
from `Kernel::getWarmupDir()` when one exists; not doing so is deprecated
79
* added `AddCacheClearerPass`
810
* added `AddCacheWarmerPass`
911

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.