2017 © Pedro Peláez
 

library basicvalueobjects

A collection of basic value objects.

image

martindilling/basicvalueobjects

A collection of basic value objects.

  • Saturday, February 14, 2015
  • by martindilling
  • Repository
  • 1 Watchers
  • 0 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Basic Value Objects

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads SensioLabsInsight, (*1)

A small collection of the most basic value objects. These can help make your code more expressive, and save some manual validation., (*2)

Install

All the available versions is visible on Packagist., (*3)

Via Composer, (*4)

``` bash $ composer require martindilling/basicvalueobjects, (*5)


## Usage Using these value objects you can type-hint method arguments to make it more sure the arguments will be given in the right format. In this example the fields will hold instances of the value objects. ``` php use BasicValueObjects\String; use BasicValueObjects\Integer; use BasicValueObjects\Boolean; class CrewMember { /** @var \BasicValueObjects\String */ private $firstname; /** @var \BasicValueObjects\String */ private $lastname; /** @var \BasicValueObjects\Integer */ private $age; /** @var \BasicValueObjects\Boolean */ private $captain; function __construct(String $firstname, String $lastname, Integer $age, Boolean $captain) { $this->firstname = $firstname; $this->lastname = $lastname; $this->age = $age; $this->captain = $captain; } } $person = new CrewMember( new String('Malcolm'), new String('Reynolds'), new Integer(49), Boolean::true() );

If you don't want the fields on the object to hold the instances but want the type-hinting, you can just assign the native value of the value object to the fields: ``` php use BasicValueObjects\String; use BasicValueObjects\Integer; use BasicValueObjects\Boolean;, (*6)

class CrewMember { /** @var string */ private $firstname;, (*7)

/** @var string */
private $lastname;

/** @var int */
private $age;

/** @var bool */
private $captain;

function __construct(String $firstname, String $lastname, Integer $age, Boolean $captain)
{
    $this->firstname = $firstname->native();
    $this->lastname  = $lastname->native();
    $this->age       = $age->native();
    $this->captain   = $captain->native();
}

}, (*8)

$person = new CrewMember( new String('River'), new String('Tam'), new Integer('28'), Boolean::false() );, (*9)


Demonstration of how to work with the value objects: ``` php // String $shiny = new String("Everything's shiny, Cap'n. Not to fret."); $fool = new String("Oh, she'll fool ya."); $shiny->native(); // (string) Everything's shiny, Cap'n. Not to fret. $fool->__toString(); // (string) Oh, she'll fool ya. $shiny->equals($fool); // (bool) false // Integer $integer1 = new Integer(42); $integer2 = new Integer(37); $integer1->native(); // (integer) 42 $integer2->__toString(); // (string) 37 $integer1->equals($integer2); // (bool) false // Boolean $boolean1 = new Boolean(true); $boolean2 = new Boolean(Boolean::TRUE); $boolean3 = Boolean::false(); $boolean1->native(); // (bool) true $boolean2->__toString(); // (string) true $boolean1->equals($boolean2); // (bool) true $boolean1->equals($boolean3); // (bool) false

Testing

bash $ phpunit, (*10)

Contributing

Please see CONTRIBUTING for details., (*11)

Security

If you discover any security related issues, please email martindilling@gmail.com instead of using the issue tracker., (*12)

Credits

License

The MIT License (MIT). Please see License File for more information., (*13)

The Versions

14/02 2015

dev-master

9999999-dev https://github.com/martindilling/basicvalueobjects

A collection of basic value objects.

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

string ddd boolean value objects float integer

14/02 2015

0.2.2

0.2.2.0 https://github.com/martindilling/basicvalueobjects

A collection of basic value objects.

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

string ddd boolean value objects float integer

14/02 2015

0.2.1

0.2.1.0 https://github.com/martindilling/basicvalueobjects

A collection of basic value objects.

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

string ddd boolean value objects float integer

14/02 2015

0.2.0

0.2.0.0 https://github.com/martindilling/basicvalueobjects

A collection of basic value objects.

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

string ddd boolean value objects float integer

13/02 2015

0.1.1

0.1.1.0 https://github.com/martindilling/basicvalueobjects

A collection of basic value objects.

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

string ddd boolean value objects integer

10/02 2015

0.1.0

0.1.0.0 https://github.com/martindilling/basicvalueobjects

A collection of basic value objects.

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

string ddd boolean value objects integer