2017 © Pedro Peláez
 

library immutable-setter

Utility class for PHP that helps making your classes immutable.

image

kamilwylegala/immutable-setter

Utility class for PHP that helps making your classes immutable.

  • Saturday, June 2, 2018
  • by kamilwylegala
  • Repository
  • 1 Watchers
  • 0 Stars
  • 27 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 13 % Grown

The README.md

Immutable Setter

Tiny utillity class that helps you making your classes immutable by adding wither methods., (*1)

Inspired by Lombok's @Wither annotation., (*2)

It lets you easily add witherX methods to clone object with modified one property., (*3)

Installation

Use composer to get library from packagist:, (*4)

$ 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:, (*5)

$ vendor/bin/phpunit

Licence

MIT, (*6)

The Versions

02/06 2018

dev-master

9999999-dev

Utility class for PHP that helps making your classes immutable.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Kamil Wylegala

setter immutable wither

02/06 2018

0.1.1

0.1.1.0

Utility class for PHP that helps making your classes immutable.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Kamil Wylegala

setter immutable wither

05/07 2017

0.1.0

0.1.0.0

Utility class for PHP that helps making your classes immutable.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Kamil Wylegala

setter immutable wither