Skip to content

Commit 0982404

Browse files
[DI] fix generating preload file when cache_dir is outside project_dir
1 parent fc9fd3b commit 0982404

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

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)