8000 bug #22681 Fixing a bug where abstract classes were wired with the pr… · symfony/symfony@b33f1df · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit b33f1df

Browse files
committed
bug #22681 Fixing a bug where abstract classes were wired with the prototype loader (weaverryan)
This PR was merged into the 3.3-dev branch. Discussion ---------- Fixing a bug where abstract classes were wired with the prototype loader | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | n/a The prototype/PSR-4 loader currently tries to wire abstract classes. The problem is if, for example, you have, for example: ```php abstract class BaseCommand extends Command { } ``` If this is registered as a service, and you have `autoconfigure`, then the console `Application` will try to use this a command. Was there some reason abstract classes were originally allowed to be registered as services with the PSR4/prototype loader? I don't know if there is a real use-case for registering abstract classes. If you wanted to use that service as a parent service... then you'll probably be configuring it yourself anyways. We could also fix this by changing all tags compiler passes to skip classes that are abstract... *if* there is a use-case for Abstract classes being auto-registered. Cheers! Commits ------- 5326bab Fixing a bug where abstract classes were wired
2 parents a3f7860 + 5326bab commit b33f1df

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ private function findClasses($namespace, $pattern)
108108
if (!$r = $this->container->getReflectionClass($class)) {
109109
throw new InvalidArgumentException(sprintf('Expected to find class "%s" in file "%s" while importing services from resource "%s", but it was not found! Check the namespace prefix used with the resource.', $class, $path, $pattern));
110110
}
111-
if (!$r->isInterface() && !$r->isTrait()) {
111+
112+
if (!$r->isInterface() && !$r->isTrait() && !$r->isAbstract()) {
112113
$classes[] = $class;
113114
}
114115
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub;
4+
5+
abstract class NoLoadAbstractBar
6+
{
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub;
4+
5+
interface NoLoadBarInterface
6+
{
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub;
4+
5+
trait NoLoadBarTrait
6+
{
7+
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ public function testRegisterClasses()
8484

8585
$loader->registerClasses(new Definition(), 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\\', 'Prototype/%sub_dir%/*');
8686

87-
$this->assertTrue($container->has(Bar::class));
87+
$this->assertEquals(
88+
array('service_container', Bar::class),
89+
array_keys($container->getDefinitions())
90+
);
889 47ED 1
}
8992

9093
/**

0 commit comments

Comments
 (0)
0