Skip to content
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

[Messenger] Compile-time errors fixes and tweaks #26672

Merged
merged 1 commit into from
Mar 29, 2018

Conversation

chalasr
Copy link
Member

@chalasr 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

@chalasr chalasr added this to the 4.1 milestone Mar 26, 2018
@chalasr chalasr force-pushed the messenger-compile-errors branch 2 times, most recently from 0d569f6 to 51c66c6 Compare March 26, 2018 09:28
}

return $parameter->getClass()->getName();
Copy link
Member Author

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));
Copy link
Member Author

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

} 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()));
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 done

$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()) {
Copy link
Member

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)

fabpot added a commit that referenced this pull request Mar 27, 2018
…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')
Copy link
Contributor

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?

@chalasr chalasr force-pushed the messenger-compile-errors branch 2 times, most recently from 574ef49 to ed9ef9d Compare March 27, 2018 10:18
@chalasr
Copy link
Member Author

chalasr commented Mar 27, 2018

@sroze @stof comments addressed

@@ -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);
Copy link
Member

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()).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@chalasr
Copy link
Member Author

chalasr commented Mar 29, 2018

ready

@sroze
Copy link
Contributor

sroze commented Mar 29, 2018

I'm happy with it. @stof & @fabpot could you amend your reviews?

}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
Copy link
Contributor

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.

Copy link
Member Author

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

@fabpot
Copy link
Member

fabpot commented Mar 29, 2018

Thank you @chalasr.

@fabpot fabpot merged commit 2889acf into symfony:master Mar 29, 2018
fabpot added a commit that referenced this pull request Mar 29, 2018
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
@chalasr chalasr deleted the messenger-compile-errors branch March 29, 2018 21:15
symfony-splitter pushed a commit to symfony/messenger that referenced this pull request Apr 3, 2018
…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)
symfony-splitter pushed a commit to symfony/framework-bundle that referenced this pull request Apr 3, 2018
…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)
sroze added a commit that referenced this pull request Apr 3, 2018
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants