2017 © Pedro Peláez
 

library value

Abstract value and enum objects

image

tmilos/value

Abstract value and enum objects

  • Monday, December 26, 2016
  • by tmilos
  • Repository
  • 1 Watchers
  • 2 Stars
  • 792 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 7 Versions
  • 8 % Grown

The README.md

Value object PHP lib

Abstract value and enum objects, (*1)

License Build Status Coverage Status Scrutinizer Code Quality SensioLabsInsight, (*2)

Value objects

class IntValue extends AbstractValue
{
    public static function isValid($value)
    {
        return is_int($value);
    }
}

$x = new IntValue(10); // ok
print $x->getValue(); // 10
$y = new IntValue(10);
var_dump($x->equal($y)); // true

$z = new IntValue('20'); // throws \UnexpectedValueException

Enum value object

All class defined constants are valid values, and magic method with same constant name can be called to instantiate Enum with that value., (*3)

class Gender extends AbstractEnum
{
    const MALE = 'male';
    const FEMALE = 'female';

    private static $titles = [
        self::MALE => 'gender.male',
        self::FEMALE => 'gender.female',
    ];

    public function getTitle()
    {
        return self::$titles[$this->getValue()];
    }
}

var_dump(Gender::all());    // ['male' => Gender() => 'female' => Gender() ]
var_dump(Gender::values()); // [ 0 => 'male', 1 => 'female' ]
$m = Gender::MALE();
print $m->getValue(); // male
print $m->getTitle(); // gender.male
var_dump(Gender::isValid('male')); // true
var_dump(Gender::isValid('something')); // false

The Versions

26/12 2016

dev-master

9999999-dev

Abstract value and enum objects

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

enum abstract value object

26/12 2016

2.0.1

2.0.1.0

Abstract value and enum objects

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

enum abstract value object

21/12 2016

2.0.0

2.0.0.0

Abstract value and enum objects

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

enum abstract value object

06/06 2016
10/05 2016
12/04 2016
08/04 2016