-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[Config][DependencyInjection] Optimize dumped resources for tracking #57948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
|
|
||
| namespace Symfony\Component\DependencyInjection; | ||
|
|
||
| use Composer\Autoload\ClassLoader; | ||
| use Composer\InstalledVersions; | ||
| use Symfony\Component\Config\Resource\ClassExistenceResource; | ||
| use Symfony\Component\Config\Resource\ComposerResource; | ||
|
|
@@ -46,6 +47,7 @@ | |
| use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag; | ||
| use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; | ||
| use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||
| use Symfony\Component\ErrorHandler\DebugClassLoader; | ||
| use Symfony\Component\ExpressionLanguage\Expression; | ||
| use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; | ||
|
|
||
|
|
@@ -117,7 +119,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface | |
| private array $vendors; | ||
|
|
||
| /** | ||
| * @var array<string, bool> the cache for paths being in vendor directories | ||
| * @var array<string, bool> whether a path is in a vendor directory | ||
| */ | ||
| private array $pathsInVendor = []; | ||
|
|
||
|
|
@@ -262,6 +264,53 @@ public function addResource(ResourceInterface $resource): static | |
| if ($resource instanceof GlobResource && $this->inVendors($resource->getPrefix())) { | ||
| return $this; | ||
| } | ||
| if ($resource instanceof FileExistenceResource && $this->inVendors($resource->getResource())) { | ||
| return $this; | ||
| } | ||
| if ($resource instanceof FileResource && $this->inVendors($resource->getResource())) { | ||
| return $this; | ||
| } | ||
| if ($resource instanceof DirectoryResource && $this->inVendors($resource->getResource())) { | ||
| return $this; | ||
| } | ||
| if ($resource instanceof ClassExistenceResource) { | ||
| $class = $resource->getResource(); | ||
|
|
||
| $inVendor = false; | ||
| foreach (spl_autoload_functions() as $autoloader) { | ||
| if (!\is_array($autoloader)) { | ||
| continue; | ||
| } | ||
|
|
||
| if ($autoloader[0] instanceof DebugClassLoader) { | ||
| $autoloader = $autoloader[0]->getClassLoader(); | ||
| } | ||
|
|
||
| if (!\is_array($autoloader) || !$autoloader[0] instanceof ClassLoader || !$autoloader[0]->findFile(__CLASS__)) { | ||
| continue; | ||
| } | ||
|
|
||
| foreach ($autoloader[0]->getPrefixesPsr4() as $prefix => $dirs) { | ||
| if ('' === $prefix || !str_starts_with($class, $prefix)) { | ||
nicolas-grekas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| continue; | ||
| } | ||
|
|
||
| foreach ($dirs as $dir) { | ||
| if (!$dir = realpath($dir)) { | ||
| continue; | ||
| } | ||
|
|
||
| if (!$inVendor = $this->inVendors($dir)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic looks wrong to me. Configuring a namespace prefixed to match a given directory does not mean that all classes matching that prefix must be defined in that folder. For existing classes, we can optimize the class existence resource if the class is defined in the vendor folder (by checking the actual class definition, not folders in which it is maybe defined). For non-existent classes, we should not optimize the resource (or we should optimize it only based on all possible autoloading locations) |
||
| break 3; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if ($inVendor) { | ||
| return $this; | ||
| } | ||
| } | ||
|
|
||
| $this->resources[(string) $resource] = $resource; | ||
|
|
||
|
|
@@ -1693,8 +1742,10 @@ private function inVendors(string $path): bool | |
| } | ||
|
|
||
| foreach ($this->vendors as $vendor) { | ||
| if (str_starts_with($path, $vendor) && false !== strpbrk(substr($path, \strlen($vendor), 1), '/'.\DIRECTORY_SEPARATOR)) { | ||
| if (\in_array($path[\strlen($vendor)] ?? '', ['/', \DIRECTORY_SEPARATOR], true) && str_starts_with($path, $vendor)) { | ||
| $this->pathsInVendor[$vendor.'/composer'] = false; | ||
| $this->addResource(new FileResource($vendor.'/composer/installed.json')); | ||
| $this->pathsInVendor[$vendor.'/composer'] = true; | ||
|
|
||
| return $this->pathsInVendor[$path] = true; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.