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 #44971 [Messenger] Resolve handled classes when only method in tag is provided (angelov)
This PR was squashed before being merged into the 6.1 branch.
Discussion
----------
[Messenger] Resolve handled classes when only method in tag is provided
| Q | A
| ------------- | ---
| Branch? | 6.1
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Tickets | /
| License | MIT
| Doc PR | /
When tagging Messenger handlers, if the `method` attribute is set, the compiler pass does not resolve the message type before handling it - it requires the `handles` attribute to be set as well.
With this PR, the message type is being resolved even if method other than `__invoke` is being used.
I'm not sure if this is a bug fix or just an improvement :/
Commits
-------
780b7da [Messenger] Resolve handled classes when only method in tag is provided
thrownewRuntimeException(sprintf('Invalid handler service "%s": class "%s" must have an "__invoke()" method.', $serviceId, $handlerClass->getName()));
209
+
thrownewRuntimeException(sprintf('Invalid handler service "%s": class "%s" must have an "%s()" method.', $serviceId, $handlerClass->getName(), $methodName));
210
210
}
211
211
212
212
if (0 === $method->getNumberOfRequiredParameters()) {
213
-
thrownewRuntimeException(sprintf('Invalid handler service "%s": method "%s::__invoke()" requires at least one argument, first one being the message it handles.', $serviceId, $handlerClass->getName()));
213
+
thrownewRuntimeException(sprintf('Invalid handler service "%s": method "%s::%s()" requires at least one argument, first one being the message it handles.', $serviceId, $handlerClass->getName(), $methodName));
214
214
}
215
215
216
216
$parameters = $method->getParameters();
217
-
if (!$type = $parameters[0]->getType()) {
218
-
thrownewRuntimeException(sprintf('Invalid handler service "%s": argument "$%s" of method "%s::__invoke()" must have a type-hint corresponding to the message class it handles.', $serviceId, $parameters[0]->getName(), $handlerClass->getName()));
thrownewRuntimeException(sprintf('Invalid handler service "%s": argument "$%s" of method "%s::%s()" must have a type-hint corresponding to the message class it handles.', $serviceId, $parameters[0]->getName(), $handlerClass->getName(), $methodName));
219
223
}
220
224
221
225
if ($typeinstanceof \ReflectionUnionType) {
@@ -232,10 +236,10 @@ private function guessHandledClasses(\ReflectionClass $handlerClass, string $ser
232
236
}
233
237
234
238
if ($type->isBuiltin()) {
235
-
thrownewRuntimeException(sprintf('Invalid handler service "%s": type-hint of argument "$%s" in method "%s::__invoke()" must be a class , "%s" given.', $serviceId, $parameters[0]->getName(), $handlerClass->getName(), $typeinstanceof \ReflectionNamedType ? $type->getName() : (string) $type));
239
+
thrownewRuntimeException(sprintf('Invalid handler service "%s": type-hint of argument "$%s" in method "%s::%s()" must be a class , "%s" given.', $serviceId, $parameters[0]->getName(), $handlerClass->getName(), $methodName, $typeinstanceof \ReflectionNamedType ? $type->getName() : (string) $type));
0 commit comments