[DI] fix generating preload file when cache_dir is outside project_dir

This commit is contained in:
Nicolas Grekas 2020-09-04 16:11:41 +02:00
parent a19f91ad69
commit 02db8e1523

View File

@ -309,7 +309,7 @@ EOF;
$this->asFiles = false;
if ($this->preload && null !== $autoloadFile = $this->getAutoloadFile()) {
$autoloadFile = substr($this->export($autoloadFile), 2, -1);
$autoloadFile = trim($this->export($autoloadFile), '()\\');
$code[$options['class'].'.preload.php'] = <<<EOF
<?php
@ -2076,9 +2076,7 @@ EOF;
private function getAutoloadFile(): ?string
{
if (null === $this->targetDirRegex) {
return null;
}
$file = null;
foreach (spl_autoload_functions() as $autoloader) {
if (!\is_array($autoloader)) {
@ -2097,14 +2095,14 @@ EOF;
if (0 === strpos($class, 'ComposerAutoloaderInit') && $class::getLoader() === $autoloader[0]) {
$file = \dirname((new \ReflectionClass($class))->getFileName(), 2).'/autoload.php';
if (preg_match($this->targetDirRegex.'A', $file)) {
if (null !== $this->targetDirRegex && preg_match($this->targetDirRegex.'A', $file)) {
return $file;
}
}
}
}
return null;
return $file;
}
private function getClasses(Definition $definition): array