定制 kamilwylegala/immutable-setter 二次开发

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

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

kamilwylegala/immutable-setter

最新稳定版本:0.1.1

Composer 安装命令:

composer require kamilwylegala/immutable-setter

包简介

Utility class for PHP that helps making your classes immutable.

README 文档

README

Tiny utillity class that helps you making your classes immutable by adding wither methods.

Inspired by Lombok's @Wither annotation.

It lets you easily add witherX methods to clone object with modified one property.

Installation

Use composer to get library from packagist:

$ php composer.phar require kamilwylegala/immutable-setter

Usage

  1. Add wither field to your class.
  2. Assign new Wither($this, ["arg1", "arg2"]) to this field and provide constructor schema with proper order of arguments. You can also skip second argument and let Wither resolve constructor arguments automatically.
  3. Add public withArg1 method to your class and put:
return $this->wither->getInstance("arg1", $newArg1)
  1. Running $valueObject->withArg1($newArg1) will create copy of your object with changed $arg1 field.

Example

use KamilWylegala\ImmutableSetter\Wither;

class Person
{

    private $name;
    private $age;

    private $wither;

    public function __construct($name, $age)
    {
        $this->name = $name;
        $this->age = $age;

        $this->wither = new Wither($this, ["name", "age"]); //Second param is optional.
    }

    public function withName($newName)
    {
        return $this->wither->getInstance("name", $newName);   
    }

}

Tests

Install dev dependencies and run in root:

$ vendor/bin/phpunit

Licence

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-07-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固