|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\DependencyInjection;
|
13 | 13 |
|
| 14 | +use Composer\Autoload\ClassLoader; |
14 | 15 | use Composer\InstalledVersions;
|
15 | 16 | use Symfony\Component\Config\Resource\ClassExistenceResource;
|
16 | 17 | use Symfony\Component\Config\Resource\ComposerResource;
|
|
46 | 47 | use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
|
47 | 48 | use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
48 | 49 | use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
| 50 | +use Symfony\Component\ErrorHandler\DebugClassLoader; |
49 | 51 | use Symfony\Component\ExpressionLanguage\Expression;
|
50 | 52 | use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
|
51 | 53 |
|
@@ -117,7 +119,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
117 | 119 | private array $vendors;
|
118 | 120 |
|
119 | 121 | /**
|
120 |
| - * @var array<string, bool> the cache for paths being in vendor directories |
| 122 | + * @var array<string, bool> whether a path is in a vendor directory |
121 | 123 | */
|
122 | 124 | private array $pathsInVendor = [];
|
123 | 125 |
|
@@ -262,6 +264,53 @@ public function addResource(ResourceInterface $resource): static
|
262 | 264 | if ($resource instanceof GlobResource && $this->inVendors($resource->getPrefix())) {
|
263 | 265 | return $this;
|
264 | 266 | }
|
| 267 | + if ($resource instanceof FileExistenceResource && $this->inVendors($resource->getResource())) { |
| 268 | + return $this; |
| 269 | + } |
| 270 | + if ($resource instanceof FileResource && $this->inVendors($resource->getResource())) { |
| 271 | + return $this; |
| 272 | + } |
| 273 | + if ($resource instanceof DirectoryResource && $this->inVendors($resource->getResource())) { |
| 274 | + return $this; |
| 275 | + } |
| 276 | + if ($resource instanceof ClassExistenceResource) { |
| 277 | + $class = $resource->getResource(); |
| 278 | + |
| 279 | + $inVendor = false; |
| 280 | + foreach (spl_autoload_functions() as $autoloader) { |
| 281 | + if (!\is_array($autoloader)) { |
| 282 | + continue; |
| 283 | + } |
| 284 | + |
| 285 | + if ($autoloader[0] instanceof DebugClassLoader) { |
| 286 | + $autoloader = $autoloader[0]->getClassLoader(); |
| 287 | + } |
| 288 | + |
| 289 | + if (!\is_array($autoloader) || !$autoloader[0] instanceof ClassLoader || !$autoloader[0]->findFile(__CLASS__)) { |
| 290 | + continue; |
| 291 | + } |
| 292 | + |
| 293 | + foreach ($autoloader[0]->getPrefixesPsr4() as $prefix => $dirs) { |
| 294 | + if ('' === $prefix || !str_starts_with($class, $prefix)) { |
| 295 | + continue; |
| 296 | + } |
| 297 | + |
| 298 | + foreach ($dirs as $dir) { |
| 299 | + if (!$dir = realpath($dir)) { |
| 300 | + continue; |
| 301 | + } |
| 302 | + |
| 303 | + if (!$inVendor = $this->inVendors($dir)) { |
| 304 | + break 3; |
| 305 | + } |
| 306 | + } |
| 307 | + } |
| 308 | + } |
| 309 | + |
| 310 | + if ($inVendor) { |
| 311 | + return $this; |
| 312 | + } |
| 313 | + } |
265 | 314 |
|
266 | 315 | $this->resources[(string) $resource] = $resource;
|
267 | 316 |
|
@@ -1693,8 +1742,10 @@ private function inVendors(string $path): bool
|
1693 | 1742 | }
|
1694 | 1743 |
|
1695 | 1744 | foreach ($this->vendors as $vendor) {
|
1696 |
| - if (str_starts_with($path, $vendor) && false !== strpbrk(substr($path, \strlen($vendor), 1), '/'.\DIRECTORY_SEPARATOR)) { |
| 1745 | + if (\in_array($path[\strlen($vendor)] ?? '', ['/', \DIRECTORY_SEPARATOR], true) && str_starts_with($path, $vendor)) { |
| 1746 | + $this->pathsInVendor[$vendor.'/composer'] = false; |
1697 | 1747 | $this->addResource(new FileResource($vendor.'/composer/installed.json'));
|
| 1748 | + $this->pathsInVendor[$vendor.'/composer'] = true; |
1698 | 1749 |
|
1699 | 1750 | return $this->pathsInVendor[$path] = true;
|
1700 | 1751 | }
|
|
0 commit comments