8000 [HttpKernel][FrameworkBundle] Add RebootableInterface, fix and un-dep… · symfony/symfony@c200b89 · GitHub
[go: up one dir, main page]

Skip to content

Commit c200b89

Browse files
[HttpKernel][FrameworkBundle] Add RebootableInterface, fix and un-deprecate cache:clear with warmup
1 parent 8c4a1e7 commit c200b89

File tree

16 files changed

+194
-54
lines changed

16 files changed

+194
-54
lines changed

UPGRADE-3.3.md

Lines 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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,37 @@ HttpKernel
143143
tags: ['console.command']
144144
```
145145
146+
* The `getCacheDir()` method of your kernel should return the non-empty value
147+
from `Kernel::getWarmupDir()` when one exists; not doing so is deprecated.
148+
149+
Before:
150+
151+
```php
152+
class AppKernel extends Kernel
153+
{
154+
public function getCacheDir()
155+
{
156+
return 'my-cache-dir';
157+
}
158+
159+
// ...
160+
}
161+
```
162+
163+
After:
164+
165+
```php
166+
class AppKernel extends Kernel
167+
{
168+
public function getCacheDir()
169+
{
170+
return $this->getWarmupDir() ?: 'my-cache-dir';
171+
}
172+
173+
// ...
174+
}
175+
```
176+
146177
Process
147178
-------
148179

UPGRADE-4.0.md

Lines 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`.
@@ -513,6 +510,37 @@ HttpKernel
513510
by Symfony. Use the `%env()%` syntax to get the value of any environment
514511
variable from configuration files instead.
515512

513+
* The `getCacheDir()` method of your kernel must return the non-empty value
514+
from `Kernel::getWarmupDir()` when one exists.
515+
516+
Before:
517+
518+
```php
519+
class AppKernel extends Kernel
520+
{
521+
public function getCacheDir()
522+
{
523+
return 'my-cache-dir';
524+
}
525+
526+
// ...
527+
}
528+
```
529+
530+
After:
531+
532+
```php
533+
class AppKernel extends Kernel
534+
{
535+
public function getCacheDir()
536+
{
537+
return $this->getWarmupDir() ?: 'my-cache-dir';
538+
}
539+
540+
// ...
541+
}
542+
```
543+
516544
Ldap
517545
----
518546

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

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

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

Lines 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

Lines 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function registerBundles()
5555

5656
public function getCacheDir()
5757
{
58-
return $this->cacheDir = sys_get_temp_dir().'/sf_micro_kernel';
58+
return $this->getWarmupDir() ?: $this->cacheDir = sys_get_temp_dir().'/sf_micro_kernel';
5959
}
6060

6161
public function getLogDir()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function getRootDir()
7272

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

7878
public function getLogDir()

src/Symfony/Bundle/SecurityBundle/composer.json

Lines 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

Lines 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

Lines 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

Lines 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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ CHANGELOG
55
-----
66

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

0 commit comments

Comments
 (0)
0