diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index dffca66710..520a886deb 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -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'] = <<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