aeviiq / value-object
A library that provides strict value objects in PHP.
Installs: 15 806
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 4
Open Issues: 0
Requires
- php: ^8.1
- symfony/validator: ^5.4|^6.0
- thecodingmachine/safe: ^2.0
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpstan/phpstan-phpunit: ^1.3
- phpstan/phpstan-strict-rules: ^1.5
- phpunit/phpunit: ^10.0
- psalm/plugin-phpunit: ^0.18.4
- roave/security-advisories: dev-master
- thecodingmachine/phpstan-strict-rules: ^1.0
- vimeo/psalm: ^5.4
README
Why
To provide an easy way to create value objects in PHP. Validation can be done by using the Symfony Validator component (https://github.com/symfony/validator and its documentation https://symfony.com/doc/current/validation.html#constraints). This also allows for easy integration with the Symfony Form component, as the value object constraints are defined statically.
Installation
composer require aeviiq/value-object
Declaration
<?php declare(strict_types=1); namespace Aeviiq\ValueObject\Value; use Aeviiq\ValueObject\AbstractString; use Aeviiq\ValueObject\Normalizer; use Symfony\Component\Validator\Constraints; final class Iban extends AbstractString { public static function getConstraints(): array { return [ new Constraints\Iban(), ]; } protected function normalize($value): string { return Normalizer::removeWhitespace($value); } }
Usage
$iban = new Iban('Invalid value'); // Results in InvalidArgumentException $iban = new Iban('NL91 ABNA 0417 1643 00'); // Contains a valid Iban.