Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpKernel] Root directory values are inconsistent #15474

@leofeyer

Description

@leofeyer

In the Kernel class, the return value of the getRootDir() method is normalized (str_replace('\\', '/', …)).

public function getRootDir()
{
    if (null === $this->rootDir) {
        $r = new \ReflectionObject($this);
        $this->rootDir = str_replace('\\', '/', dirname($r->getFileName()));
    }

    return $this->rootDir;
}

However, in the app*DebugProjectContainer class, it is not:

public function __construct()
{
    $dir = __DIR__;
    for ($i = 1; $i <= 5; ++$i) {
        $this->targetDirs[$i] = $dir = dirname($dir);
    }
    …
}

protected function getDefaultParameters()
{
    return array(
        'kernel.root_dir' => $this->targetDirs[2],
    …
}

On Windows, this means that $kernel->getRootDir() outputs something different than $container->getParameter('kernel.root_dir).

echo $kernel->getRootDir();
// C:/xampp/htdocs/symfony-standard

echo $container->getParameter('kernel.root_dir');
// C:\xampp\htdocs\symfony-standard

I'd happily create a PR, however I am not sure how to solve the problem. Should the path normalization in the getRootDir() method be removed or should the cache class be adjusted?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions