Skip to content

Commit c69c539

Browse files
committed
bug #22921 [FrameworkBundle] Only override getProjectDir if it exists in the kernel (aschempp)
This PR was merged into the 3.3 branch. Discussion ---------- [FrameworkBundle] Only override getProjectDir if it exists in the kernel | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22872, #2289 | License | MIT | Doc PR | - As discussed with @nicolas-grekas, the `getProjectDir` method does not belong to `KernelInterface` so it can't just be called. I think we should also not add the method to the kernel if it does not exist in the parent, because we would not have a useful value to return. Commits ------- c7ed08e Only override getProjectDir if it exists in the kernel
2 parents cf60f6d + c7ed08e commit c69c539

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,27 @@ protected function warmup($warmupDir, $realCacheDir, $enableOptionalWarmers = tr
199199
*/
200200
protected function getTempKernel(KernelInterface $parent, $namespace, $parentClass, $warmupDir)
201201
{
202+
$projectDir = '';
202203
$cacheDir = var_export($warmupDir, true);
203204
$rootDir = var_export(realpath($parent->getRootDir()), true);
204-
$projectDir = var_export(realpath($parent->getProjectDir()), true);
205205
$logDir = var_export(realpath($parent->getLogDir()), true);
206206
// the temp kernel class name must have the same length than the real one
207207
// to avoid the many problems in serialized resources files
208208
$class = substr($parentClass, 0, -1).'_';
209209
// the temp container class must be changed too
210210
$containerClass = var_export(substr(get_class($parent->getContainer()), 0, -1).'_', true);
211+
212+
if (method_exists($parent, 'getProjectDir')) {
213+
$projectDir = var_export(realpath($parent->getProjectDir()), true);
214+
$projectDir = <<<EOF
215+
public function getProjectDir()
216+
{
217+
return $projectDir;
218+
}
219+
220+
EOF;
221+
};
222+
211223
$code = <<<EOF
212224
<?php
213225
@@ -225,11 +237,7 @@ public function getRootDir()
225237
return $rootDir;
226238
}
227239
228-
public function getProjectDir()
229-
{
230-
return $projectDir;
231-
}
232-
240+
$projectDir
233241
public function getLogDir()
234242
{
235243
return $logDir;

0 commit comments

Comments
 (0)