You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Fix invalid callables dumped for ArgumentInterface objects
| Q | A
| ------------- | ---
| Branch? | 3.3
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | ~
| License | MIT
| Doc PR | ~
Follow up of symfony#22511, from @iltar:
> Currently, when having a service definition which has more than 1 usage of that service, it will put the argument in `$a` for example. By doing so, it will also use `$a` in the callable of the `ServiceLocator`, which result in an undefined variable `$a`.
> I managed to trigger this with the translator service, where I have my own loader, that I add for NL and EN, causing 2 method calls to turn the direct getter into a variable. I've added 2 test cases, 1 with only 1 method call and 1 with 2 method calls.
Commits
-------
f81c577 [DI] Test references inside ServiceLocator are not inlined
8783602 [DI] Fix invalid callables dumped for ArgumentInterface objects
thrownewInvalidArgumentException(sprintf('A ClosureProxyArgument must hold a Reference, "%s" given.', is_object($values[0]) ? get_class($values[0]) : gettype($values[0])));
thrownewRuntimeException(sprintf('Cannot dump definition for service "%s": dynamic class names or methods, and closure-proxies are incompatible with each other.', $reference));
1469
+
}
1470
+
if (!method_exists($class, $method)) {
1471
+
thrownewInvalidArgumentException(sprintf('Cannot create closure-proxy for service "%s": method "%s::%s" does not exist.', $reference, $class, $method));
thrownewInvalidArgumentException(sprintf('Cannot create closure-proxy for service "%s": method "%s::%s" must be public.', $reference, $class, $method));
thrownewRuntimeException(sprintf('Cannot dump definition for service "%s": dynamic class names or methods, and closure-proxies are incompatible with each other.', $reference));
1513
-
}
1514
-
if (!method_exists($class, $method)) {
1515
-
thrownewInvalidArgumentException(sprintf('Cannot create closure-proxy for service "%s": method "%s::%s" does not exist.', $reference, $class, $method));
thrownewInvalidArgumentException(sprintf('Cannot create closure-proxy for service "%s": method "%s::%s" must be public.', $reference, $class, $method));
@@ -97,6 +103,101 @@ protected function getFooServiceService()
97
103
}));
98
104
}
99
105
106
+
/**
107
+
* Gets the 'translator.loader_1' service.
108
+
*
109
+
* This service is shared.
110
+
* This method always returns the same instance of the service.
111
+
*
112
+
* @return \stdClass A stdClass instance
113
+
*/
114
+
protectedfunctiongetTranslator_Loader1Service()
115
+
{
116
+
return$this->services['translator.loader_1'] = new \stdClass();
117
+
}
118
+
119
+
/**
120
+
* Gets the 'translator.loader_2' service.
121
+
*
122
+
* This service is shared.
123
+
* This method always returns the same instance of the service.
124
+
*
125
+
* @return \stdClass A stdClass instance
126
+
*/
127
+
protectedfunctiongetTranslator_Loader2Service()
128
+
{
129
+
return$this->services['translator.loader_2'] = new \stdClass();
130
+
}
131
+
132
+
/**
133
+
* Gets the 'translator.loader_3' service.
134
+
*
135
+
* This service is shared.
136
+
* This method always returns the same instance of the service.
137
+
*
138
+
* @return \stdClass A stdClass instance
139
+
*/
140
+
protectedfunctiongetTranslator_Loader3Service()
141
+
{
142
+
return$this->services['translator.loader_3'] = new \stdClass();
143
+
}
144
+
145
+
/**
146
+
* Gets the 'translator_1' service.
147
+
*
148
+
* This service is shared.
149
+
* This method always returns the same instance of the service.
150
+
*
151
+
* @return \Symfony\Component\DependencyInjection\Tests\Fixtures\StubbedTranslator A Symfony\Component\DependencyInjection\Tests\Fixtures\StubbedTranslator instance
152
+
*/
153
+
protectedfunctiongetTranslator1Service()
154
+
{
155
+
return$this->services['translator_1'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\StubbedTranslator(new \Symfony\Component\DependencyInjection\ServiceLocator(array('translator.loader_1' => function () {
0 commit comments