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
-------
c7ed08e2c0
Only override getProjectDir if it exists in the kernel
This commit is contained in:
commit
c69c539ead
@ -199,15 +199,27 @@ EOF
|
|||||||
*/
|
*/
|
||||||
protected function getTempKernel(KernelInterface $parent, $namespace, $parentClass, $warmupDir)
|
protected function getTempKernel(KernelInterface $parent, $namespace, $parentClass, $warmupDir)
|
||||||
{
|
{
|
||||||
|
$projectDir = '';
|
||||||
$cacheDir = var_export($warmupDir, true);
|
$cacheDir = var_export($warmupDir, true);
|
||||||
$rootDir = var_export(realpath($parent->getRootDir()), true);
|
$rootDir = var_export(realpath($parent->getRootDir()), true);
|
||||||
$projectDir = var_export(realpath($parent->getProjectDir()), true);
|
|
||||||
$logDir = var_export(realpath($parent->getLogDir()), true);
|
$logDir = var_export(realpath($parent->getLogDir()), true);
|
||||||
// the temp kernel class name must have the same length than the real one
|
// the temp kernel class name must have the same length than the real one
|
||||||
// to avoid the many problems in serialized resources files
|
// to avoid the many problems in serialized resources files
|
||||||
$class = substr($parentClass, 0, -1).'_';
|
$class = substr($parentClass, 0, -1).'_';
|
||||||
// the temp container class must be changed too
|
// the temp container class must be changed too
|
||||||
$containerClass = var_export(substr(get_class($parent->getContainer()), 0, -1).'_', true);
|
$containerClass = var_export(substr(get_class($parent->getContainer()), 0, -1).'_', true);
|
||||||
|
|
||||||
|
if (method_exists($parent, 'getProjectDir')) {
|
||||||
|
$projectDir = var_export(realpath($parent->getProjectDir()), true);
|
||||||
|
$projectDir = <<<EOF
|
||||||
|
public function getProjectDir()
|
||||||
|
{
|
||||||
|
return $projectDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
EOF;
|
||||||
|
};
|
||||||
|
|
||||||
$code = <<<EOF
|
$code = <<<EOF
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
@ -225,11 +237,7 @@ namespace $namespace
|
|||||||
return $rootDir;
|
return $rootDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getProjectDir()
|
$projectDir
|
||||||
{
|
|
||||||
return $projectDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getLogDir()
|
public function getLogDir()
|
||||||
{
|
{
|
||||||
return $logDir;
|
return $logDir;
|
||||||
|
Reference in New Issue
Block a user