transprime-research / laravel-chained
PHP Laravel-Chained
1.0.0
2021-10-24 13:24 UTC
Requires
- php: >=7.2
Requires (Dev)
- phpunit/phpunit: ~8.0
This package is auto-updated.
Last update: 2024-09-24 19:36:01 UTC
README
关于 Laravel-chained
Laravel chained 帮助在任意类上链式调用方法。
像专业人士一样做 🆗
安装
composer require transprime-research/laravel-chained
快速使用
假设我们有一个有很多静态方法的类。而不是
$value = Str::lower('ChainedOnStr'); $value = Str::snake($value); $value = Str::before($value, '_'); $value = Str::length($value); //7
你使用
$value = chained(Str::class, ) ->to('lower', 'ChainedOnStr') ->to('snake') ->to('before', '_') ->to('length')(); //14
或者别名方法调用
$value = chained(Str::class) ->lower('ChainedOnStr') ->snake() ->before('_') ->length()(); //7
其他用法
tap() 方法
$value = chained(Str::class) ->to('lower', 'ChainedOnStr') ->tap(function ($res) { var_dump($res); }) ->to('snake') ->to('length') ->up(); //Up is used instead of ()
即将推出
在更多类上链式调用
use Transprime\Chained\Chained; $value = chained(DB::class)->to('resolveDb', 'ChainedOnStr') ->chain(Str::class, function (Chained $chain) { return $chain->to('lower')->to('snake'); }) ->chain(Arr::class, function (Chained $chain) { return $chain->to('wrap')->to('add', 1, 'using_add'); })(); //Or chained(DB::class) ->to('resolveDb', 'ChainedOnStr') ->chain(Str::class) // next calls use `Str` class ->to('lower')->to('snake') ->chain(Arr::class) // next calls use `Arr` class ->to('wrap')->to('add', 1, 'using_add')();
API 实现待定
附加信息
此包是“代码冒险”系列的一部分。
在此处查看此系列中的其他包
- 一个智能 PHP if...elseif...else 语句 https://github.com/omitobi/conditional
- 以面向对象方式实现的 PHP 功能性 pipe https://github.com/transprime-research/piper
- 数组现在是对象 https://github.com/transprime-research/arrayed
- 一个智能 PHP try...catch 语句 https://github.com/transprime-research/attempt
- 一个智能 Carbon + Collection 包 https://github.com/omitobi/carbonate
- Jsonable Http Request(er) 包含集合响应 https://github.com/omitobi/laravel-habitue
贡献
对于新功能,请使用前缀 feature/#issueid
检查 out,例如 feature/#100-add-auto-deploy
- 克隆此存储库
- 运行
sh dockerizer.sh
或bash dockerizer.sh
- 使用
docker-compose exec conditional sh
(sh
可以是另一个 bash)在 docker 环境中执行 - 使用
vendor/bin/phpunit
运行测试
使用 Laravel Dockerizer 简化了 docker 设置
类似包
许可证
MIT(见 LICENCE 文件)