StraTDeS VO is a library containing some standard value objects ready to use.
To install the library just run:
composer require stratdes/vo
Using this library is quite straightforward. All the Value Objects have a named constructor, usually create or fromValue.
Some examples:
use StraTDeS\VO\Single\Currency;
use StraTDeS\VO\Single\Money;
use StraTDeS\VO\Single\Name;
use StraTDeS\VO\Single\Description;
use StraTDeS\VO\Single\PhoneNumber;
$name = Name::fromValue("John Smith");
$description = Description::fromValue("This is a description");
$money = Money::create(
20034,
Currency::fromValue(Currency::USD)
);
$phoneNumber = PhoneNumber::create("34", "938140000");
You can use collections, also. For example, for a collection of Emails, you have:
use StraTDeS\VO\Collection\EmailCollection;
use StraTDeS\VO\Single\Email;
$emailCollection = EmailCollection::create();
$emailCollection->add(Email::fromValue('[email protected]'));
$emailCollection->add(Email::fromValue('[email protected]'));
$emailCollection->add(Email::fromValue('[email protected]'));
foreach($emailCollection as $email) {
echo $email->value() . "\n\r";
}
If you find some issue in the library, please feel free to open an issue here on Github.