Commit 09ba274
committed
feature symfony#59704 [DependencyInjection] Add
This PR was squashed before being merged into the 7.3 branch.
Discussion
----------
[DependencyInjection] Add `Definition::addExcludedTag()` and `ContainerBuilder::findExcludedServiceIds()` for auto-discovering value-objects
| Q | A
| ------------- | ---
| Branch? | 7.3
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Issues | -
| License | MIT
We could **not** use the method `findTaggedServiceIds` in symfony#59401 (comment), same for api-platform/core#6943.
As "using the container loading tools to do resource discovery quite seamlessly" [seems to be a good idea](symfony#59401 (review)), this changes make it easier.
I'm not closed to alternative ideas if we want to go further with this use-case.
### Usage
Let's create a `AppModel` attribute class and use it on any class of the project.
In the extension class:
```php
$this->registerAttributeForAutoconfiguration(AppModel::class, static function (ChildDefinition $definition) {
$definition->addExcludedTag('app.model');
});
```
In a compiler pass:
```php
$classes = [];
foreach($containerBuilder->findExcludedServiceIds('app.model') as $id => $tags) {
$classes[] = $containerBuilder->getDefinition($id)->getClass();
}
$containerBuilder->setParameter('.app.model_classes', $classes);
```
And this parameter can be injected into a service, or directly update a service definition to inject this list of classes. The attribute parameters can be injected into the tag, and retrieved in the compiler pass, for more advanced configuration.
Commits
-------
7a0443b [DependencyInjection] Add `Definition::addExcludedTag()` and `ContainerBuilder::findExcludedServiceIds()` for auto-discovering value-objectsDefinition::addExcludedTag() and ContainerBuilder::findExcludedServiceIds() for auto-discovering value-objects (GromNaN)File tree
5 files changed
+104
-9
lines changed- src/Symfony/Component/DependencyInjection
- Tests
5 files changed
+104
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
Lines changed: 32 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1351 | 1351 | | |
1352 | 1352 | | |
1353 | 1353 | | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
1354 | 1386 | | |
1355 | 1387 | | |
1356 | 1388 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
455 | 455 | | |
456 | 456 | | |
457 | 457 | | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
458 | 472 | | |
459 | 473 | | |
460 | 474 | | |
| |||
Lines changed: 46 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1062 | 1062 | | |
1063 | 1063 | | |
1064 | 1064 | | |
1065 | | - | |
| 1065 | + | |
1066 | 1066 | | |
1067 | 1067 | | |
1068 | | - | |
1069 | | - | |
| 1068 | + | |
| 1069 | + | |
1070 | 1070 | | |
1071 | 1071 | | |
1072 | | - | |
1073 | | - | |
1074 | | - | |
1075 | | - | |
| 1072 | + | |
| 1073 | + | |
1076 | 1074 | | |
1077 | | - | |
1078 | | - | |
| 1075 | + | |
| 1076 | + | |
1079 | 1077 | | |
1080 | 1078 | | |
1081 | 1079 | | |
| |||
1085 | 1083 | | |
1086 | 1084 | | |
1087 | 1085 | | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
1088 | 1125 | | |
1089 | 1126 | | |
1090 | 1127 | | |
| |||
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
261 | 271 | | |
262 | 272 | | |
263 | 273 | | |
| |||
0 commit comments