This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
Samuel ROZE 7497ad4a68 feature #27275 [Messenger] Allow to scope handlers per bus (ogizanagi, sroze)
This PR was merged into the 4.1 branch.

Discussion
----------

[Messenger] Allow to scope handlers per bus

| Q             | A
| ------------- | ---
| Branch?       | 4.1 <!-- see below -->
| Bug fix?      | no
| New feature?  | yes <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | N/A   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | todo

<img width="970" alt="screenshot 2018-05-15 a 18 34 11" src="https://user-images.githubusercontent.com/2211145/40070551-b36d1f50-586e-11e8-8a44-c6a1503312dd.PNG">

This prevents from dispatching a message in the wrong bus. It works especially great with PSR-4 discovery in DI:

```yaml
command_handlers:
    namespace: App\Message\
    resource: '%kernel.project_dir%/src/Message/*CommandHandler.php'
    tags:
        - { name: messenger.message_handler, bus: command_bus }

query_handlers:
    namespace: App\Message\
    resource: '%kernel.project_dir%/src/Message/*QueryHandler.php'
    tags:
        - { name: messenger.message_handler, bus: query_bus }
```

<details>

<summary>(or in some layered architecture)</summary>

```yaml
command_handlers:
    namespace: App\Application\
    resource: '%kernel.project_dir%/src/Application/**/Handler/*CommandHandler.php'
    tags:
        - { name: messenger.message_handler, bus: command_bus }

query_handlers:
    namespace: App\Application\
    resource: '%kernel.project_dir%/src/Application/**/Handler/*QueryHandler.php'
    tags:
        - { name: messenger.message_handler, bus: query_bus }
```

</details>

---
It also updates (and add tests for) the `DebugCommand`, so we can inspect easily where is supposed to be handled each message.
It's totally optional, and if the bus isn't provided, then it stays available in every bus.

Commits
-------

fd810cdee0 Uses `protected` for test functions
9d658e915e [Messenger] Allow to scope handlers per bus
2018-05-20 10:49:44 +01:00
.composer Drop hirak/prestissimo 2016-05-12 07:44:15 -05:00
.github minor #27079 Added .github/CODEOWNERS (lyrixx) 2018-04-30 12:11:06 -07:00
src/Symfony Uses protected for test functions 2018-05-20 10:26:34 +01:00
.editorconfig Add EditorConfig File 2012-06-16 14:08:15 +02:00
.gitignore Add appveyor.yml for C.I. on Windows 2015-08-25 23:41:37 +02:00
.php_cs.dist [DI] Service decoration: autowire the inner service 2018-03-20 19:23:30 +01:00
.travis.yml [Messenger] Add AMQP adapter 2018-04-12 09:15:52 +01:00
appveyor.yml Merge branch '3.4' into 4.0 2018-04-26 18:12:06 +02:00
CHANGELOG-4.0.md updated CHANGELOG for 4.0.9 2018-04-30 21:45:53 +02:00
CHANGELOG-4.1.md updated CHANGELOG for 4.1.0-BETA1 2018-05-07 17:29:57 +02:00
composer.json Merge branch '4.0' 2018-05-01 16:02:13 -07:00
CONTRIBUTING.md Mention the community review guide 2016-12-18 22:02:35 +01:00
CONTRIBUTORS.md update CONTRIBUTORS for 2.7.46 2018-04-27 07:41:29 +02:00
LICENSE fixed years in copyright 2018-01-03 08:23:28 +01:00
link [DI] Minor performance tweak in PriorityTaggedServiceTrait 2018-05-03 17:03:52 -07:00
phpunit Force phpunit-bridge update (bis) 2017-11-22 10:25:38 +01:00
phpunit.xml.dist [Cache] Rely on mock for Doctrine ArrayCache 2018-03-19 23:12:11 +01:00
README.md Prefer composer install instead for using Symfony Installer 2018-01-10 18:56:50 +01:00
UPGRADE-4.0.md [Form] Fix typo in Upgrade 3.4/4.0 2018-04-06 07:20:49 +02:00
UPGRADE-4.1.md [Workflow] "clear()" instead of "reset()" 2018-04-29 09:31:06 -07:00
UPGRADE-5.0.md [Workflow] "clear()" instead of "reset()" 2018-04-29 09:31:06 -07:00

Symfony is a PHP framework for web applications and a set of reusable PHP components. Symfony is used by thousands of web applications (including BlaBlaCar.com and Spotify.com) and most of the popular PHP projects (including Drupal and Magento).

Installation

Documentation

Community

Contributing

Symfony is an Open Source, community-driven project with thousands of contributors. Join them contributing code or contributing documentation.

Security Issues

If you discover a security vulnerability within Symfony, please follow our disclosure procedure.

About Us

Symfony development is sponsored by SensioLabs, led by the Symfony Core Team and supported by Symfony contributors.