georgii-web / php-typed-values
Typed value objects library for common php data types.
v3.12.12
2026-04-06 21:07 UTC
Requires
- php: >=8.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^v3.94
- pestphp/pest: ^v3.8
- pestphp/pest-plugin-type-coverage: ^v3.6
- phpunit/phpunit: ^11.5
- rector/rector: ^2.3
- vimeo/psalm: ^6.16
Suggests
- ext-bcmath: Optionally required for Decimal type.
- dev-master
- v3.12.12
- v3.12.11
- v3.12.10
- v3.12.9
- v3.12.8
- v3.12.7
- v3.12.6
- v3.12.5
- v3.12.4
- v3.12.3
- v3.12.2
- v3.12.1
- v3.12.0
- v3.11.35
- v3.11.34
- v3.11.33
- v3.11.32
- v3.11.31
- v3.11.30
- v3.11.29
- v3.11.28
- v3.11.27
- v3.11.26
- v3.11.25
- v3.11.24
- v3.11.23
- v3.11.22
- v3.11.21
- v3.11.20
- v3.11.19
- v3.11.18
- v3.11.17
- v3.11.16
- v3.11.15
- v3.11.14
- v3.11.13
- v3.11.12
- v3.11.11
- v3.11.10
- v3.11.9
- v3.11.8
- v3.11.7
- v3.11.6
- v3.11.5
- v3.11.4
- v3.11.3
- v3.11.2
- v3.11.1
- v3.11.0
- v2.12.12
- v2.12.11
- v2.12.10
- v2.12.9
- v2.12.8
- v2.12.7
- v2.12.6
- v2.12.5
- v2.12.4
- v2.12.3
- v2.12.2
- v2.12.1
- v2.12.0
- v2.11.35
- v2.11.34
- v2.11.33
- v2.11.32
- v2.11.31
- v2.11.30
- v2.11.29
- v2.11.28
- v2.11.27
- v2.11.26
- v2.11.25
- v2.11.24
- v2.11.23
- v2.11.22
- v2.11.21
- v2.11.20
- v2.11.19
- v2.11.18
- v2.11.17
- v2.11.16
- v2.11.15
- v2.11.14
- v2.11.13
- v2.11.12
- v2.11.11
- v2.11.10
- v2.11.9
- v2.11.8
- v2.11.7
- v2.11.6
- v2.11.5
- v2.11.4
- v2.11.3
- v2.11.2
- v2.11.1
- v2.11.0
- v2.10.17
- v2.10.16
- v2.10.15
- v2.10.14
- v2.10.13
- v2.10.12
- v2.10.11
- v2.10.10
- v2.10.9
- v2.10.8
- v2.10.7
- v2.10.6
- v2.10.5
- v2.10.4
- v2.10.3
- v2.10.2
- v2.10.1
- v2.10.0
- v2.9.14
- v2.9.13
- v2.9.12
- v2.9.11
- v2.9.10
- v2.9.9
- v2.9.8
- v2.9.7
- v2.9.6
- v2.9.5
- v2.9.4
- v2.9.3
- v2.9.2
- v2.9.1
- v2.9.0
- v2.8.5
- v2.8.4
- v2.8.3
- v2.8.2
- v2.8.1
- v2.8.0
- v2.7.7
- v2.7.6
- v2.7.5
- v2.7.4
- v2.7.3
- v2.7.2
- v2.7.1
- v2.7.0
- v2.6.17
- v2.6.16
- v2.6.15
- v2.6.14
- v2.6.13
- v2.6.12
- v2.6.11
- v2.6.10
- v2.6.9
- v2.6.8
- v2.6.7
- v2.6.6
- v2.6.5
- v1.12.11
- v1.12.10
- v1.12.9
- v1.12.8
- v1.12.7
- v1.12.6
- v1.12.5
- v1.12.4
- v1.12.3
- v1.12.2
- v1.12.1
- v1.12.0
- v1.11.35
- v1.11.34
- v1.11.33
- v1.11.32
- v1.11.31
- v1.11.30
- v1.11.29
- v1.11.28
- v1.11.27
- v1.11.26
- v1.11.25
- v1.11.24
- v1.11.23
- v1.11.22
- v1.11.21
- v1.11.20
- v1.11.19
- v1.11.18
- v1.11.17
- v1.11.16
- v1.11.15
- v1.11.14
- v1.11.13
- v1.11.12
- v1.11.11
- v1.11.10
- v1.11.9
- v1.11.8
- v1.11.7
- v1.11.6
- v1.11.5
- v1.11.4
- v1.11.3
- v1.11.2
- v1.11.1
- v1.11.0
- v1.10.17
- v1.10.16
- v1.10.15
- v1.10.14
- v1.10.13
- v1.10.12
- v1.10.11
- v1.10.10
- v1.10.9
- v1.10.8
- v1.10.7
- v1.10.6
- v1.10.5
- v1.10.4
- v1.10.3
- v1.10.2
- v1.10.1
- v1.10.0
- v1.9.14
- v1.9.13
- v1.9.12
- v1.9.11
- v1.9.10
- v1.9.9
- v1.9.8
- v1.9.7
- v1.9.6
- v1.9.5
- v1.9.4
- v1.9.3
- v1.9.2
- v1.9.1
- v1.9.0
- v1.8.5
- v1.8.4
- v1.8.3
- v1.8.2
- v1.8.1
- v1.8.0
- v1.7.7
- v1.7.6
- v1.7.5
- v1.7.4
- v1.7.2
- v1.7.1
- v1.7.0
- v1.6.17
- v1.6.16
- v1.6.15
- v1.6.14
- v1.6.13
- v1.6.12
- v1.6.11
- v1.6.10
- v1.6.9
- v1.6.8
- v1.6.7
- v1.6.4
- v1.6.3
- v1.6.2
- v1.6.1
- v1.6.0
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.1
- v1.4.0
- v1.3.1
- v1.3.0
- v1.2.0
- v1.1.0
- 1.0.0
- dev-php7.4
- dev-php8.2
This package is auto-updated.
Last update: 2026-04-06 21:16:48 UTC
README
PHP Typed Values
Typed value objects for PHP. Build precise, immutable, and validated data for DTOs, Value Objects, and Entities.
Install
- Use V3 for PHP 8.4:
composer require georgii-web/php-typed-values:^3
- Use V2 for PHP >=8.2 & <8.4:
composer require georgii-web/php-typed-values:^2
- Use V1 for PHP 7.4:
composer require georgii-web/php-typed-values:^1
Why
- Strong typing for scalars with runtime validation
- Immutable and self‑documenting values
- Safer constructors for your DTOs/VOs/Entities
- Great fit for static analysis
- Safe type conversion, no silent errors
Quick start
Use existing typed values
use PhpTypedValues\Integer\IntegerPositive; $id = IntegerPositive::fromString('123');
Instead of spreading validation across an application
$id = (int) '123'; if ($id <= 0) { throw new InvalidArgumentException('Invalid ID'); }
Create an alias (in your domain)
use PhpTypedValues\Integer\IntegerPositive; readonly class Id extends IntegerPositive {} Id::fromInt(123);
Create composite objects
final readonly class Profile { public function __construct( private IntegerPositive $id, private StringUsername $username, private FloatPositive|Undefined $rating, ) {} }
Undefined
Prefer using the Undefined type over null to maintain consistency and improve type safety within the codebase.
Other usage examples docs/USAGE.md
Key features
- Idempotent conversion on fromString() > toString(): "1" > 1 > "1"
- Static analysis friendly
- Strict types
- Validation on construction; no invalid state
- Immutable, readonly objects
- No external runtime dependencies
- Easy to extend with your own types and composites
- Heavily tested
Performance note
- Objects vs Scalars:
- ~2.3× slower for large arrays of objects
- ~1.5× higher memory usage
- Use value objects for domain boundaries, validation, and clarity
- Use raw scalars in hot loops or large data processing paths
Documentation
- Development guide: docs/DEVELOP.md
- More usage examples in tests/Unit
Types structure
Types
├── ArrayType
│ ├── ArrayEmpty
│ ├── ArrayNonEmpty
│ ├── ArrayOfObjects
│ └── ArrayUndefined
├── Bool
│ ├── Alias
│ │ └── BooleanType
│ ├── Specific
│ │ ├── BoolSwitch
│ │ └── BoolToggle
│ ├── BoolStandard
│ ├── FalseStandard
│ └── TrueStandard
├── DateTime
│ ├── MariaDb
│ │ └── DateTimeSql
│ ├── Timestamp
│ │ ├── TimestampMicroseconds
│ │ ├── TimestampMilliseconds
│ │ └── TimestampSeconds
│ ├── DateIso8601
│ ├── DateTimeAtom
│ ├── DateTimeCookie
│ ├── DateTimeRFC1123
│ ├── DateTimeRFC2822
│ ├── DateTimeRFC3339
│ ├── DateTimeRFC3339Extended
│ ├── DateTimeW3C
│ └── TimeIso8601
├── Decimal
│ ├── Alias
│ │ └── Decimal
│ ├── Specific
│ │ ├──DecimalMoney
│ │ ├── DecimalPercent
│ │ └── DecimalProbability
│ ├── DecimalNegative
│ ├── DecimalNonNegative
│ ├── DecimalNonPositive
│ ├── DecimalNonZero
│ ├── DecimalPositive
│ ├── DecimalStandard
├── Float
│ ├── Alias
│ │ ├── DoubleType
│ │ └── FloatType
│ ├── Specific
│ │ ├── FloatPercent
│ │ └── FloatProbability
│ ├── FloatNegative
│ ├── FloatNonNegative
│ ├── FloatNonPositive
│ ├── FloatNonZero
│ ├── FloatPositive
│ └── FloatStandard
├── Integer
│ ├── Alias
│ │ └── IntegerType
│ ├── Specific
│ │ ├── IntegerAge
│ │ ├── IntegerDayOfMonth
│ │ ├── IntegerHour
│ │ ├── IntegerHttpStatusCode
│ │ ├── IntegerMinute
│ │ ├── IntegerMonth
│ │ ├── IntegerPercent
│ │ ├── IntegerPort
│ │ ├── IntegerSecond
│ │ ├── IntegerWeekDay
│ │ └── IntegerYear
│ ├── MariaDb
│ │ ├── IntegerBig
│ │ ├── IntegerBigUnsigned
│ │ ├── IntegerMedium
│ │ ├── IntegerMediumUnsigned
│ │ ├── IntegerNormal
│ │ ├── IntegerNormalUnsigned
│ │ ├── IntegerSmall
│ │ ├── IntegerSmallUnsigned
│ │ ├── IntegerTiny
│ │ └── IntegerTinyUnsigned
│ ├── IntegerNegative
│ ├── IntegerNonNegative
│ ├── IntegerPositive
│ └── IntegerStandard
├── String
│ ├── Alias
│ │ └── StringType
│ ├── MariaDb
│ │ ├── StringLongText
│ │ ├── StringMediumText
│ │ ├── StringText
│ │ ├── StringTinyText
│ │ └── StringVarChar255
│ ├── Specific
│ │ ├── StringBase64
│ │ ├── StringCountryCode
│ │ ├── StringCurrencyCode
│ │ ├── StringDomain
│ │ ├── StringEmail
│ │ ├── StringFileName
│ │ ├── StringHex
│ │ ├── StringIban
│ │ ├── StringIpV4
│ │ ├── StringIpV6
│ │ ├── StringJson
│ │ ├── StringJwt
│ │ ├── StringLanguageCode
│ │ ├── StringLocaleCode
│ │ ├── StringMacAddress
│ │ ├── StringMd5
│ │ ├── StringMimeType
│ │ ├── StringPath
│ │ ├── StringPhoneE164
│ │ ├── StringSemVer
│ │ ├── StringSha256
│ │ ├── StringSha512
│ │ ├── StringSlug
│ │ ├── StringUrl
│ │ ├── StringUrlPath
│ │ ├── StringUsername
│ │ ├── StringUuidV4
│ │ └── StringUuidV7
│ ├── StringEmpty
│ ├── StringNonBlank
│ ├── StringNonEmpty
│ └── StringStandard
└── Undefined
├── Alias
│ └── Undefined
└── UndefinedStandard
License
MIT