PHPackages                             martijnvdb/type-vault - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. martijnvdb/type-vault

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

martijnvdb/type-vault
=====================

Validated types for PHP: Email, UUID, URL, and more

0.2.0(3w ago)13↓50%MITPHP

Since Jun 14Pushed 1w agoCompare

[ Source](https://github.com/martijnvdb87/type-vault-php)[ Packagist](https://packagist.org/packages/martijnvdb/type-vault)[ Docs](https://github.com/martijnvdb87/type-vault-php)[ RSS](/packages/martijnvdb-type-vault/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (8)Versions (4)Used By (0)

🔒 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
----------

[](#-features)

- ✅ Runtime and compile time validation
- 🧪 Built-in helpers for immutability
- 🔁 Types are `\Stringable` and `\JsonSerializable`

📦 Installation
--------------

[](#-installation)

Install Type Vault from Packagist using Composer:

```
composer require martijnvdb/type-vault
```

🧑‍💻 How to use
--------------

[](#‍-how-to-use)

### 📥 Basic Usage

[](#-basic-usage)

Create a validated `Email` instance and access or update its value:

```
use Martijnvdb\TypeVault\Types\Email;

$email = new Email("user@example.com");
echo $email->value; // 'user@example.com'

// Update the value with another valid email
$email->value = "foo@bar.com";
echo $email->value; // 'foo@bar.com'
```

### 🔒 Immutable Variant

[](#-immutable-variant)

Use `::immutable()` or pass `new TypeOptionsDTO(immutable: true)` to prevent value changes after initialization:

```
use Martijnvdb\TypeVault\DTOs\TypeOptionsDTO;
use Martijnvdb\TypeVault\Errors\ImmutableValueError;
use Martijnvdb\TypeVault\Errors\TypeVaultValidationError;
use Martijnvdb\TypeVault\Types\Email;

$immutable = Email::immutable("user@example.com");
// Or:
$immutable = new Email("user@example.com", new TypeOptionsDTO(immutable: true));

echo $immutable->value; // 'user@example.com'

try {
	$immutable->value = "another@example.com"; // ❌
} catch (ImmutableValueError $error) {
	// Specific immutable mutation error
} catch (TypeVaultValidationError $error) {
	// Fallback for any Type Vault validation error
}
```

### 🚨 Error Types

[](#-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. in `copyWith`).
- `InvalidTypeError` - Thrown for mismatched types in utilities like `Collection`.

🧰 Supported Types
-----------------

[](#-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

[](#-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

[](#-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'` or `december`)
- `Weekday` – Valid weekday name (e.g. `'monday'`)
- `Year` – Valid four-digit year (e.g. `'2025'`)

### 🌐 Communication Types

[](#-communication-types)

For validating contact and identity formats:

- `Email` – RFC-compliant email address (e.g. `'user@example.com'`)
- `PhoneNumber` – E.164 formatted phone number (e.g. `'+31612345678'`)

### ✏️ Text &amp; Numeric Types

[](#️-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.5` or `1`)
- `Url` – Valid absolute URL (e.g. `'https://example.com'`)
- `Uuid` – RFC 4122 UUID string (e.g. `'550e8400-e29b-41d4-a716-446655440000'`)

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance97

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity26

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~10 days

Total

3

Last Release

26d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16452270?v=4)[martijnvdb](/maintainers/martijnvdb)[@MartijnvdB](https://github.com/MartijnvdB)

---

Top Contributors

[![martijnvdb87](https://avatars.githubusercontent.com/u/41451264?v=4)](https://github.com/martijnvdb87 "martijnvdb87 (87 commits)")

---

Tags

urlvalidationValue Objectemailcoloruuidcollectionimmutabletype-safedate-timestrict typestyped-collectionruntime-validationData Modelingutility-typesnormalized-valuesdate-onlytime-onlytype-vault

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/martijnvdb-type-vault/health.svg)

```
[![Health](https://phpackages.com/badges/martijnvdb-type-vault/health.svg)](https://phpackages.com/packages/martijnvdb-type-vault)
```

###  Alternatives

[egulias/email-validator

A library for validating emails against several RFCs

11.6k734.8M453](/packages/egulias-email-validator)[stymiee/email-validator

A robust PHP 7.4+ email validation library that extends beyond basic validation with MX record checks, disposable email detection, and free email provider validation. Features include strict typing, custom validator support, internationalization (i18n), and an extensible architecture. Perfect for applications requiring thorough email verification with customizable validation rules.

33487.3k1](/packages/stymiee-email-validator)[erag/laravel-disposable-email

A Laravel package to detect and block disposable email addresses.

254168.5k](/packages/erag-laravel-disposable-email)[neverbounce/neverbounce-php

This package provides convenient methods to integrate the NeverBounce API into your project.

241.2M3](/packages/neverbounce-neverbounce-php)[osiemsiedem/laravel-autolink

A Laravel package for converting URLs in a given string of text into clickable links.

13139.9k](/packages/osiemsiedem-laravel-autolink)[kouz/laravel-mailgun-email-validation

Laravel email validation that uses the Mailgun API for a three-step validation check.

11145.0k1](/packages/kouz-laravel-mailgun-email-validation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
