Skip to content

Commit b253363

Browse files
-
1 parent d33a4f7 commit b253363

File tree

12 files changed

+31
-22
lines changed

12 files changed

+31
-22
lines changed

UPGRADE-7.4.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ DependencyInjection
2727
-------------------
2828

2929
* Add argument `$target` to `ContainerBuilder::registerAliasForArgument()`
30-
* Add argument `$skipAbstractClasses` to `ContainerBuilder::findTaggedResourceIds()`
30+
* Add argument `$throwOnAbstract` to `ContainerBuilder::findTaggedResourceIds()`
3131
* Deprecate registering a service without a class when its id is a non-existing FQCN
3232

3333
DoctrineBridge

src/Symfony/Component/DependencyInjection/Compiler/ResolveInvalidReferencesPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private function processValue(mixed $value, int $rootLevel = 0, int $level = 0):
6262
} elseif ($value instanceof ArgumentInterface) {
6363
$value->setValues($this->processValue($value->getValues(), $rootLevel, 1 + $level));
6464
} elseif ($value instanceof Definition) {
65-
if ($value->isSynthetic() || $value->isAbstract()) {
65+
if ($value->isSynthetic() || $value->isAbstract() || $value->hasTag('container.excluded')) {
6666
return $value;
6767
}
6868
$value->setArguments($this->processValue($value->getArguments(), 0));

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,22 +1366,29 @@ public function findTaggedServiceIds(string $name, bool $throwOnAbstract = false
13661366
* }
13671367
* }
13681368
*
1369-
* @param bool $skipAbstractClasses Whether to skip abstract classes (noted by the `container.abstract` tag)
1369+
* @param bool $throwOnAbstract Whether to throw if an abstract class is found
13701370
*
13711371
* @return array<string, array> An array of tags with the tagged service as key, holding a list of attribute arrays
13721372
*/
1373-
public function findTaggedResourceIds(string $tagName/* , bool $skipAbstractClasses = true */): array
1373+
public function findTaggedResourceIds(string $tagName/* , bool $throwOnAbstract = true */): array
13741374
{
1375-
$skipAbstractClasses = \func_num_args() > 1 ? func_get_arg(1) : true;
1375+
$throwOnAbstract = \func_num_args() > 1 ? func_get_arg(1) : true;
13761376
$this->usedTags[] = $tagName;
13771377
$tags = [];
13781378
foreach ($this->getDefinitions() as $id => $definition) {
1379-
if (!$definition->hasTag($tagName) || $skipAbstractClasses && $definition->hasTag('container.abstract')) {
1379+
if (!$definition->hasTag($tagName)) {
13801380
continue;
13811381
}
13821382
if (!$definition->hasTag('container.excluded')) {
13831383
throw new InvalidArgumentException(\sprintf('The resource "%s" tagged "%s" is missing the "container.excluded" tag.', $id, $tagName));
13841384
}
1385+
$class = $this->parameterBag->resolveValue($definition->getClass());
1386+
if (!$class || interface_exists($class) || $throwOnAbstract && $definition->isAbstract()) {
1387+
throw new InvalidArgumentException(\sprintf('The resource "%s" tagged "%s" must refer to a concrete class.', $id, $tagName));
1388+
}
1389+
if ($definition->getClass() !== $class) {
1390+
$definition->setClass($class);
1391+
}
13851392
$tags[$id] = $definition->getTag($tagName);
13861393
}
13871394

src/Symfony/Component/DependencyInjection/Definition.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,7 @@ public function addTag(string $name, array $attributes = []): static
465465
public function addResourceTag(string $name, array $attributes = []): static
466466
{
467467
return $this->addTag($name, $attributes)
468-
->addTag('container.excluded', ['source' => \sprintf('by tag "%s"', $name)])
469-
->setAbstract(true);
468+
->addTag('container.excluded', ['source' => \sprintf('by tag "%s"', $name)]);
470469
}
471470

472471
/**

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ public function registerClasses(Definition $prototype, string $namespace, string
207207
$autoconfigureAttributes?->processClass($this->container, $r);
208208
if (!$r->isInterface()) {
209209
$definition->setAbstract(true)
210-
->addTag('container.excluded', ['source' => 'because the class is abstract'])
211-
->addTag('container.abstract');
210+
->addTag('container.excluded', ['source' => 'because the class is abstract']);
212211
}
213212
continue;
214213
}

src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public function testAddResourceTag()
262262
$def->addResourceTag('foo', ['bar' => true]);
263263

264264
$this->assertSame([['bar' => true]], $def->getTag('foo'));
265-
$this->assertTrue($def->isAbstract());
265+
$this->assertFalse($def->isAbstract());
266266
$this->assertSame([['source' => 'by tag "foo"']], $def->getTag('container.excluded'));
267267
}
268268

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ public function testRegisterClassesWithAbstractClassesAndAutoconfigure()
231231
$definition = $container->getDefinition('.abstract.'.AbstractClass::class);
232232
$this->assertTrue($definition->isAbstract());
233233
$this->assertTrue($definition->hasTag('container.excluded'));
234-
$this->assertTrue($definition->hasTag('container.abstract'));
235234
$this->assertTrue($definition->isAutoconfigured());
236235
}
237236

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function testResourceTags()
156156
$this->assertTrue($def->hasTag('another.tag'));
157157
$this->assertSame([['foo' => 'bar']], $def->getTag('my.tag'));
158158
$this->assertSame([[]], $def->getTag('another.tag'));
159-
$this->assertTrue($def->isAbstract());
159+
$this->assertFalse($def->isAbstract());
160160
}
161161

162162
public function testAutoConfigureAndChildDefinition()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ public function testResourceTags()
381381
$this->assertTrue($def->hasTag('another.tag'));
382382
$this->assertSame([['foo' => 'bar']], $def->getTag('my.tag'));
383383
$this->assertSame([[]], $def->getTag('another.tag'));
384-
$this->assertTrue($def->isAbstract());
384+
$this->assertFalse($def->isAbstract());
385385
}
386386

387387
public function testParsesIteratorArgument()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public function testResourceTags()
259259
$this->assertTrue($def->hasTag('another.tag'));
260260
$this->assertSame([['foo' => 'bar']], $def->getTag('my.tag'));
261261
$this->assertSame([[]], $def->getTag('another.tag'));
262-
$this->assertTrue($def->isAbstract());
262+
$this->assertFalse($def->isAbstract());
263263
}
264264

265265
public function testLoadShortSyntax()

0 commit comments

Comments
 (0)