定制 amtgard/builder-traits 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

amtgard/builder-traits

最新稳定版本:v2.2.2

Composer 安装命令:

composer require amtgard/builder-traits

包简介

Builder traits

README 文档

README

Implements a Lombokish version of Builder using Traits.

Supports the following traits individually:

  • Builderå
  • Getter
  • Setter
  • ToBuilder
  • Data

Example usage is in tests/Models/ and tests/BuilderTest.php.

Builder

To add builder functionality, add the Builder trait:

use Builder;

You can then construct an object using the builder fluent interface:

Gato::builder()->age(7)->name("Charlie")->build();

Getter, Setter, Data

You can add getters and setters over all private members by adding the Getter or Setter traits.

Due to limitations in library design, both Getter and Setter cannot be used in the same class.

Instead, use the Data trait.

Getter

class Gato {
    use Getter;
    private $name;
}

$catName = $gato->getName();

Setter

class Gato {
    use Setter;
    private $name;
}
$name = $gato->getName();

Data

Due to trait method collision, we can't compose Getter and Setter in the same class.

Instead use the Data trait.

class Gato {
    use Data;
    private $name;
}
$gato->setName('Charlie');
$name = $gato->getName();

ToBuilder

We can mutate an existing object with the ToBuilder trait.

class Gato {
    use ToBuilder;
    private $name;
}
$chuck = $gato->toBuilder()->name('Charlie')->build();

Hooks

#[PostInit] Attribute

Apply the #[PostInit] attribute to any private method to be called during the ->build() phase of the Builder.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-03