kylwes/laravel-pipes 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kylwes/laravel-pipes

最新稳定版本:1.0.0

Composer 安装命令:

composer require kylwes/laravel-pipes

包简介

Easily chain and execute multiple actions on a single data object.

README 文档

README

Latest Version on Packagist Total Downloads

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.

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-02-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固