Skip to content

Commit 44dd80f

Browse files
committed
bug #38139 [DI] dump OS-indepent paths in the compiled container (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [DI] dump OS-indepent paths in the compiled container | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #38123 | License | MIT | Doc PR | - This allows compiling on Windows and running on Linux (Docker). Commits ------- 4dcf9e7 [DI] dump OS-indepent paths in the compiled container
2 parents e8dc35d + 4dcf9e7 commit 44dd80f

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2017,7 +2017,15 @@ private function export($value)
20172017
$suffix = $matches[0][1] + \strlen($matches[0][0]);
20182018
$matches[0][1] += \strlen($matches[1][0]);
20192019
$prefix = $matches[0][1] ? $this->doExport(substr($value, 0, $matches[0][1]), true).'.' : '';
2020-
$suffix = isset($value[$suffix]) ? '.'.$this->doExport(substr($value, $suffix), true) : '';
2020+
2021+
if ('\\' === \DIRECTORY_SEPARATOR && isset($value[$suffix])) {
2022+
$cookie = '\\'.random_int(100000, \PHP_INT_MAX);
2023+
$suffix = '.'.$this->doExport(str_replace('\\', $cookie, substr($value, $suffix)), true);
2024+
$suffix = str_replace('\\'.$cookie, "'.\\DIRECTORY_SEPARATOR.'", $suffix);
2025+
} else {
2026+
$suffix = isset($value[$suffix]) ? '.'.$this->doExport(substr($value, $suffix), true) : '';
2027+
}
2028+
20212029
$dirname = $this->asFiles ? '$this->containerDir' : '__DIR__';
20222030
$offset = 2 + $this->targetDirMaxMatches - \count($matches);
20232031

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public function testDumpAsFiles()
233233
$dumper = new PhpDumper($container);
234234
$dump = print_r($dumper->dump(['as_files' => true, 'file' => __DIR__, 'hot_path_tag' => 'hot']), true);
235235
if ('\\' === \DIRECTORY_SEPARATOR) {
236-
$dump = str_replace('\\\\Fixtures\\\\includes\\\\foo.php', '/Fixtures/includes/foo.php', $dump);
236+
$dump = str_replace("'.\\DIRECTORY_SEPARATOR.'", '/', $dump);
237237
}
238238
$this->assertStringMatchesFormatFile(self::$fixturesPath.'/php/services9_as_files.txt', $dump);
239239
}
@@ -260,7 +260,7 @@ public function testDumpAsFilesWithFactoriesInlined()
260260
$dump = print_r($dumper->dump(['as_files' => true, 'file' => __DIR__, 'hot_path_tag' => 'hot', 'build_time' => 1563381341]), true);
261261

262262
if ('\\' === \DIRECTORY_SEPARATOR) {
263-
$dump = str_replace('\\\\Fixtures\\\\includes\\\\', '/Fixtures/includes/', $dump);
263+
$dump = str_replace("'.\\DIRECTORY_SEPARATOR.'", '/', $dump);
264264
}
265265
$this->assertStringMatchesFormatFile(self::$fixturesPath.'/php/services9_inlined_factories.txt', $dump);
266266
}
@@ -286,7 +286,7 @@ public function testDumpAsFilesWithLazyFactoriesInlined()
286286
$dump = print_r($dumper->dump(['as_files' => true, 'file' => __DIR__, 'hot_path_tag' => 'hot', 'build_time' => 1563381341]), true);
287287

288288
if ('\\' === \DIRECTORY_SEPARATOR) {
289-
$dump = str_replace('\\\\Fixtures\\\\includes\\\\', '/Fixtures/includes/', $dump);
289+
$dump = str_replace("'.\\DIRECTORY_SEPARATOR.'", '/', $dump);
290290
}
291291
$this->assertStringMatchesFormatFile(self::$fixturesPath.'/php/services9_lazy_inlined_factories.txt', $dump);
292292
}
@@ -304,7 +304,7 @@ public function testNonSharedLazyDumpAsFiles()
304304
$dump = print_r($dumper->dump(['as_files' => true, 'file' => __DIR__]), true);
305305

306306
if ('\\' === \DIRECTORY_SEPARATOR) {
307-
$dump = str_replace('\\\\Fixtures\\\\includes\\\\foo_lazy.php', '/Fixtures/includes/foo_lazy.php', $dump);
307+
$dump = str_replace("'.\\DIRECTORY_SEPARATOR.'", '/', $dump);
308308
}
309309
$this->assertStringMatchesFormatFile(self::$fixturesPath.'/php/services_non_shared_lazy_as_files.txt', $dump);
310310
}
@@ -980,7 +980,7 @@ public function testArrayParameters()
980980

981981
$dumper = new PhpDumper($container);
982982

983-
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_array_params.php', str_replace('\\\\Dumper', '/Dumper', $dumper->dump(['file' => self::$fixturesPath.'/php/services_array_params.php'])));
983+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_array_params.php', str_replace("'.\\DIRECTORY_SEPARATOR.'", '/', $dumper->dump(['file' => self::$fixturesPath.'/php/services_array_params.php'])));
984984
}
985985

986986
public function testExpressionReferencingPrivateService()
@@ -1143,7 +1143,7 @@ public function testHotPathOptimizations()
11431143

11441144
$dump = $dumper->dump(['hot_path_tag' => 'container.hot_path', 'inline_class_loader_parameter' => 'inline_requires', 'file' => self::$fixturesPath.'/php/services_inline_requires.php']);
11451145
if ('\\' === \DIRECTORY_SEPARATOR) {
1146-
$dump = str_replace("'\\\\includes\\\\HotPath\\\\", "'/includes/HotPath/", $dump);
1146+
$dump = str_replace("'.\\DIRECTORY_SEPARATOR.'", '/', $dump);
11471147
}
11481148

11491149
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_inline_requires.php', $dump);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy