21
21
use Symfony \Component \Console \Input \InputOption ;
22
22
use Symfony \Component \Console \Output \OutputInterface ;
23
23
use Symfony \Component \Console \Style \SymfonyStyle ;
24
+ use Symfony \Component \DependencyInjection \Attribute \Target ;
24
25
use Symfony \Component \HttpKernel \Debug \FileLinkFormatter ;
25
26
26
27
/**
@@ -86,6 +87,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
86
87
}
87
88
}
88
89
90
+ $ reverseAliases = [];
91
+
92
+ foreach ($ container ->getAliases () as $ id => $ alias ) {
93
+ if ('. ' === ($ id [0 ] ?? null )) {
94
+ $ reverseAliases [(string ) $ alias ][] = $ id ;
95
+ }
96
+ }
97
+
89
98
uasort ($ serviceIds , 'strnatcmp ' );
90
99
91
100
$ io ->title ('Autowirable Types ' );
@@ -103,30 +112,47 @@ protected function execute(InputInterface $input, OutputInterface $output): int
103
112
}
104
113
$ text = [];
105
114
$ resolvedServiceId = $ serviceId ;
106
- if (!str_starts_with ($ serviceId , $ previousId )) {
115
+ if (!str_starts_with ($ serviceId , $ previousId. ' $ ' )) {
107
116
$ text [] = '' ;
108
- if ('' !== $ description = Descriptor::getClassDescription ($ serviceId , $ resolvedServiceId )) {
109
- if (isset ($ hasAlias [$ serviceId ])) {
117
+ $ previousId = preg_replace ('/ \$.*/ ' , '' , $ serviceId );
118
+ if ('' !== $ description = Descriptor::getClassDescription ($ previousId , $ resolvedServiceId )) {
119
+ if (isset ($ hasAlias [$ previousId ])) {
110
120
continue ;
111
121
}
112
122
$ text [] = $ description ;
113
123
}
114
- $ previousId = $ serviceId .' $ ' ;
115
124
}
116
125
117
126
$ serviceLine = sprintf ('<fg=yellow>%s</> ' , $ serviceId );
118
- if ($ this ->supportsHref && '' !== $ fileLink = $ this ->getFileLink ($ serviceId )) {
119
- $ serviceLine = sprintf ('<fg=yellow;href=%s>%s</> ' , $ fileLink , $ serviceId );
127
+ if ($ this ->supportsHref && '' !== $ fileLink = $ this ->getFileLink ($ previousId )) {
128
+ $ serviceLine = substr ($ serviceId , \strlen ($ previousId ));
129
+ $ serviceLine = sprintf ('<fg=yellow;href=%s>%s</> ' , $ fileLink , $ previousId ).('' !== $ serviceLine ? sprintf ('<fg=yellow>%s</> ' , $ serviceLine ) : '' );
120
130
}
121
131
122
132
if ($ container ->hasAlias ($ serviceId )) {
123
133
$ hasAlias [$ serviceId ] = true ;
124
134
$ serviceAlias = $ container ->getAlias ($ serviceId );
135
+ $ alias = (string ) $ serviceAlias ;
136
+
137
+ $ target = null ;
138
+ foreach ($ reverseAliases [(string ) $ serviceAlias ] ?? [] as $ id ) {
139
+ if (!str_starts_with ($ id , '. ' .$ previousId .' $ ' )) {
140
+ continue ;
141
+ }
142
+ $ target = substr ($ id , \strlen ($ previousId ) + 3 );
143
+
144
+ if ($ previousId .' $ ' .(new Target ($ target ))->getParsedName () === $ serviceId ) {
145
+ $ serviceLine .= ' - <fg=magenta>target:</><fg=cyan> ' .$ target .'</> ' ;
146
+ break ;
147
+ }
148
+ }
125
149
126
150
if ($ container ->hasDefinition ($ serviceAlias ) && $ decorated = $ container ->getDefinition ($ serviceAlias )->getTag ('container.decorator ' )) {
127
- $ serviceLine .= ' <fg=cyan>( ' .$ decorated [0 ]['id ' ].')</> ' ;
128
- } else {
129
- $ serviceLine .= ' <fg=cyan>( ' .$ serviceAlias .')</> ' ;
151
+ $ alias = $ decorated [0 ]['id ' ];
152
+ }
153
+
154
+ if ($ alias !== $ target ) {
155
+ $ serviceLine .= ' - <fg=magenta>alias:</><fg=cyan> ' .$ alias .'</> ' ;
130
156
}
131
157
132
158
if ($ serviceAlias ->isDeprecated ()) {
0 commit comments