8000 [DI] fix detecting singly implemented interfaces · symfony/symfony@eccb937 · GitHub
[go: up one dir, main page]

Skip to content

Commit eccb937

Browse files
[DI] fix detecting singly implemented interfaces
1 parent 29a2f17 commit eccb937

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/Symfony/Component/DependencyInjection/Loader/FileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function registerClasses(Definition $prototype, $namespace, $resource, $e
112112
continue;
113113
}
114114
foreach (class_implements($class, false) as $interface) {
115-
$this->singlyImplemented[$interface] = isset($this->singlyImplemented[$interface]) ? false : $class;
115+
$this->singlyImplemented[$interface] = ($this->singlyImplemented[$interface] ?? $class) !== $class ? false : $class;
116116
}
117117
}
118118
}

src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ public function testRegisterClasses()
9191
$loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures'));
9292

9393
$loader->registerClasses(new Definition(), 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\\', 'Prototype/%sub_dir%/*');
94+
$loader->registerClasses(new Definition(), 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\\', 'Prototype/%sub_dir%/*'); // loading twice should not be an issue
95+
$loader->registerAliasesForSinglyImplementedInterfaces();
9496

9597
$this->assertEquals(
9698
['service_container', Bar::class],
@@ -119,6 +121,7 @@ public function testRegisterClassesWithExclude()
119121
// load everything, except OtherDir/AnotherSub & Foo.php
120122
'Prototype/{%other_dir%/AnotherSub,Foo.php}'
121123
);
124+
$loader->registerAliasesForSinglyImplementedInterfaces();
122125

123126
$this->assertTrue($container->has(Bar::class));
124127
$this->assertTrue($container->has(Baz::class));
@@ -148,6 +151,8 @@ public function testRegisterClassesWithExcludeAsArray()
148151
'Prototype/OtherDir/AnotherSub/DeeperBaz.php',
149152
]
150153
);
154+
$loader->registerAliasesForSinglyImplementedInterfaces();
155+
151156
$this->assertTrue($container->has(Foo::class));
152157
$this->assertTrue($container->has(Baz::class));
153158
$this->assertFalse($container->has(Bar::class));
@@ -162,6 +167,7 @@ public function testNestedRegisterClasses()
162167
$prototype = new Definition();
163168
$prototype->setPublic(true)->setPrivate(true);
164169
$loader->registerClasses($prototype, 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\\', 'Prototype/*');
170+
$loader->registerAliasesForSinglyImplementedInterfaces();
165171

166172
$this->assertTrue($container->has(Bar::class));
167173
$this->assertTrue($container->has(Baz::class));
@@ -193,6 +199,7 @@ public function testMissingParentClass()
193199
'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\\',
194200
'Prototype/%bad_classes_dir%/*'
195201
);
202+
$loader->registerAliasesForSinglyImplementedInterfaces();
196203

197204
$this->assertTrue($container->has(MissingParent::class));
198205

@@ -211,6 +218,7 @@ public function testRegisterClassesWithBadPrefix()
211218

212219
// the Sub is missing from namespace prefix
213220
$loader->registerClasses(new Definition(), 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\\', 'Prototype/Sub/*');
221+
$loader->registerAliasesForSinglyImplementedInterfaces();
214222
}
215223

216224
public function testRegisterClassesWithIncompatibleExclude()
@@ -226,6 +234,7 @@ public function testRegisterClassesWithIncompatibleExclude()
226234
'Prototype/*',
227235
'yaml/*'
228236
);
237+
$loader->registerAliasesForSinglyImplementedInterfaces();
229238
}
230239
}
231240

@@ -240,10 +249,4 @@ public function supports($resource, $type = null): bool
240249
{
241250
return false;
242251
}
243-
244-
public function registerClasses(Definition $prototype, $namespace, $resource, $exclude = null)
245-
{
246-
parent::registerClasses($prototype, $namespace, $resource, $exclude);
247-
$this->registerAliasesForSinglyImplementedInterfaces();
248-
}
249252
}

0 commit comments

Comments
 (0)
0