承接 skybluesofa/chainable 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

skybluesofa/chainable

Composer 安装命令:

composer require skybluesofa/chainable

包简介

Allow for chainable, fluent method calls

README 文档

README

Build Status Code Climate Test Coverage Total Downloads Version Software License

Chainable

Allow for chainable, fluent method calls

Chaining Methods

Check out the [Tests/Sandwich(https://github.com/skybluesofa/chainable/blob/master/tests/Sandwich.php] class. It gives a bunch of uses for the Chainable trait.

Basic use of this trait:

  • Set the visibility for the chainable functions to 'private'
  • Ensure that you either modify the current class or return a cloned version of the class
  • Ensure that you return a reference to the class
private function withBread($breadType=null) {
  $this->breadType = $breadType;
  return $this;
}

Calling fluent methods

Now you can call these methods fluently:

Sandwich::withBread('white')->
  addCondiment('peanut butter')->
  addCondiment('jelly')->
  make();

or the same sandwich, but the methods are called in a different order:

Sandwich::addCondiment('peanut butter')->
  withBread('white')->
  addCondiment('jelly')->
  make();

Modifying the output

Any time up until you return something other than a reference to the chained class, you can modify what will be output:

Sandwich::withBread('wheat')->
  addCondiment('peanut butter')->
  addCondiment('grape jelly')->
  withBread('white')->
  removeCondiment('grape jelly')->
  addCondiment('strawberry jelly')->
  make();

Missing methods

This will return an exception, as the 'addBananas' method does not exist.

Sandwich::withBread('white')->
  addCondiment('peanut butter')->
  addBananas()->
  make();

Public methods

This will return an error, as the 'addVegetable' method is not static:

Sandwich::addVegetable('lettuce')->
  withBread('white')->
  make();

To work around this, use the 'chainableProxy' method before calling 'addVegetable':

Sandwich::chainableProxy()->
  addVegetable('lettuce')->
  withBread('white')->
  make();

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-10-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固