PHP code example of nice-yu / unique-code

1. Go to this page and download the library: Download nice-yu/unique-code 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/ */

    

nice-yu / unique-code example snippets


use NiceYu\UniqueCode\UniqueCode;

UniqueCode::setSeedNumber(0)
    ->setDictionaries([
        '2', '3', '4', '5', '6', '7', '8', '9',
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
        'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R',
        'S', 'T', 'U', 'V', 'W', 'X'
    ])
    ->setComplement(['Y', 'Z'])
    ->setMax(6);

use NiceYu\UniqueCode\UniqueCode;

UniqueCode::getSeedNumber();
UniqueCode::getDictionaries();
UniqueCode::getComplement();
UniqueCode::getMax();

use NiceYu\UniqueCode\UniqueCode;

$id = 123456789;
$code = UniqueCode::encode($id); // Generate
$decodedId = UniqueCode::decode($code); // Reverse

$id = 12345;
$code = unique_encode($id); // Generate
$decodedId = unique_decode($code); // Reverse
sh
PHPUnit 9.6.0 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.4
Configuration: /var/www/packages/unique-code/phpunit.xml

Functions (NiceYu\Tests\Functions)
 ✔ Unique encode [1.34 ms]
 ✔ Unique decode [17.30 ms]

Unique Code (NiceYu\Tests\UniqueCode)
 ✔ Getters [0.17 ms]
 ✔ Encode decode consistency [0.21 ms]
 ✔ Encode with max length [3.46 ms]
 ✔ Encode exceeding max [1.02 ms]
 ✔ Invalid decode [0.13 ms]
 ✔ Set seed number [0.15 ms]
 ✔ Set dictionaries [1.03 ms]
 ✔ Set complement [0.13 ms]
 ✔ Set max [0.12 ms]

Time: 00:00.040, Memory: 8.00 MB

OK (11 tests, 20 assertions)