Download the PHP package philiprehberger/php-uuid-tools without Composer
On this page you can find all versions of the php package philiprehberger/php-uuid-tools. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download philiprehberger/php-uuid-tools
More information about philiprehberger/php-uuid-tools
Files in philiprehberger/php-uuid-tools
Package php-uuid-tools
Short Description UUID v4 and v7 generation, validation, and ordered UUIDs for database indexing
License MIT
Homepage https://github.com/philiprehberger/php-uuid-tools
Informations about the package php-uuid-tools
PHP UUID Tools
UUID v4, v5, and v7 generation, ULID support, short ID encoding, and ordered UUIDs for database indexing.
Requirements
- PHP 8.2+
Installation
Usage
Generate UUID v4
Generate UUID v7
Time-ordered UUIDs with millisecond precision, ideal for database primary keys:
Generate UUID v5
Deterministic namespace-based UUIDs using SHA-1 hashing:
ULID
Generate ULIDs (Universally Unique Lexicographically Sortable Identifiers):
Short IDs
Encode UUIDs as compact Base62 strings (~22 characters):
Validate a UUID
Extract Version
Binary Conversion
Convert between UUID strings and 16-byte binary for compact storage:
Ordered UUIDs
Reorder UUID fields for optimal database index performance. Puts the most-significant time bits first so UUIDs sort chronologically:
Batch Generation
Generate multiple UUIDs at once:
Comparison
Nil UUID
API
| Method | Description |
|---|---|
Uuid::v4(): string |
Generate a random UUID v4 |
Uuid::v5(string $namespace, string $name): string |
Generate a deterministic UUID v5 (SHA-1) |
Uuid::v7(): string |
Generate a time-ordered UUID v7 |
Uuid::isValid(string $uuid): bool |
Validate a UUID string (any version) |
Uuid::validateBatch(array $uuids): array |
Return indices of invalid UUIDs in a list |
Uuid::version(string $uuid): ?int |
Extract the version number (null if invalid) |
Uuid::toBytes(string $uuid): string |
Convert UUID to 16-byte binary |
Uuid::fromBytes(string $bytes): string |
Convert 16-byte binary to UUID string |
Uuid::toOrdered(string $uuid): string |
Reorder UUID for database index performance |
Uuid::fromOrdered(string $ordered): string |
Reverse an ordered UUID to standard format |
Uuid::equals(string $a, string $b): bool |
Case-insensitive UUID equality check |
Uuid::compareTo(string $a, string $b): int |
Lexicographic comparison (-1, 0, 1) for sorting |
Uuid::batch(int $count, int $version = 4): array |
Generate multiple UUIDs at once |
Uuid::nil(): string |
Return the nil UUID (all zeros) |
Uuid::ulid(): string |
Generate a ULID |
Uuid::isValidUlid(string $ulid): bool |
Validate a ULID string |
Uuid::toShortId(string $uuid): string |
Encode UUID as Base62 short ID |
Uuid::fromShortId(string $shortId): string |
Decode Base62 short ID to UUID |
Ulid::generate(): string |
Generate a new ULID |
Ulid::isValid(string $ulid): bool |
Validate a ULID string |
Ulid::toUuid(string $ulid): string |
Convert ULID to UUID format |
Ulid::fromUuid(string $uuid): string |
Convert UUID to ULID format |
Ulid::timestamp(string $ulid): int |
Extract Unix timestamp (ms) from ULID |
Ulid::toDateTime(string $ulid, ?\DateTimeZone $tz = null): \DateTimeImmutable |
Decode ULID timestamp into a DateTimeImmutable (UTC default) |
ShortId::encode(string $uuid): string |
Encode UUID as Base62 short ID |
ShortId::decode(string $shortId): string |
Decode Base62 short ID to UUID |
Development
Support
If you find this project useful:
License
MIT