Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DependencyInjection] Fix optimizing ClassExistenceResource#61615

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nicolas-grekas merged 1 commit intosymfony:7.3fromnicolas-grekas:di-fix
Sep 3, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 38 additions & 26 deletionssrc/Symfony/Component/DependencyInjection/ContainerBuilder.php
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -273,46 +273,58 @@ public function addResource(ResourceInterface $resource): static
if ($resource instanceof DirectoryResource && $this->inVendors($resource->getResource())) {
return $this;
}
if ($resource instanceof ClassExistenceResource) {
$class= $resource->getResource();
if (!$resource instanceof ClassExistenceResource) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

should we extract the check of ClassExistenceResource being in vendors into a private method instead of this early check of any other type ? It might reduce the risk of mistakes when wanting to optimize other Resource implementations in the future.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

let's see in the future :)

$this->resources[(string) $resource]= $resource;

$inVendor = false;
foreach (spl_autoload_functions() as $autoloader) {
if (!\is_array($autoloader)) {
continue;
}
return $this;
}

if ($autoloader[0] instanceof DebugClassLoader) {
$autoloader = $autoloader[0]->getClassLoader();
}
$class = $resource->getResource();

if (!(new ClassExistenceResource($class, false))->isFresh(1)) {
if (!$this->inVendors((new \ReflectionClass($class))->getFileName())) {
$this->resources[$class] = $resource;
}

return $this;
}

$inVendor = true;
foreach (spl_autoload_functions() as $autoloader) {
if (!\is_array($autoloader)) {
$inVendor = false;
break;
}

if ($autoloader[0] instanceof DebugClassLoader) {
$autoloader = $autoloader[0]->getClassLoader();
}

if (!\is_array($autoloader) || !$autoloader[0] instanceof ClassLoader || !$autoloader[0]->findFile(__CLASS__)) {
if (!\is_array($autoloader) || !$autoloader[0] instanceof ClassLoader) {
$inVendor = false;
break;
}

foreach ($autoloader[0]->getPrefixesPsr4() as $prefix => $dirs) {
if (!str_starts_with($class, $prefix)) {
continue;
}

foreach ($autoloader[0]->getPrefixesPsr4() as $prefix => $dirs) {
if ('' === $prefix || !str_starts_with($class, $prefix)) {
foreach ($dirs as $dir) {
if (!$dir = realpath($dir)) {
continue;
}

foreach ($dirs as $dir) {
if (!$dir = realpath($dir)) {
continue;
}

if (!$inVendor = $this->inVendors($dir)) {
break 3;
}
if (!$inVendor = $this->inVendors($dir)) {
break 3;
}
}
}

if ($inVendor) {
return $this;
}
}

$this->resources[(string) $resource] = $resource;
if (!$inVendor) {
$this->resources[$class] = $resource;
}

return $this;
}
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1230,7 +1230,10 @@ public function testGetReflectionClass()
$r2 = $container->getReflectionClass('BarClass');
$r3 = $container->getReflectionClass('BarClass');

$this->assertNull($container->getReflectionClass('BarMissingClass'));
$this->assertNull($container->getReflectionClass(BarMissingClass::class));

// No resource should be added for this class because no autoloader would be able to load it
$this->assertNull($container->getReflectionClass(\BarMissingClass::class));

$this->assertEquals($r1, $r2);
$this->assertSame($r2, $r3);
Expand All@@ -1240,7 +1243,7 @@ public function testGetReflectionClass()
$this->assertCount(2, $resources);

$this->assertSame('reflection.BarClass', (string) $resources[0]);
$this->assertSame('BarMissingClass', (string) end($resources));
$this->assertSame(BarMissingClass::class, (string) end($resources));
}

public function testGetReflectionClassOnInternalTypes()
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp