25
25
*/
26
26
class CacheClearCommand extends ContainerAwareCommand
27
27
{
28
+ protected $ name ;
29
+
28
30
/**
29
31
* @see Command
30
32
*/
@@ -85,13 +87,33 @@ protected function warmup($warmupDir)
85
87
$ warmer ->warmUp ($ warmupDir );
86
88
87
89
// fix container files and classes
90
+ $ regex = '/ ' .preg_quote ($ this ->getTempKernelSuffix (), '/ ' ).'/ ' ;
88
91
$ finder = new Finder ();
89
92
foreach ($ finder ->files ()->name (get_class ($ kernel ->getContainer ()).'* ' )->in ($ warmupDir ) as $ file ) {
90
93
$ content = file_get_contents ($ file );
91
- $ content = preg_replace (' /__.*__/ ' , '' , $ content );
92
- file_put_contents (preg_replace (' /__.*__/ ' , '' , $ file ), $ content );
94
+ $ content = preg_replace ($ regex , '' , $ content );
95
+ file_put_contents (preg_replace ($ regex , '' , $ file ), $ content );
93
96
unlink ($ file );
94
97
}
98
+
99
+ // fix meta references to the Kernel
100
+ foreach ($ finder ->files ()->name ('*.meta ' )->in ($ warmupDir ) as $ file ) {
101
+ $ content = preg_replace (
102
+ '/C\:\d+\:"AppKernel ' .preg_quote ($ this ->getTempKernelSuffix (), '"/ ' ).'"/ ' ,
103
+ 'C:9:"AppKernel" ' ,
104
+ file_get_contents ($ file )
105
+ );
106
+ file_put_contents ($ file , $ content );
107
+ }
108
+ }
109
+
110
+ protected function getTempKernelSuffix ()
111
+ {
112
+ if (null === $ this ->name ) {
113
+ $ this ->name = '__ ' .uniqid ().'__ ' ;
114
+ }
115
+
116
+ return $ this ->name ;
95
117
}
96
118
97
119
protected function getTempKernel (KernelInterface $ parent , $ warmupDir )
@@ -104,8 +126,8 @@ protected function getTempKernel(KernelInterface $parent, $warmupDir)
104
126
$ parentClass = substr ($ parentClass , $ pos + 1 );
105
127
}
106
128
107
- $ rand = uniqid ();
108
- $ class = $ parentClass .$ rand ;
129
+ $ suffix = $ this -> getTempKernelSuffix ();
130
+ $ class = $ parentClass .$ suffix ;
109
131
$ rootDir = $ parent ->getRootDir ();
110
132
$ code = <<<EOF
111
133
<?php
@@ -126,7 +148,7 @@ public function getRootDir()
126
148
127
149
protected function getContainerClass()
128
150
{
129
- return parent::getContainerClass().'__ { $ rand } __ ';
151
+ return parent::getContainerClass().' { $ suffix } ';
130
152
}
131
153
}
132
154
}
0 commit comments