This library is useful for building value objects in php. It is a collection of abstract classes (each for every scalar type), that contain common validation mechanisms, so you don't have to write them.
So far, we have StringValue
and IntegerValue
which already satisfy most of the needs.
More scalar representations may be implemented in the future (feel free to contribute).
Look here to find some unit tested examples.
Required PHP version: 7.0.0 or higher
composer require jakubgiminski/value-object
Every ValueObject has a getValue()
method.
Validation rules (optional):
/** @var int */
protected $minLength;
/** @var int */
protected $maxLength;
/** @var array */
protected $validValues = [];
Comparison methods:
public function isEqual(StringValueInterface $stringValue): bool;
public function isShorterThan(StringValueInterface $stringValue): bool;
public function isLongerThan(StringValueInterface $stringValue): bool;
Examples of usage:
Validation rules (optional):
/** @var array */
protected $validRange = [];
/** @var array */
protected $validValues = [];
/** @var array */
protected $invalidValues = [];
Comparison methods:
public function isEqual(IntegerValueInterface $integerValue): bool;
public function isLessThan(IntegerValueInterface $integerValue): bool;
public function isGreaterThan(IntegerValueInterface $integerValue): bool;
Examples of usage: