lorisleiva/laravel-actions
Composer 安装命令:
composer require lorisleiva/laravel-actions
包简介
Laravel components that take care of one specific task
README 文档
README
⚡ Classes that take care of one specific task.
This package introduces a new way of organising the logic of your Laravel applications by focusing on the actions your applications provide.
Instead of creating controllers, jobs, listeners and so on, it allows you to create a PHP class that handles a specific task and run that class as anything you want.
Therefore it encourages you to switch your focus from:
"What controllers do I need?", "should I make a FormRequest for this?", "should this run asynchronously in a job instead?", etc.
to:
"What does my application actually do?"
Installation
composer require lorisleiva/laravel-actions
Documentation
📚 Read the full documentation at laravelactions.com
Basic usage
Create your first action using php artisan make:action PublishANewArticle and define the asX methods when you want your action to be running as X. E.g. asController, asJob, asListener and/or asCommand.
class PublishANewArticle { use AsAction; public function handle(User $author, string $title, string $body): Article { return $author->articles()->create([ 'title' => $title, 'body' => $body, ]); } public function asController(Request $request): ArticleResource { $article = $this->handle( $request->user(), $request->get('title'), $request->get('body'), ); return new ArticleResource($article); } public function asListener(NewProductReleased $event): void { $this->handle( $event->product->manager, $event->product->name . ' Released!', $event->product->description, ); } }
As an object
Now, you can run your action as an object by using the run method like so:
PublishANewArticle::run($author, 'My title', 'My content');
As a controller
Simply register your action as an invokable controller in a routes file.
Route::post('articles', PublishANewArticle::class)->middleware('auth');
As a listener
Simply register your action as a listener of the NewProductReleased event.
Event::listen(NewProductReleased::class, PublishANewArticle::class);
Then, the asListener method of your action will be called whenever the NewProductReleased event is dispatched.
event(new NewProductReleased($manager, 'Product title', 'Product description'));
And more...
On top of running your actions as objects, controllers and listeners, Laravel Actions also supports jobs, commands and even mocking your actions in tests.
📚 Check out the full documentation to learn everything that Laravel Actions has to offer.
lorisleiva/laravel-actions 适用场景与选型建议
lorisleiva/laravel-actions 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.6M 次下载、GitHub Stars 达 2.84k, 最近一次更新时间为 2019 年 05 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「command」 「controller」 「listener」 「object」 「component」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lorisleiva/laravel-actions 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lorisleiva/laravel-actions 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lorisleiva/laravel-actions 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Give your JS App some Backbone with Models, Views, Collections, and Events.
A Wrapper for exec and it's results
Symfony bundle to monitor and execute commands
Timestamp parameter in public file uri
Shell command module for PHP.
The Listener component of the RabbitEvents library.
统计信息
- 总下载量: 8.6M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2845
- 点击次数: 34
- 依赖项目数: 123
- 推荐数: 8
其他信息
- 授权协议: MIT
- 更新时间: 2019-05-19
