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
feature symfony#24301 [DI] Add AutowireRequiredMethodsPass to fix bindings for @required methods (nicolas-grekas)
This PR was merged into the 3.4 branch.
Discussion
----------
[DI] Add AutowireRequiredMethodsPass to fix bindings for `@required` methods
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | yes
| New feature? | yes
| BC breaks? | yes
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Spotted while doing a SF4 workshop :)
Discovery of `@required` methods should be split from AutowirePass so that bindings can apply to these methods also when autowiring is enabled.
Commits
-------
dc55dd2 [DI] Add AutowireRequiredMethodsPass to fix bindings for `@required` methods
@@ -117,14 +117,14 @@ protected function getConstructor(Definition $definition, $required)
117
117
$class = $definition->getClass();
118
118
119
119
if (!$r = $this->container->getReflectionClass($class)) {
120
-
thrownewRuntimeException(sprintf('Unable to resolve service "%s": class "%s" does not exist.', $this->currentId, $class));
120
+
thrownewRuntimeException(sprintf('Invalid service "%s": class "%s" does not exist.', $this->currentId, $class));
121
121
}
122
122
if (!$r = $r->getConstructor()) {
123
123
if ($required) {
124
-
thrownewRuntimeException(sprintf('Unable to resolve service "%s": class%s has no constructor.', $this->currentId, sprintf($class !== $this->currentId ? ' "%s"' : '', $class)));
124
+
thrownewRuntimeException(sprintf('Invalid service "%s": class%s has no constructor.', $this->currentId, sprintf($class !== $this->currentId ? ' "%s"' : '', $class)));
125
125
}
126
126
} elseif (!$r->isPublic()) {
127
-
thrownewRuntimeException(sprintf('Unable to resolve service "%s": %s must be public.', $this->currentId, sprintf($class !== $this->currentId ? 'constructor of class "%s"' : 'its constructor', $class)));
127
+
thrownewRuntimeException(sprintf('Invalid service "%s": %s must be public.', $this->currentId, sprintf($class !== $this->currentId ? 'constructor of class "%s"' : 'its constructor', $class)));
128
128
}
129
129
130
130
return$r;
@@ -145,20 +145,20 @@ protected function getReflectionMethod(Definition $definition, $method)
145
145
}
146
146
147
147
if (!$class = $definition->getClass()) {
148
-
thrownewRuntimeException(sprintf('Unable to resolve service "%s": the class is not set.', $this->currentId));
148
+
thrownewRuntimeException(sprintf('Invalid service "%s": the class is not set.', $this->currentId));
149
149
}
150
150
151
151
if (!$r = $this->container->getReflectionClass($class)) {
152
-
thrownewRuntimeException(sprintf('Unable to resolve service "%s": class "%s" does not exist.', $this->currentId, $class));
152
+
thrownewRuntimeException(sprintf('Invalid service "%s": class "%s" does not exist.', $this->currentId, $class));
153
153
}
154
154
155
155
if (!$r->hasMethod($method)) {
156
-
thrownewRuntimeException(sprintf('Unable to resolve service "%s": method "%s()" does not exist.', $this->currentId, $class !== $this->currentId ? $class.'::'.$method : $method));
156
+
thrownewRuntimeException(sprintf('Invalid service "%s": method "%s()" does not exist.', $this->currentId, $class !== $this->currentId ? $class.'::'.$method : $method));
157
157
}
158
158
159
159
$r = $r->getMethod($method);
160
160
if (!$r->isPublic()) {
161
-
thrownewRuntimeException(sprintf('Unable to resolve service "%s": method "%s()" must be public.', $this->currentId, $class !== $this->currentId ? $class.'::'.$method : $method));
161
+
thrownewRuntimeException(sprintf('Invalid service "%s": method "%s()" must be public.', $this->currentId, $class !== $this->currentId ? $class.'::'.$method : $method));
Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php
+3-3
Original file line number
Diff line number
Diff line change
@@ -61,11 +61,11 @@ protected function processValue($value, $isRoot = false)
61
61
}
62
62
}
63
63
64
-
thrownewInvalidArgumentException(sprintf('Unable to resolve service "%s": method "%s()" has no argument named "%s". Check your service definition.', $this->currentId, $class !== $this->currentId ? $class.'::'.$method : $method, $key));
64
+
thrownewInvalidArgumentException(sprintf('Invalid service "%s": method "%s()" has no argument named "%s". Check your service definition.', $this->currentId, $class !== $this->currentId ? $class.'::'.$method : $method, $key));
thrownewInvalidArgumentException(sprintf('Unable to resolve service "%s": the value of argument "%s" of method "%s()" must be null, an instance of %s or an instance of %s, %s given.', $this->currentId, $key, $class !== $this->currentId ? $class.'::'.$method : $method, Reference::class, Definition::class, gettype($argument)));
68
+
thrownewInvalidArgumentException(sprintf('Invalid service "%s": the value of argument "%s" of method "%s()" must be null, an instance of %s or an instance of %s, %s given.', $this->currentId, $key, $class !== $this->currentId ? $class.'::'.$method : $method, Reference::class, Definition::class, gettype($argument)));
69
69
}
70
70
71
71
foreach ($parametersas$j => $p) {
@@ -76,7 +76,7 @@ protected function processValue($value, $isRoot = false)
76
76
}
77
77
}
78
78
79
-
thrownewInvalidArgumentException(sprintf('Unable to resolve service "%s": method "%s()" has no argument type-hinted as "%s". Check your service definition.', $this->currentId, $class !== $this->currentId ? $class.'::'.$method : $method, $key));
79
+
thrownewInvalidArgumentException(sprintf('Invalid service "%s": method "%s()" has no argument type-hinted as "%s". Check your service definition.', $this->currentId, $class !== $this->currentId ? $class.'::'.$method : $method, $key));
0 commit comments