Skip to content

Library of abstract classes intended to be used as bases for value objects. Includes examples in form of unit tested use cases.

Notifications You must be signed in to change notification settings

jakubgiminski/value-object

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Value Object

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

Installation

composer require jakubgiminski/value-object

Overview

Every ValueObject has a getValue() method.

ValueObject\StringValue

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:

ValueObject\IntegerValue

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:

About

Library of abstract classes intended to be used as bases for value objects. Includes examples in form of unit tested use cases.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages