Skip to content

Commit

Permalink
bug #2342 [TwigComponent] Fix directory separator in Debug command (c…
Browse files Browse the repository at this point in the history
…lussiana, smnandre)

This PR was merged into the 2.x branch.

Discussion
----------

[TwigComponent] Fix directory separator in Debug command

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| Issues        |
| License       | MIT

Component template paths are retrieved by the `SplFileInfo` class, which returns paths containing backslashes on Windows and slashes on other operating systems.

So on Windows environment, the command fails as the component `Card\Card.html.twig` is not formatted into `Card:Card`

Commits
-------

41d9df0 Fix copy/paste error
3664af5 CS fix
d906c6e fix: replace / by DIRECTORY_SEPARATOR
  • Loading branch information
smnandre committed Nov 7, 2024
2 parents 2f1e7b8 + 41d9df0 commit 8215922
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/TwigComponent/src/Command/TwigComponentDebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ private function findAnonymousComponents(): array
->name('*.html.twig')
;
foreach ($finderTemplates as $template) {
$component = str_replace('/', ':', $template->getRelativePathname());
$component = str_replace(\DIRECTORY_SEPARATOR, ':', $template->getRelativePathname());
$component = substr($component, 0, -10); // remove file extension ".html.twig"
$path = $template->getPath();

if ($template->getRelativePath()) {
$path = \rtrim(\substr($template->getPath(), 0, -1 * \strlen($template->getRelativePath())), '/');
$path = rtrim(substr($template->getPath(), 0, -1 * \strlen($template->getRelativePath())), \DIRECTORY_SEPARATOR);
}

if (isset($dirs[$path]) && FilesystemLoader::MAIN_NAMESPACE !== $dirs[$path]) {
Expand Down

0 comments on commit 8215922

Please sign in to comment.