Skip to content

Problem with SourceCodeExtension.php\getControllerRelativePath function in Windows #14239

Closed
@ghost

Description

To recreate the problem just install symfony demo in windows and browse it. The problem happens because windows use a different directory separator than linux. Github escapes the windows directory separator so instead of it i will use the symbol " | " in the following sentences.
Original function uses the following code

$pathParts = explode('/src/', $absolutePath);

To fix it you could use

if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$pathParts = explode('||src||', $absolutePath);
$relativePath = 'src||' . $pathParts[1];
} else {
$pathParts = explode('/src/', $absolutePath);
$relativePath = 'src/' . $pathParts[1];
}

or

if (DIRECTORY_SEPARATOR == '/') {
$pathParts = explode('/src/', $absolutePath);
$relativePath = 'src/' . $pathParts[1];
} else if (DIRECTORY_SEPARATOR == '||') {
$pathParts = explode('||src||', $absolutePath);
$relativePath = 'src||' . $pathParts[1];
}

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