Download the PHP package best-served-cold/phalue-objects without Composer
On this page you can find all versions of the php package best-served-cold/phalue-objects. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download best-served-cold/phalue-objects
More information about best-served-cold/phalue-objects
Files in best-served-cold/phalue-objects
Package phalue-objects
Short Description Phalue Objects - PHP Value Objects
License MIT
Homepage http://bestservedcold.com
Informations about the package phalue-objects
PhalueObjects
A generic set of PHP Value Objects for use in any project.
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.
Table of contents
- Installation
- Philosophy
- Documents
- Format
Installation
Philosophy
To make this code consistent, we've stuck to a certain set of restrictions:
Rules
- Must be immutable
- Must contain one value
- Can instantiate new object from value
- Can be created from multiple arguments
- Can be equal regardless of object
- Must have a zero lifespan
Disclaimer: This is my interpretation of "The rules".
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.
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
Can instantiate new object from value
Rather than mutating, a new object can be instantiated from an existing one.
Example:
Can be created from multiple arguments
Instead of an object having multiple object properties, it should be created from multiple arguments.
Example:
Can be equal regardless of object
The type of a value object is irrelevant to equality:
Example:
is true where the type and value are equal.
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.
Conventions
Follow PSR-FIG rules.
Constructor
Example:
- Must only have one argument of any type
Creation methods (From)
Example:
- Always start with "from"
- Must be static
- Can contain multiple arguments
- Must return new static instance
Conversion methods (To)
Example:
- Always start with "to"
- Must not be static
- Must have zero arguments
- Must return new static instance
All versions of phalue-objects with dependencies
symfony/yaml Version 2.*
symfony/finder Version 2.*
sabre/xml Version ^1.5