PHPackages                             amine-lejmi/messenger-maker - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. amine-lejmi/messenger-maker

ActiveSymfony-bundle[CLI &amp; Console](/categories/cli)

amine-lejmi/messenger-maker
===========================

Separate and enhance the creation of symfony messenger queries, events and commands messages.

v1.0.1(1y ago)21.1kMITPHPPHP &gt;=7.2.5

Since Jul 15Pushed 1y ago1 watchersCompare

[ Source](https://github.com/aminelejmi/MessengerMaker)[ Packagist](https://packagist.org/packages/amine-lejmi/messenger-maker)[ RSS](/packages/amine-lejmi-messenger-maker/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (3)Used By (0)

AmineLejmi/MessengerMaker
=========================

[](#aminelejmimessengermaker)

**The MessengerMaker** is a Symfony bundle that simplifies the creation and registration of messages, distinctly separating queries, commands, and events.

### Key Features:

[](#key-features)

- **Automated Message Creation:** Effortlessly creates and segregates queries, events, and commands.
- **Input and Getter Generation:** Automatically generates inputs and getter methods for messages.
- **Bus Registration:** Seamlessly registers messages in the specified message transport.

This bundle adds a layer on top of Symfony/Messenger, leveraging its configuration. For more details, please refer to the [Symfony Messenger Component documentation](https://symfony.com/doc/current/components/messenger.html).

Installation
============

[](#installation)

Make sure Composer is installed globally, as explained in the [installation chapter](https://getcomposer.org/doc/00-intro.md)of the Composer documentation.

Applications that use Symfony Flex
----------------------------------

[](#applications-that-use-symfony-flex)

Open a command console, enter your project directory and execute:

```
composer require amine-lejmi/messenger-maker
```

Applications that don't use Symfony Flex
----------------------------------------

[](#applications-that-dont-use-symfony-flex)

### Step 1: Download the Bundle

[](#step-1-download-the-bundle)

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

```
composer require amine-lejmi/messenger-maker
```

### Step 2: Enable the Bundle

[](#step-2-enable-the-bundle)

Then, enable the bundle by adding it to the list of registered bundles in the `config/bundles.php` file of your project:

```
// config/bundles.php

return [
    // ...
    AmineLejmi\MessengerMaker\MessengerMakerBundle::class => ['all' => true],
];
```

After Installation
==================

[](#after-installation)

To use the provided interfaces for automatically registering messages in their corresponding buses, add the following lines to your config/services.yaml file:

```
services:
  # ...
  _instanceof:
    AmineLejmi\MessengerMaker\Contract\CommandHandlerInterface:
      tags:
        - { name: messenger.message_handler, bus: command.bus }
    AmineLejmi\MessengerMaker\Contract\EventHandlerInterface:
      tags:
        - { name: messenger.message_handler, bus: event.bus }
    AmineLejmi\MessengerMaker\Contract\QueryHandlerInterface:
      tags:
        - { name: messenger.message_handler, bus: query.bus }
```

**Note :** You can only add the interfaces you need in your project.

Usage
=====

[](#usage)

The bundle provides three different console commands for creating commands, queries, and events:

### 1- Creating a new command

[](#1--creating-a-new-command)

```
php bin/console make:messenger:command
```

**Note:** The `` must end with "Command".

### 2- Creating a new query

[](#2--creating-a-new-query)

```
php bin/console make:messenger:query
```

**Note:** The `` must end with "Query".

### 3- Creating a new event

[](#3--creating-a-new-event)

```
php bin/console make:messenger:event
```

**Note:** The `` must end with "Event".

How It Works
------------

[](#how-it-works)

### Executing the command

[](#executing-the-command)

For each of these commands, the console will prompt you:

1. to choose the corresponding transport if configured in `config/messenger.yaml`:

```
$ php bin/console make:messenger:command SendEmailCommand

 Register this command as : [none]:
  [0] none
  [1] low-priority
  [2] high-priority
 >
```

**Note:** After choosing a transport, the bundle will automatically register the message in routing section inside `config/packages/messenger.yaml`

```
framework:
  # ...
  messenger:
    # ...
    routing:
        # ...
        App\Messenger\Command\SendEmailCommand: low-priority
        # ...
```

2. To add Any additional inputs required for the specific message

```
New property name (press  to stop adding fields):
>

Field type (enter ? to see all types) [string]:
>

Can this field be null (nullable) (yes/no) [no]:
>
```

Follow the prompts to complete the creation of the command, query, or event.

### Creation of the files

[](#creation-of-the-files)

Depending on which command you executed, those folders will be created containing the corresponding files:

```
📦project_dir
 ┣ 📂...
 ┣ 📂 src
 ┃ ┗ 📂 Messenger
 ┃    ┗ 📂 Command
 ┃    ┗ 📂 CommandHandler
 ┃    ┗ 📂 Event
 ┃    ┗ 📂 EventHandler
 ┃    ┗ 📂 Query
 ┃    ┗ 📂 QueryHandler

```

**Note:** : Handlers implement interfaces to allow them to be dispatched to the corresponding bus:

- query.bus
- event.bus
- command.bus

### Examples

[](#examples)

```
