kylwes/laravel-pipes
Composer 安装命令:
composer require kylwes/laravel-pipes
包简介
Easily chain and execute multiple actions on a single data object.
README 文档
README
Laravel Pipes is a PHP library that allows you to easily chain and execute multiple actions on a single data object. It is inspired by the Unix pipe concept, where the output of one command can be used as the input to another command.
$user = $createUser->execute($request->validated()); $sendWelcomeEmail->execute($user);
you can write this:
$user = pipe($request->validated(), [ CreateUser::class, SendWelcomeEmail::class, ]);
Installation
You can install the package via composer:
composer require kylwes/pipe
Usage
You can create a pipe by use the pipe function:
$user = pipe($request->validated(), [ CreateUser::class, SendWelcomeEmail::class, ]); // $user is an instance of App\Models\User
When one of your actions expects another parameter, you can use the with method:
// App\Actions\AssignRoleToUser.php class AssignRoleToUser { public function execute(User $user, $role) { $user->assignRole($role); return $user; } } // App\Http\Controllers\UserController.php $user = pipe($request->validated()) ->with(['role' => Role::find(1)]) ->through([ CreateUser::class, AssignRoleToUser::class, SendWelcomeEmail::class, ]); // $user is an instance of App\Models\User
You can also use pass anonymous functions:
$user = pipe($data, [ CreateUser::class, function ($user) { $user->assignRole(Role::find(1)); return $user; }, SendWelcomeEmail::class, ]); // $user is an instance of App\Models\User
or call a function:
$title = pipe(' My awesome title ', [ 'trim', 'strtoupper', ]); // $title is 'MY AWESOME TITLE'
You can also pipe each individual item in an array or collection by using the ->each() method:
$users = pipe($users) ->each() ->through([ ResetAnswers::class, InviteForNextSession::class, ]);
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Contributions are welcome! If you find a bug or have a feature request, please open an issue on GitHub. If you would like to contribute code, please fork the repository and submit a pull request.
Credits
License
Laravel Pipes is licensed under the MIT license. See the LICENSE file for details.
kylwes/laravel-pipes 适用场景与选型建议
kylwes/laravel-pipes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 02 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「pipes」 「actions」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kylwes/laravel-pipes 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kylwes/laravel-pipes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kylwes/laravel-pipes 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova tool to allow for placing actions in the Nova toolbar detached from the checkbox selection mechanism.
A PHP 8.1+ tool kit featuring RESTFUL ORM, sockets, session management, and routing.
A lightweight WordPress hook helper library. Register hooks before WordPress loads, run callbacks only once, and more.
Turns CPD style XML reports into Github pull-request annotations via the Checks API. This script is meant for use within your Github Action.
Action for small code bits, usable in laravel
A Laravel package to generate Action classes via Artisan
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-20