Skip to content

Commit 42e9c24

Browse files
committed
AutowiredService - support named services
1 parent 536d2f1 commit 42e9c24

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

conf/config.neon

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -983,9 +983,6 @@ services:
983983
autowired:
984984
- PHPStan\Command\ErrorFormatter\CiDetectedErrorFormatter
985985

986-
errorFormatter.raw:
987-
class: PHPStan\Command\ErrorFormatter\RawErrorFormatter
988-
989986
errorFormatter.table:
990987
class: PHPStan\Command\ErrorFormatter\TableErrorFormatter
991988
arguments:

src/Command/ErrorFormatter/RawErrorFormatter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
use PHPStan\Command\AnalysisResult;
66
use PHPStan\Command\Output;
7+
use PHPStan\DependencyInjection\AutowiredService;
78
use function sprintf;
89

10+
#[AutowiredService(name: 'errorFormatter.raw')]
911
final class RawErrorFormatter implements ErrorFormatter
1012
{
1113

src/DependencyInjection/AutowiredAttributeServicesExtension.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ public function loadConfiguration(): void
1717

1818
foreach ($autowiredServiceClasses as $class) {
1919
$reflection = new ReflectionClass($class->name);
20+
$attribute = $class->attribute;
2021

21-
$definition = $builder->addDefinition(null)
22+
$definition = $builder->addDefinition($attribute->name)
2223
->setType($class->name)
2324
->setAutowired();
2425

src/DependencyInjection/AutowiredService.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@
1616
final class AutowiredService
1717
{
1818

19+
public function __construct(public ?string $name = null)
20+
{
21+
}
22+
1923
}

0 commit comments

Comments
 (0)