Value Objects are small and immutable classes representing typed values usually implemented using PHP primitive types. However, objects can embed validation to ensure that your data is always valid without adding any check elsewhere in your code. That's why you should ALWAYS use Value Objects rather than primitive types!
This package provides most common types you can use in any project.
This package requires PHP 7.4+
Add it as Composer dependency:
$ composer require mediagone/types-common
All value-objects implement a common ValueObject
interface and JsonSerializable
.
Bic
Iban
Hash
(abstract class)HashBcrypt
HashArgon2id
RandomToken
Sha512
Note: all Hash* types are based on Hash
base class, so they are perfectly interoperable.
Address
City
Country
Latitude
Longitude
Color
Age
Base64
Binary
Count
Date
DateTimeUTC
DayOfMonth
Duration
Hex
Quantity
Name
NameDigit
NameSpecial
Slug
SlugSnake
Text
TextMedium
Title
EmailAddress
Url
UrlHost
UrlPath
Types Common is licensed under MIT license. See LICENSE file.