patienceman/custom-handler
Composer 安装命令:
composer require patienceman/custom-handler
包简介
Provide a convenient way creating single action handlers. The idea of a action handler is a single action controller that means a unique class handles each action
README 文档
README
Provide a convenient way creating single action handlers. The idea of a action handler is a single action controller that means a unique class handles each action
Installation
Install the package doesn't require much requirement except to use the following command in the laravel terminal, and you're good to go.
composer require patienceman/custom-handler
Usage
To start working with handler, u need to run command 🎉 in your custom directories:
php artisan make:handler NewStartupHandler
so it will create the filter file for u, Just in
App\Handlers
namespace App\Handlers; use Patienceman\CustomHandler\Handler; class NewStartupHandler extends Handler { /** * Custom execution from Handler Pipeline * @return Exception|void */ public function execute() { // do whatever action inside handler } }
So you may want even to specify the custom path for your Handler, Just relax and add it in front of your Handler name. Let's take again our current example.
php artisan make:handler Model/DatabaseHandler
So far so good, Let see how you can your handlers anywhere in controller or services or ...:
namespace App\Http\Controllers; use App\Handlers\NewStartupHandler; use Patienceman\CustomHandler\CustomHandler; class TestBuilderController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $handler = CustomHandler::handle(new NewStartupHandler()); } }
But don't worry, you chain many handlers as you want, what you need to do is keep add ->handle(), let see it in action:
namespace App\Http\Controllers; use App\Handlers\NewStartupHandler; use App\Handlers\NewCompanyHandler; use Patienceman\CustomHandler\CustomHandler; class TestBuilderController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $handler = CustomHandler::handle(new NewStartupHandler()) ->handle(new NewCompanyHandler()); } }
And now once your controller get execution, all your handler will run.
Exchanges of data
There might a time you need to store and exchange tou data throughout your handlers,
This package provide convinient way to do so, by just use ->collect(array data) to collect data and ->collection() to get collected data, let take example:
In our NewStartupHandler:
namespace App\Handlers; use Patienceman\CustomHandler\Handler; use App\Models\Startup; class NewStartupHandler extends Handler { /** * Custom execution from Handler Pipeline * @return Exception|void */ public function execute() { $startup = Startup::create([ 'name' => "MorganTv" ]); $this->collect([ 'startup' => $startup ]); } }
That look to clear 🎉, so Let see how you can call the collected data anywhere your want, for example in our
NewCompanyHandler class:
namespace App\Handlers; use Patienceman\CustomHandler\Handler; class NewCompanyHandler extends Handler { /** * Custom execution from Handler Pipeline * * @return Exception|void */ public function execute() { $startup = $this->collection()->get('startup'); } }
🚨 You've seen where we are using ->collection() function, and this is coming from Laravel collection, you can read more about it to their website: Laravel collection avalibale method for more about getting and filtering data.
There is also another way to get collected data, for instance when you're outside handler, and to apply this you use same functionality
as ->collection() after your handler, take a look:
namespace App\Http\Controllers; use App\Handlers\NewStartupHandler; use App\Handlers\NewCompanyHandler; use Patienceman\CustomHandler\CustomHandler; class TestBuilderController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $handler = CustomHandler::handle(new NewStartupHandler()) ->handle(new NewCompanyHandler()) ->collection() ->get('startup') // or ->get(), ->filter() ->sort(); } }
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
Connect with Me
patienceman/custom-handler 适用场景与选型建议
patienceman/custom-handler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.72k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 05 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「laravel」 「handlers」 「custom-handler」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 patienceman/custom-handler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 patienceman/custom-handler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 patienceman/custom-handler 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Use Monolog to log data to files/databases/notifications/...
Handler discovery and management, for CodeIgniter 4
MvcCore - Extension - Debug - Tracy - Panel MvcCore - render and add into tracy debug panel current MvcCore application instance, printed by \Tracy\Dumper::toHtml(\MvcCore\Application::GetInstance()); to display main application objects used to render current page response. Rendered objects inside M
MessengerRouting – is a Command Router for messengers, like Telegram and Others. Php8 command handler attributes.
Alfabank REST API integration
The Opulence debug library
统计信息
- 总下载量: 2.72k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-04