https://github.com/Aerendir/component-value-objects
A set of PHP Value Objects to manage composite values
https://github.com/Aerendir/component-value-objects
doctrine php value-object
Last synced: 10 months ago
JSON representation
A set of PHP Value Objects to manage composite values
- Host: GitHub
- URL: https://github.com/Aerendir/component-value-objects
- Owner: Aerendir
- License: mit
- Created: 2015-07-07T02:11:35.000Z (over 10 years ago)
- Default Branch: dev
- Last Pushed: 2025-04-01T08:04:56.000Z (11 months ago)
- Last Synced: 2025-04-10T04:02:19.099Z (10 months ago)
- Topics: doctrine, php, value-object
- Language: PHP
- Size: 1.59 MB
- Stars: 20
- Watchers: 1
- Forks: 1
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Serendipity HQ Value Objects
A set of PHP Value Objects to manage simple and composite values.
## Current Status
[](https://sonarcloud.io/dashboard?id=Aerendir_component-value-objects)
[](https://sonarcloud.io/dashboard?id=Aerendir_component-value-objects)
[](https://sonarcloud.io/dashboard?id=Aerendir_component-value-objects)
[](https://sonarcloud.io/dashboard?id=Aerendir_component-value-objects)
[](https://sonarcloud.io/dashboard?id=Aerendir_component-value-objects)
[](https://sonarcloud.io/dashboard?id=Aerendir_component-value-objects)
[](https://sonarcloud.io/dashboard?id=Aerendir_component-value-objects)
[](https://github.com/Aerendir/component-value-objects/actions?query=branch%3Adev)
[](https://github.com/Aerendir/component-value-objects/actions?query=branch%3Adev)
[](https://github.com/Aerendir/component-value-objects/actions?query=branch%3Adev)
[](https://github.com/Aerendir/component-value-objects/actions?query=branch%3Adev)
[](https://github.com/Aerendir/component-value-objects/actions?query=branch%3Adev)
[](https://github.com/Aerendir/component-value-objects/actions?query=branch%3Adev)
[](https://github.com/Aerendir/component-value-objects/actions?query=branch%3Adev)
## Features
It supports `SimpleValueObjects` and `ComplexValueObjects`.
Complex value objects are hydrated passing an array. If a key of the array isn't recognized as property of the object it
is added to the `$otherData` array so it isn't lost.
Some of those value objects support also the persistence in Doctrine providing [custom mapping types](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/custom-mapping-types.html) (See below).
Do you like this library?
LEAVE A ★
or run
composer global require symfony/thanks && composer thanks
to say thank you to all libraries you use in your current project, this included!
## What are Value Objects
Value Objects are PHP [`objects`](http://php.net/manual/en/language.types.object.php) that represent and manage simple
or complex values. Once set, the value object cannot be modified without changing its identity.
**Simple value objects** represent a simple value, like an email.
**Complex value objects** represent complex values, that, in order to really represent a value, need more than one
value, like a price that needs an amount and a currency to be understandable and have a sense.
PHP supports only one value object: the [`DateTime`](http://php.net/manual/en/class.datetime.php) object.
This library gives support for other kind of values, differentiating them between complex and simple.
To better understand the concepts behind the value objects, you can [read this post](https://io.serendipityhq.com/experience/php-and-doctrine-immutable-objects-value-objects-and-embeddables/).
## Install component-value-objects via Composer
$ composer require serendipity_hq/component-value-objects
This library follows the http://semver.org/ versioning conventions.
[Instructions to install Intl PHP extension in MAMP for Mac](https://io.serendipityhq.com/experience/how-to-install-php-intl-module-in-mamp/)
## Available Value Objects
Currently, this library supports the following Value Objects:
* **[Address](docs/Address.md)**: Built-in. A more advanced value object is [`commerceguys/addressing`](https://github.com/commerceguys/addressing) (but it more suited for shipping addresses than for addresses themself);
* **[CurrencyExchangeRate](docs/CurrencyExchangeRate.md)**: Built-in;
* **[Email](docs/Email.md)**: A basic class derived from [Wowo's gist EmailValueObject](https://gist.github.com/wowo/b49ac45b975d5c489214). It implements [`egulias/email-validator](https://github.com/egulias/EmailValidator) to validate emails;
* **[IP](docs/Ip.md)**: Just a proxy for the library [`darsyn/ip`](https://github.com/darsyn/ip);
* **[Money](docs/Money.md)**: Just a proxy for the library [`moneyphp/money`](https://github.com/moneyphp/money);
* **[Payment](docs/Payment.md)**: Built-in
* **[Phone](docs/Phone.md)**: Just a proxy for the library [`giggsey/libphonenumber-for-php`](https://github.com/giggsey/libphonenumber-for-php);
* **[Tax](docs/Tax.md)**: Built-in
* **[Uri](docs/Uri.md)**: Just a proxy for the library [`Laminas\Uri`](https://github.com/laminas/laminas-uri) (formerly Zend Uri). A more advanced value object is [`League\Uri`](https://github.com/thephpleague/uri)
* **[VatRate](docs/Vat.md)**: Built-in
* **[VatNumber](docs/VatNumber.md)**: Built-in
## Supported features
ValueObject
Doctrine
Symfony
Embeddable
Type
Form Type
Twig filter
Address
✓
✕
✓
✕
Currency
N/A
✓
✕
✕
CurrencyExchangeRate
N/A
N/A
N/A
N/A
Email
N/A
✓
N/A
N/A
IP
N/A
N/A
N/A
N/A
Money
N/A
✓
✓
✓
Payment
✕
✕
✕
✕
Phone
✕
✕
✕
✕
Tax
✕
✕
✕
✕
Uri
✕
✓
✕
✕
VAT Rate
✕
✕
✕
✕
VAT Number
✕
✕
✕
✕
Do you like this library?
LEAVE A ★
or run
composer global require symfony/thanks && composer thanks
to say thank you to all libraries you use in your current project, this included!