amine-lejmi/messenger-maker
Composer 安装命令:
composer require amine-lejmi/messenger-maker
包简介
Separate and enhance the creation of symfony messenger queries, events and commands messages.
关键字:
README 文档
README
The MessengerMaker is a Symfony bundle that simplifies the creation and registration of messages, distinctly separating queries, commands, and events.
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.
Installation
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
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
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
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
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
The bundle provides three different console commands for creating commands, queries, and events:
1- Creating a new command
php bin/console make:messenger:command <command-name>
Note: The <command-name> must end with "Command".
2- Creating a new query
php bin/console make:messenger:query <query-name>
Note: The <query-name> must end with "Query".
3- Creating a new event
php bin/console make:messenger:event <event-name>
Note: The <event-name> must end with "Event".
How It Works
Executing the command
For each of these commands, the console will prompt you:
- 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 # ...
- To add Any additional inputs required for the specific message
New property name (press <return> 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
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
<?php namespace App\Messenger\Command; class SendEmailCommand { private string $address; private ?string $message; public function __construct(string $address, ?string $message) { $this->address = $address; $this->message = $message; } public function getAddress(): string { return $this->address; } public function getMessage(): ?string { return $this->message; } }
<?php namespace App\Messenger\CommandHandler; use AmineLejmi\MessengerMaker\Contract\CommandHandlerInterface; use App\Messenger\Command\SendEmailCommand; class SendEmailCommandHandler implements CommandHandlerInterface { public function __construct() { } public function __invoke(SendEmailCommand $command) { $address = $command->getAddress(); $message = $command->getMessage(); // Do something with your variables } }
amine-lejmi/messenger-maker 适用场景与选型建议
amine-lejmi/messenger-maker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.1k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 07 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「console」 「make」 「Messenger」 「cqrs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 amine-lejmi/messenger-maker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 amine-lejmi/messenger-maker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 amine-lejmi/messenger-maker 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This class provides you with an easy-to-use interface to progress bars.
A Laravel package to retrieve data from Google Search Console
Additional artisan commands for Laravel
The bundle for easy using json-rpc api on your project
Laravel Artisan Command To Generate Facades (php artisan make generator now execpts facade Facadename)
A table generator class for the PHP CLI.
统计信息
- 总下载量: 1.1k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-15