PHP code example of thamtech / yii2-uuid

1. Go to this page and download the library: Download thamtech/yii2-uuid 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/ */

    

thamtech / yii2-uuid example snippets


$uuid = \thamtech\uuid\helpers\UuidHelper::uuid();

$uuid = 'de305d54-75b4-431b-adb2-eb6b9e546014';
$isValid = \thamtech\uuid\helpers\UuidHelper::isValid($uuid); // true

$uuid = 'not-a-uuid';
$isValid = \thamtech\uuid\helpers\UuidHelper::isValid($uuid); // false

// or using the Validator class directly
$validator = new \thamtech\uuid\validators\UuidValidator();
if ($validator->validate($uuid, $error)) {
    // valid
} else {
    // not valid
    echo $error
}

use thamtech\uuid\helpers\UuidHelper;
use thamtech\uuid\helpers\UuidValidator;

// ...

$uuid = 'de305d54-75b4-431b-adb2-eb6b9e546014';
$isValid = UuidHelper::isValid($uuid); // true

$uuid = 'not-a-uuid';
$isValid = UuidHelper::isValid($uuid); // false

// or using the Validator class directly
$validator = new UuidValidator();
if ($validator->validate($uuid, $error)) {
    // valid
} else {
    // not valid
    echo $error
}

public function rules()
{
    return [
        [['uuid'], 'thamtech\uuid\validators\UuidValidator'],
    ];
}