danielefavi/fluent-api
Composer 安装命令:
composer require danielefavi/fluent-api
包简介
Class designed for fluent API interface: you can invoke the same method statically and non-statically.
README 文档
README
PHP package for fluent API interfaces: you can invoke a method both statically and non-statically.
Installation
composer require danielefavi/fluent-api
Usage
1) Import the FluentApi class in the file you need it.
use DanieleFavi\FluentApi\FluentApi;
2) Extend your class with FluentApi class.
class FluentMath extends FluentApi { }
3) Create your methods that can be invoked statically and non-statically.
Declare the functions that can be called statically or non-statically with an underscore _.
In the example below the functions add and subtract can be invoked statically or non-statically.
class FluentMath extends FluentApi { private $result = 0; protected function _add($num) { $this->result += $num; return $this; } protected function _subtract($num) { $this->result -= $num; return $this; } public function result() { return $this->result; } }
4) Example of usage
$res1 = FluentMath::add(5) ->add(3) ->subtract(2) ->add(8) ->result(); $res2 = FluentMath::subtract(1) ->add(10) ->result(); // $res1 equals to 14 // $res2 equals to 9
统计信息
- 总下载量: 16
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-01-15