-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Messenger] Compile-time errors fixes and tweaks #26672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
chalasr
commented
Mar 26, 2018
Q | A |
---|---|
Branch? | master |
Bug fix? | no (master only) |
New feature? | no |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | n/a |
License | MIT |
Doc PR | n/a |
0d569f6
to
51c66c6
Compare
} | ||
|
||
return $parameter->getClass()->getName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getClass()
breaks if the class does not exist (ReflectionException
)
|
||
throw new RuntimeException(sprintf('The message class "%s" %s of service "%s" does not exist.', $messageClassLocation, $handles, $serviceId)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad argument ordering in sprintf
51c66c6
to
37bcfea
Compare
} catch (\ReflectionException $e) { | ||
throw new RuntimeException(sprintf('Service "%s" should have an `__invoke` function.', $serviceId)); | ||
throw new RuntimeException(sprintf('Invalid service "%s": class "%s" must have an "__invoke()" method.', $serviceId, $handlerClass->getName())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about replacing all the "Invalid service" by "Invalid handler service" to clarify why it requires such method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 done
37bcfea
to
f30d857
Compare
$parameter = $parameters[0]; | ||
if (null === $parameter->getClass()) { | ||
throw new RuntimeException(sprintf('The parameter of `__invoke` function of service "%s" must type hint the message class it handles.', $serviceId)); | ||
if (!$parameters[0]->hasType()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should also report the issue if it has a builtin type as typehint (i.e. not a class)
…tead of `message.handler` (sroze) This PR was merged into the 4.1-dev branch. Discussion ---------- [Messenger] Uses the `messenger.message_handler` tag instead of `message.handler` | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no (technically, it's not even in 4.1) | Deprecations? | no | Tests pass? | yes | Fixed tickets | ø | License | MIT After a few days using it, it feels weird to have the `messenger.receiver` and `messenger.sender` tags while the one for message handlers is `message_handler`. I believe that for consistency, this would make sense to rename this tag `messenger.message_handler`. As we don't have tests for this pass yet (will be added in #26672) there is nothing else to change (but the documentation). Commits ------- bddebc4 Uses the `messenger.message_handler` tag instead of `message.handler`
$container = $this->getContainerBuilder(); | ||
$container | ||
->register(MissingArgumentHandler::class, MissingArgumentHandler::class) | ||
->addTag('message_handler') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tag has changed and is now messenger.message_handler
. Could you rebase this PR on master and update the tests?
574ef49
to
ed9ef9d
Compare
@@ -67,12 +67,12 @@ private function registerHandlers(ContainerBuilder $container) | |||
|
|||
foreach ($container->findTaggedServiceIds($this->handlerTag, true) as $serviceId => $tags) { | |||
foreach ($tags as $tag) { | |||
$handles = $tag['handles'] ?? $this->guessHandledClass($container, $serviceId); | |||
$handles = $tag['handles'] ?? $this->guessHandledClass($r = $container->getReflectionClass($container->getDefinition($serviceId)->getClass()), $serviceId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class in the definition can be a parameter like %some_class_name%
, you should resolve it here (via $container->getParameterBag()->resolveValue()
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
ed9ef9d
to
2889acf
Compare
ready |
} | ||
|
||
/** | ||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what's our stance on this, but phpunit advices to use method calls instead of annotations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for now we use annotations everywhere, perhaps it should be rediscussed on 2.7
Thank you @chalasr. |
This PR was merged into the 4.1-dev branch. Discussion ---------- [Messenger] Compile-time errors fixes and tweaks | Q | A | ------------- | --- | Branch? | master | Bug fix? | no (master only) | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Commits ------- 2889acf [Messenger] Compile time errors fixes and tweaks
…messages + auto-configuration) (sroze) This PR was squashed before being merged into the 4.1-dev branch (closes #26685). Discussion ---------- [Messenger] Add a `MessageHandlerInterface` (multiple messages + auto-configuration) | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | ø | License | MIT | Doc PR | ø Based on @chalasr's PR: symfony/symfony#26672. This reduces the hassle of registering handlers: it allows the auto-configuration with a new interface `HandlerInterface`. At the same time, it allows a handler to handle multiple messages. Commits ------- 07e6bc73a3 [Messenger] Add a `MessageHandlerInterface` (multiple messages + auto-configuration)
…messages + auto-configuration) (sroze) This PR was squashed before being merged into the 4.1-dev branch (closes #26685). Discussion ---------- [Messenger] Add a `MessageHandlerInterface` (multiple messages + auto-configuration) | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | ø | License | MIT | Doc PR | ø Based on @chalasr's PR: symfony/symfony#26672. This reduces the hassle of registering handlers: it allows the auto-configuration with a new interface `HandlerInterface`. At the same time, it allows a handler to handle multiple messages. Commits ------- 07e6bc73a3 [Messenger] Add a `MessageHandlerInterface` (multiple messages + auto-configuration)
…messages + auto-configuration) (sroze) This PR was squashed before being merged into the 4.1-dev branch (closes #26685). Discussion ---------- [Messenger] Add a `MessageHandlerInterface` (multiple messages + auto-configuration) | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | ø | License | MIT | Doc PR | ø Based on @chalasr's PR: #26672. This reduces the hassle of registering handlers: it allows the auto-configuration with a new interface `HandlerInterface`. At the same time, it allows a handler to handle multiple messages. Commits ------- 07e6bc7 [Messenger] Add a `MessageHandlerInterface` (multiple messages + auto-configuration)