PHP code example of projectsaturnstudios / quickuuid

1. Go to this page and download the library: Download projectsaturnstudios/quickuuid library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

projectsaturnstudios / quickuuid example snippets




nerate a UUIDv4
$uuid4 = new_uuid4();
echo "UUIDv4: $uuid4\n";

// --- UUIDv5 Generation ---

// Define a name for your UUIDv5
$name = 'com.example.myapp.someidentifier';

// Generate a UUIDv5 using the default namespace
// The default namespace is `Ramsey\Uuid\Uuid::NAMESPACE_DNS` unless you define
// the `QUICKUUID_DEFAULT_V5_NAMESPACE` constant before this helper file is loaded.
$uuid5_default_ns = new_uuid5($name);
echo "UUIDv5 (default NS): $uuid5_default_ns\n";

// Generate a UUIDv5 with a custom namespace
$customNamespace = 'a1b2c3d4-e5f6-7788-9900-aabbccddeeff'; // Replace with your actual valid UUID namespace
if (Ramsey\Uuid\Uuid::isValid($customNamespace)) {
    $uuid5_custom_ns = new_uuid5($name, $customNamespace);
    echo "UUIDv5 (custom NS - '{$customNamespace}'): $uuid5_custom_ns\n";
} else {
    echo "Custom namespace '{$customNamespace}' is not a valid UUID.\n";
}

// --- General Purpose new_uuid() Helper ---

// No name provided, so it generates a UUIDv4
$another_uuid4 = new_uuid(); 
echo "Another UUIDv4: $another_uuid4\n";

// Name provided, so it generates a UUIDv5 with the default namespace
$another_uuid5_default_ns = new_uuid($name);
echo "Another UUIDv5 (default NS): $another_uuid5_default_ns\n";

// Name and custom namespace provided for UUIDv5 generation
if (Ramsey\Uuid\Uuid::isValid($customNamespace)) {
    $another_uuid5_custom_ns = new_uuid($name, $customNamespace); 
echo "Another UUIDv5 (custom NS - '{$customNamespace}'): $another_uuid5_custom_ns\n";
}


if (!defined('QUICKUUID_DEFAULT_V5_NAMESPACE')) {
    define('QUICKUUID_DEFAULT_V5_NAMESPACE', 'YOUR-OWN-DEFAULT-NAMESPACE-UUID'); // Replace with your actual UUID
}

// Composer will then load quickuuid's helpers, which will use this constant.
bash
composer analyse