Skip to content

Commit

Permalink
bug #20676 [ClassLoader] Use only forward slashes in generated class …
Browse files Browse the repository at this point in the history
…map (nicolas-grekas)

This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #20676).

Discussion
----------

[ClassLoader] Use only forward slashes in generated class map

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20655
| License       | MIT
| Doc PR        | -

Commits
-------

6d1f1b5 [ClassLoader] Use only forward slashes in generated class map
  • Loading branch information
fabpot committed Nov 29, 2016
2 parents ec937cb + 6d1f1b5 commit 49addbe
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Symfony/Component/ClassLoader/ClassCollectionLoader.php
Expand Up @@ -63,7 +63,7 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
throw new \RuntimeException(sprintf('Class Collection Loader was not able to create directory "%s"', $cacheDir));
}
$cacheDir = rtrim(realpath($cacheDir) ?: $cacheDir, '/'.DIRECTORY_SEPARATOR);
$cache = $cacheDir.DIRECTORY_SEPARATOR.$name.$extension;
$cache = $cacheDir.'/'.$name.$extension;

// auto-reload
$reload = false;
Expand Down Expand Up @@ -114,7 +114,7 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
REGEX;
$dontInlineRegex = str_replace('.', $spacesRegex, $dontInlineRegex);

$cacheDir = explode(DIRECTORY_SEPARATOR, $cacheDir);
$cacheDir = explode('/', str_replace(DIRECTORY_SEPARATOR, '/', $cacheDir));
$files = array();
$content = '';
foreach (self::getOrderedClasses($classes) as $class) {
Expand All @@ -126,19 +126,19 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
$c = file_get_contents($file);

if (preg_match($dontInlineRegex, $c)) {
$file = explode(DIRECTORY_SEPARATOR, $file);
$file = explode('/', str_replace(DIRECTORY_SEPARATOR, '/', $file));

for ($i = 0; isset($file[$i], $cacheDir[$i]); ++$i) {
if ($file[$i] !== $cacheDir[$i]) {
break;
}
}
if (1 >= $i) {
$file = var_export(implode(DIRECTORY_SEPARATOR, $file), true);
$file = var_export(implode('/', $file), true);
} else {
$file = array_slice($file, $i);
$file = str_repeat('..'.DIRECTORY_SEPARATOR, count($cacheDir) - $i).implode(DIRECTORY_SEPARATOR, $file);
$file = '__DIR__.'.var_export(DIRECTORY_SEPARATOR.$file, true);
$file = str_repeat('../', count($cacheDir) - $i).implode('/', $file);
$file = '__DIR__.'.var_export('/'.$file, true);
}

$c = "\nnamespace {require $file;}";
Expand Down

0 comments on commit 49addbe

Please sign in to comment.