Download the PHP package martijnvdb/type-vault without Composer
On this page you can find all versions of the php package martijnvdb/type-vault. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download martijnvdb/type-vault
More information about martijnvdb/type-vault
Files in martijnvdb/type-vault
Package type-vault
Short Description Validated types for PHP: Email, UUID, URL, and more
License MIT
Homepage https://github.com/martijnvdb87/type-vault-php
Informations about the package type-vault
๐ Type Vault
Type Vault is a PHP utility package that provides robust and validated types for common structured values like UUIDs, URLs, ISO date-times, hex colors, and more. It helps enforce correctness at runtime while maintaining strong typing.
โจ Features
- โ Runtime and compile time validation
- ๐งช Built-in helpers for immutability
- ๐ Types are
\Stringableand\JsonSerializable
๐ฆ Installation
Install Type Vault from Packagist using Composer:
๐งโ๐ป How to use
๐ฅ Basic Usage
Create a validated Email instance and access or update its value:
๐ Immutable Variant
Use ::immutable() or pass new TypeOptionsDTO(immutable: true) to prevent value changes after initialization:
๐จ Error Types
All validation-related errors extend TypeVaultValidationError.
InvalidValueError- Thrown when a value fails validation.ImmutableValueError- Thrown when mutating an immutable type value.InvalidPropertyError- Thrown when updating a non-existing DTO property (e.g. incopyWith).InvalidTypeError- Thrown for mismatched types in utilities likeCollection.
๐งฐ Supported Types
Type Vault offers a rich set of validated types. Each type enforces strict formatting and value constraints at runtime, and all values are stored in a normalized form to ensure consistency and predictability across your application.
๐จ Color Types
For working with color values in various formats:
ColorHexโ Hexadecimal color code (e.g.'#ffcc00ff','#ffcc00'or'#fc0')ColorRgbโ RGB color object (e.g.'rgb(255 128 0 / 100%)','rgb(255, 128, 0)'or'rgb(255 128 0 / 1)')ColorHslโ HSL color object (e.g.'hsl(360 0 0 / 1)'or'hsl(360deg 0% 0% / 100%)')ColorOklchโ OKLCH color object (e.g.'oklch(70 0.4 120deg / 25%)','oklch(70% 100% 120deg / 0.25)'or'oklch(0.7 0.4 120 / 25%)')
๐ Temporal Types
For representing and validating time-related values:
DateOnlyโ ISO date string without time (e.g.'2023-01-02'or'2023-1-2')DateTimeโ ISO UTC date-time string (e.g.'2023-01-02T01:23:45.123Z'or'2023-01-02T01:23:45Z')TimeOnlyโ ISO time string without date (e.g.'01:23:45.123'or'01:23:45')Durationโ ISO 8601 duration string (e.g.'PT1H30M')Monthโ Valid month name or number (e.g.'january'ordecember)Weekdayโ Valid weekday name (e.g.'monday')Yearโ Valid four-digit year (e.g.'2025')
๐ Communication Types
For validating contact and identity formats:
Emailโ RFC-compliant email address (e.g.'[email protected]')PhoneNumberโ E.164 formatted phone number (e.g.'+31612345678')
โ๏ธ Text & Numeric Types
For structured text, numbers, and identifiers:
Textโ A valid text string (e.g.'foo','Lorem ipsum dolor sit amet'or'')Integerโ Whole number (e.g.42)FloatingPointโ Decimal number (e.g.3.14)Percentageโ Decimal number between 0 and 1 (e.g.0,0.5or1)Urlโ Valid absolute URL (e.g.'https://example.com')Uuidโ RFC 4122 UUID string (e.g.'550e8400-e29b-41d4-a716-446655440000')