19
19
use Symfony \Component \Filesystem \Filesystem ;
20
20
use Symfony \Component \HttpKernel \CacheClearer \CacheClearerInterface ;
21
21
use Symfony \Component \HttpKernel \KernelInterface ;
22
+ use Symfony \Component \HttpKernel \RebootableInterface ;
22
23
use Symfony \Component \Finder \Finder ;
23
24
24
25
/**
@@ -33,6 +34,7 @@ class CacheClearCommand extends ContainerAwareCommand
33
34
{
34
35
private $ cacheClearer ;
35
36
private $ filesystem ;
37
+ private $ warning ;
36
38
37
39
/**
38
40
* @param CacheClearerInterface $cacheClearer
@@ -112,6 +114,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
112
114
$ this ->filesystem ->rename ($ realCacheDir , $ oldCacheDir );
113
115
} else {
114
116
$ 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
+ }
115
123
}
116
124
117
125
if ($ output ->isVerbose ()) {
@@ -167,17 +175,23 @@ protected function warmup($warmupDir, $realCacheDir, $enableOptionalWarmers = tr
167
175
{
168
176
// create a temporary kernel
169
177
$ realKernel = $ this ->getApplication ()->getKernel ();
170
- $ realKernelClass = get_class ($ realKernel );
171
- $ namespace = '' ;
172
- if (false !== $ pos = strrpos ($ realKernelClass , '\\' )) {
173
- $ namespace = substr ($ realKernelClass , 0 , $ pos );
174
- $ realKernelClass = substr ($ realKernelClass , $ pos + 1 );
175
- }
176
- $ tempKernel = $ this ->getTempKernel ($ realKernel , $ namespace , $ realKernelClass , $ warmupDir );
177
- $ tempKernel ->boot ();
178
+ if ($ realKernel instanceof RebootableInterface) {
179
+ $ realKernel ->reboot ($ warmupDir );
180
+ $ tempKernel = $ realKernel ;
181
+ } else {
182
+ $ 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. ' ;
183
+ $ realKernelClass = get_class ($ realKernel );
184
+ $ namespace = '' ;
185
+ if (false !== $ pos = strrpos ($ realKernelClass , '\\' )) {
186
+ $ namespace = substr ($ realKernelClass , 0 , $ pos );
187
+ $ realKernelClass = substr ($ realKernelClass , $ pos + 1 );
188
+ }
189
+ $ tempKernel = $ this ->getTempKernel ($ realKernel , $ namespace , $ realKernelClass , $ warmupDir );
190
+ $ tempKernel ->boot ();
178
191
179
- $ tempKernelReflection = new \ReflectionObject ($ tempKernel );
180
- $ tempKernelFile = $ tempKernelReflection ->getFileName ();
192
+ $ tempKernelReflection = new \ReflectionObject ($ tempKernel );
193
+ $ tempKernelFile = $ tempKernelReflection ->getFileName ();
194
+ }
181
195
182
196
// warmup temporary dir
183
197
$ warmer = $ tempKernel ->getContainer ()->get ('cache_warmer ' );
@@ -186,6 +200,20 @@ protected function warmup($warmupDir, $realCacheDir, $enableOptionalWarmers = tr
186
200
}
187
201
$ warmer ->warmUp ($ warmupDir );
188
202
203
+ // fix references to cached files with the real cache directory name
204
+ $ search = array ($ warmupDir , str_replace ('\\' , '\\\\' , $ warmupDir ));
205
+ $ replace = str_replace ('\\' , '/ ' , $ realCacheDir );
206
+ foreach (Finder::create ()->files ()->in ($ warmupDir ) as $ file ) {
207
+ $ content = str_replace ($ search , $ replace , file_get_contents ($ file ), $ count );
208
+ if ($ count ) {
209
+ file_put_contents ($ file , $ content );
210
+ }
211
+ }
212
+
213
+ if ($ realKernel instanceof RebootableInterface) {
214
+ return ;
215
+ }
216
+
189
217
// fix references to the Kernel in .meta files
190
218
$ safeTempKernel = str_replace ('\\' , '\\\\' , get_class ($ tempKernel ));
191
219
$ realKernelFQN = get_class ($ realKernel );
@@ -198,16 +226,6 @@ protected function warmup($warmupDir, $realCacheDir, $enableOptionalWarmers = tr
198
226
));
199
227
}
200
228
201
- // fix references to cached files with the real cache directory name
202
- $ search = array ($ warmupDir , str_replace ('\\' , '\\\\' , $ warmupDir ));
203
- $ replace = str_replace ('\\' , '/ ' , $ realCacheDir );
204
- foreach (Finder::create ()->files ()->in ($ warmupDir ) as $ file ) {
205
- $ content = str_replace ($ search , $ replace , file_get_contents ($ file ), $ count );
206
- if ($ count ) {
207
- file_put_contents ($ file , $ content );
208
- }
209
- }
210
-
211
229
// fix references to container's class
212
230
$ tempContainerClass = $ tempKernel ->getContainerClass ();
213
231
$ realContainerClass = $ tempKernel ->getRealContainerClass ();
0 commit comments