Skip to content

Commit 4222a72

Browse files
committed
bug symfony#38062 [DI] fix generating preload file when cache_dir is outside project_dir (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [DI] fix generating preload file when cache_dir is outside project_dir | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | no | License | MIT | Doc PR | - Commits ------- 02db8e1 [DI] fix generating preload file when cache_dir is outside project_dir
2 parents da73be8 + 02db8e1 commit 4222a72

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public function dump(array $options = [])
309309
$this->asFiles = false;
310310

311311
if ($this->preload && null !== $autoloadFile = $this->getAutoloadFile()) {
312-
$autoloadFile = substr($this->export($autoloadFile), 2, -1);
312+
$autoloadFile = trim($this->export($autoloadFile), '()\\');
313313

314314
$code[$options['class'].'.preload.php'] = <<<EOF
315315
<?php
@@ -2076,9 +2076,7 @@ private function doExport($value, bool $resolveEnv = false)
20762076

20772077
private function getAutoloadFile(): ?string
20782078
{
2079-
if (null === $this->targetDirRegex) {
2080-
return null;
2081-
}
2079+
$file = null;
20822080

20832081
foreach (spl_autoload_functions() as $autoloader) {
20842082
if (!\is_array($autoloader)) {
@@ -2097,14 +2095,14 @@ private function getAutoloadFile(): ?string
20972095
if (0 === strpos($class, 'ComposerAutoloaderInit') && $class::getLoader() === $autoloader[0]) {
20982096
$file = \dirname((new \ReflectionClass($class))->getFileName(), 2).'/autoload.php';
20992097

2100-
if (preg_match($this->targetDirRegex.'A', $file)) {
2098+
if (null !== $this->targetDirRegex && preg_match($this->targetDirRegex.'A', $file)) {
21012099
return $file;
21022100
}
21032101
}
21042102
}
21052103
}
21062104

2107-
return null;
2105+
return $file;
21082106
}
21092107

21102108
private function getClasses(Definition $definition): array

0 commit comments

Comments
 (0)