@@ -22,15 +22,18 @@ class TranslatorPathsPass extends AbstractRecursivePass
22
22
private $ translatorServiceId ;
23
23
private $ debugCommandServiceId ;
24
24
private $ updateCommandServiceId ;
25
+ private $ resolverServiceId ;
25
26
private $ level = 0 ;
26
27
private $ paths = array ();
27
28
private $ definitions = array ();
29
+ private $ controllers = array ();
28
30
29
- public function __construct (string $ translatorServiceId = 'translator ' , string $ debugCommandServiceId = 'console.command.translation_debug ' , string $ updateCommandServiceId = 'console.command.translation_update ' )
31
+ public function __construct (string $ translatorServiceId = 'translator ' , string $ debugCommandServiceId = 'console.command.translation_debug ' , string $ updateCommandServiceId = 'console.command.translation_update ' , string $ resolverServiceId = ' argument_resolver.service ' )
30
32
{
31
33
$ this ->translatorServiceId = $ translatorServiceId ;
32
34
$ this ->debugCommandServiceId = $ debugCommandServiceId ;
33
35
$ this ->updateCommandServiceId = $ updateCommandServiceId ;
36
+ $ this ->resolverServiceId = $ resolverServiceId ;
34
37
}
35
38
36
39
public function process (ContainerBuilder $ container )
@@ -39,21 +42,37 @@ public function process(ContainerBuilder $container)
39
42
return ;
40
43
}
41
44
45
+ $ controllerLocator = array ();
46
+ if ($ container ->hasDefinition ($ this ->resolverServiceId )) {
47
+ $ controllerLocator = $ container ->getDefinition ($ this ->resolverServiceId )->getArgument (0 )->getArgument (0 );
48
+ } elseif ($ container ->hasDefinition ('debug. ' .$ this ->resolverServiceId )) {
49
+ $ controllerLocator = $ container ->getDefinition ('debug. ' .$ this ->resolverServiceId )->getArgument (0 )->getArgument (0 )->getArgument (0 );
50
+ }
51
+ foreach ($ controllerLocator as $ controller => $ argument ) {
52
+ list ($ ref ) = $ argument ->getValues ();
53
+ $ this ->controllers [(string ) $ ref ][substr ($ controller , 0 , strpos ($ controller , ': ' ))] = true ;
54
+ }
55
+
42
56
try {
43
57
parent ::process ($ container );
44
58
45
- if (!$ this ->paths ) {
59
+ $ paths = array ();
60
+ foreach ($ this ->paths as $ class => $ _ ) {
61
+ if (($ r = $ container ->getReflectionClass ($ class )) && !$ r ->isInterface ()) {
62
+ $ paths [] = $ r ->getFileName ();
63
+ }
64
+ }
65
+ if (!$ paths ) {
46
66
return ;
47
67
}
48
- $ this ->paths = array_values ($ this ->paths );
49
68
50
69
if ($ container ->hasDefinition ($ this ->debugCommandServiceId )) {
51
70
$ definition = $ container ->getDefinition ($ this ->debugCommandServiceId );
52
- $ definition ->replaceArgument (6 , array_merge ($ definition ->getArgument (6 ), $ this -> paths ));
71
+ $ definition ->replaceArgument (6 , array_merge ($ definition ->getArgument (6 ), $ paths ));
53
72
}
54
73
if ($ container ->hasDefinition ($ this ->updateCommandServiceId )) {
55
74
$ definition = $ container ->getDefinition ($ this ->updateCommandServiceId );
56
- $ definition ->replaceArgument (7 , array_merge ($ definition ->getArgument (7 ), $ this -> paths ));
75
+ $ definition ->replaceArgument (7 , array_merge ($ definition ->getArgument (7 ), $ paths ));
57
76
}
58
77
} finally {
59
78
$ this ->level = 0 ;
@@ -67,11 +86,17 @@ protected function processValue($value, $isRoot = false)
67
86
if ($ value instanceof Reference) {
68
87
if ((string ) $ value === $ this ->translatorServiceId ) {
69
88
for ($ i = $ this ->level - 1 ; $ i >= 0 ; --$ i ) {
70
- if (ServiceLocator::class === $ class = $ this ->definitions [$ i ]->getClass ()) {
71
- continue ;
72
- }
73
- if (!isset ($ this ->paths [$ class ]) && ($ r = $ this ->container ->getReflectionClass ($ class , false )) && !$ r ->isInterface ()) {
74
- $ this ->paths [$ class ] = $ r ->getFileName ();
89
+ $ class = $ this ->definitions [$ i ]->getClass ();
90
+
91
+ if (ServiceLocator::class === $ class ) {
92
+ if (!isset ($ this ->controllers [$ this ->currentId ])) {
93
+ continue ;
94
+ }
95
+ foreach ($ this ->controllers [$ this ->currentId ] as $ class => $ _ ) {
96
+ $ this ->paths [$ class ] = true ;
97
+ }
98
+ } else {
99
+ $ this ->paths [$ class ] = true ;
75
100
}
76
101
77
102
break ;
0 commit comments