Commit 18d7668
committed
feature symfony#61575 [DependencyInjection] Allow multiple
This PR was squashed before being merged into the 7.4 branch.
Discussion
----------
[DependencyInjection] Allow multiple `#[AsDecorator]` attributes
| Q | A
| ------------- | ---
| Branch? | 7.4
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Issues |
| License | MIT
Make `#[AsDecorator]` attribute repeatable to allow decorating multiple services at once.
Example for a simple HttpClient logger:
```php
#[AsDecorator('api1.client')]
#[AsDecorator('api2.client')]
#[AsDecorator('api3.client')]
class LoggableService implements HttpClientInterface
{
use DecoratorTrait;
public function __construct(
private HttpClientInterface $client,
private readonly LoggerInterface $logger,
) {
}
public function request(string $method, string $url, array $options = []): ResponseInterface
{
try {
$response = $this->client->request($method, $url, $options);
$this->logger->info('API call: {method} {url}.', ['method'= > $method, 'url' => $url]);
return $response;
} catch (\Throwable $e) {
$this->logger->error('API call failed: {method} {url}.', ['method'= > $method, 'url' => $url, 'exception' => $e]);
throw $exception;
}
}
}
```
Commits
-------
3986c94 [DependencyInjection] Allow multiple `#[AsDecorator]` attributes#[AsDecorator] attributes (Jean-Beru)File tree
5 files changed
+60
-5
lines changed- src/Symfony/Component/DependencyInjection
- Attribute
- Compiler
- Tests
- Compiler
- Fixtures/includes
5 files changed
+60
-5
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
Lines changed: 19 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
41 | 52 | | |
42 | 53 | | |
| 54 | + | |
43 | 55 | | |
| 56 | + | |
44 | 57 | | |
| 58 | + | |
| 59 | + | |
45 | 60 | | |
46 | 61 | | |
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1346 | 1346 | | |
1347 | 1347 | | |
1348 | 1348 | | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
1349 | 1371 | | |
1350 | 1372 | | |
1351 | 1373 | | |
| |||
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
128 | 145 | | |
129 | 146 | | |
130 | 147 | | |
| |||
0 commit comments