hyperized / value-objects
A basic value objects collection
Installs: 7 417
Dependents: 4
Suggesters: 0
Security: 0
Stars: 6
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: ^7.4|^8.0
- ext-json: *
Requires (Dev)
- phpstan/phpstan: ^1.2
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^4.13
README
A basic PHP value objects collection.
Install
composer require hyperized/value-objects
Examples
Integer type
<?php declare(strict_types=1); use Hyperized\ValueObjects\Abstracts\Integers\AbstractInteger; include 'vendor/autoload.php'; // Implement concrete class for as value object class MyObject extends AbstractInteger {} $myObject = MyObject::fromInteger(1337); var_dump($myObject->getValue()); // int(1337)
Other types that are offered:
- NegativeInteger.
- Validates value is below 0 (zero).
- PositiveInteger
- Validates value is above 0 (zero).
- RangedInteger.
- Validates value is higher than minimum.
- Validates value is lower than maximum.
- By default minimum value is
PHP_INT_MIN
and maximum valuePHP_INT_MAX
.
- Octal.
- Validates value is octal.
String type (ByteArray)
Strings are called ByteArrays due to string being a reserved word in PHP.
<?php declare(strict_types=1); use Hyperized\ValueObjects\Abstracts\Strings\AbstractByteArray; include 'vendor/autoload.php'; class MyObject extends AbstractByteArray {} $myObject = MyObject::fromString('Hello world!'); var_dump($myObject->getValue()); // string('Hello world');
Other types that are offered:
- EmptyByteArray.
- Validates value equals '' (empty string)
- NonEmptyByteArray.
- Validates value does not equal '' (empty string)
Licence
MIT
Author
Gerben Geijteman gerben@hyperized.net