UUID (Universally Unique Identifiers)

The artiframe add uuid command installs the standard ramsey/uuid package, used for generating Universally Unique Identifiers (UUID) in PHP. It is perfect for generating order numbers (Order ID) in a database, user tokens, or non-sequential hidden identities.

💡 Information: Direct Usage
ArtiFrame does not copy a specific integration (Wrapper/Stub) class to the src/Service folder for this package. The installation simply includes the package into the project via Composer. The codes below are basic usage examples demonstrating the package's native operations. For more information, please review the Ramsey UUID Documentation.
Installation
terminal
$ artiframe add uuid
Usage Example
OrderService.php
<?php

use Ramsey\Uuid\Uuid;

// 1. Generate a random UUIDv4 (The most preferred version)
$uuid4 = Uuid::uuid4();
echo "Your Order Number: " . $uuid4->toString(); 
// Output Example: 25769c6c-d34d-4bfe-ba98-e0ee856f3e7a


// 2. Generate a time-based UUIDv1 (Provides sorting advantages)
$uuid1 = Uuid::uuid1();
echo "Log ID: " . $uuid1->toString(); 
// Output Example: e4eaaaf2-d142-11e1-b3e4-080027620cdd


// 3. Parse and Validate an Existing String UUID
$stringUuid = '25769c6c-d34d-4bfe-ba98-e0ee856f3e7a';

if (Uuid::isValid($stringUuid)) {
    $parsedUuid = Uuid::fromString($stringUuid);
    echo "<br>Yes, this is a valid UUID. Version: " . $parsedUuid->getFields()->getVersion();
} else {
    echo "<br>Invalid UUID format!";
}