This repository contains value objects implementations for PHP basic types:
- Boolean and Nullable boolean, bool type
- DateTime and Nullable dateTime, DateTime class
- Decimal and Nullable decimal, float type
- Enum, constants
- Integer and Nullable integer, int type
- Json and Nullable json, string type with json validation
- Text and Nullable text, string type
- Uuid and Nullable Uuid, string type with uuid validation
By definition these classes are immutable, will always be valid, don't have an identity (id) and describe a concept. In accordance with these ideas the value object classes have:
- __construct($value) to initialize its value and a value() function to get it.
- validation() function. Basic validations like string length validation, min/max validations or json and uuid format validations. When a validation fails throws an
- InvalidValueObjectException.
- abstract definition. You most describe your domain concepts.
- and equals() and toString() functions implementations.
To use this repository you copy and paste the folder "Src" into your project. The reason it's simple: you have to control this code. This code belongs to your inner logic. I recommend you copy "Tests" folder into your project too just in case you need to modify the src code.
Remember to configure the namespace "Src" classes according to your project.
The Order class it's a Domain Model example where are used value objects. Take a look at Example/Order/Order.php class and its test class Tests/Example/OrderTest.php.
To watch each value object example take a look at Test/Src folder.
To test this repository you most install composer dependency management tool. If you have installed composer download the repository and execute next command at root folder
composer tests