2017-25 © Pedro Peláez
 

library phalue-objects

Phalue Objects - PHP Value Objects

image

best-served-cold/phalue-objects

Phalue Objects - PHP Value Objects

  • Wednesday, April 19, 2017
  • by nark3d
  • Repository
  • 2 Watchers
  • 3 Stars
  • 133 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 13 Versions
  • 0 % Grown

The README.md

PhalueObjects

Build Status Scrutinizer Quality Score Code Coverage SensioLabsInsight, (*1)

A generic set of PHP Value Objects for use in any project., (*2)

Wikipedia, (*3)

When people exchange business cards, they generally do not distinguish between each unique card; they only are concerned about the information printed on the card. In this context, business cards are value objects., (*4)

Table of contents

Installation

composer require best-served-cold/phalue-objects

Philosophy

To make this code consistent, we've stuck to a certain set of restrictions:, (*5)

Rules

Disclaimer: This is my interpretation of "The rules"., (*6)

Must be immutable

The value object's value must be set at the time of construction. At no point should the value be mutated within the object., (*7)

Must contain one value

The value object can only be constructed from one value, this can be any of the following types: * boolean * integer * float/double * string * array * object * resource * null, (*8)

Can instantiate new object from value

Rather than mutating, a new object can be instantiated from an existing one., (*9)

Example:, (*10)

//...
public function double() 
{
    return new static($this->getValue() * 2);
}
...//

Can be created from multiple arguments

Instead of an object having multiple object properties, it should be created from multiple arguments., (*11)

Example:, (*12)

//...
public static function fromVars($one = 1, $two = 2, $three = 3)
{
    return new static([$one, $two, $three]); 
}
...//

Can be equal regardless of object

The type of a value object is irrelevant to equality:, (*13)

Example:, (*14)

//...
$bob = $stringValueObject->equals($csvValueObject);
...//

$bob is true where the type and value are equal., (*15)

Must have a zero lifespan

Value objects must not persist data between run times. For example: no database or session information should be collected from within the object., (*16)

Conventions

Follow PSR-FIG rules., (*17)

Constructor

Example:, (*18)

new SomeClass('value');
  • Must only have one argument of any type

Creation methods (From)

Example:, (*19)

SomeClass::fromSomeObject($someObject);
  • Always start with "from"
  • Must be static
  • Can contain multiple arguments
  • Must return new static instance

Conversion methods (To)

Example:, (*20)

$someObject->toArray();
  • Always start with "to"
  • Must not be static
  • Must have zero arguments
  • Must return new static instance

The Versions

12/03 2017

v0.0.11-alpha

0.0.11.0-alpha http://bestservedcold.com

Phalue Objects - PHP Value Objects

  Sources   Download

MIT

The Requires

 

The Development Requires

immutable value objects best served cold phalueobjects

11/03 2017

v0.0.10-alpha

0.0.10.0-alpha http://bestservedcold.com

Phalue Objects - PHP Value Objects

  Sources   Download

MIT

The Requires

 

The Development Requires

immutable value objects best served cold phalueobjects

03/03 2017

v0.0.9-alpha

0.0.9.0-alpha http://bestservedcold.com

Phalue Objects - PHP Value Objects

  Sources   Download

MIT

The Requires

 

The Development Requires

immutable value objects best served cold phalueobjects

29/01 2016

v0.0.8-alpha

0.0.8.0-alpha http://bestservedcold.com

Phalue Objects - PHP Value Objects

  Sources   Download

MIT

The Requires

 

The Development Requires

immutable value objects best served cold phalueobjects

02/01 2016

v0.0.7-alpha

0.0.7.0-alpha http://bestservedcold.com

Phalue Objects - PHP Value Objects

  Sources   Download

MIT

The Requires

 

The Development Requires

immutable value objects best served cold phalueobjects

02/01 2016

v0.0.6-alpha

0.0.6.0-alpha http://bestservedcold.com

Phalue Objects - PHP Value Objects

  Sources   Download

MIT

The Requires

 

The Development Requires

immutable value objects best served cold phalueobjects

02/01 2016

v0.0.5-alpha

0.0.5.0-alpha http://bestservedcold.com

Phalue Objects - PHP Value Objects

  Sources   Download

MIT

The Requires

 

The Development Requires

immutable value objects best served cold phalueobjects

02/01 2016

v0.0.2-alpha

0.0.2.0-alpha http://bestservedcold.com

Phalue Objects - PHP Value Objects

  Sources   Download

MIT

The Requires

 

The Development Requires

immutable value objects best served cold phalueobjects

02/01 2016

v0.0.3-alpha

0.0.3.0-alpha http://bestservedcold.com

Phalue Objects - PHP Value Objects

  Sources   Download

MIT

The Requires

 

The Development Requires

immutable value objects best served cold phalueobjects

02/01 2016

v0.0.4-alpha

0.0.4.0-alpha http://bestservedcold.com

Phalue Objects - PHP Value Objects

  Sources   Download

MIT

The Requires

 

The Development Requires

immutable value objects best served cold phalueobjects

23/09 2015