2017 © Pedro Peláez
 

library shortuuid-php

image

pyyoshi/shortuuid-php

  • Wednesday, December 6, 2017
  • by PyYoshi
  • Repository
  • 1 Watchers
  • 5 Stars
  • 2,814 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 1 Open issues
  • 9 Versions
  • 13 % Grown

The README.md

shortuuid-php

Build Status Build Status, (*1)

The PHP implementation of shortuuid., (*2)

Installation

composer require pyyoshi/shortuuid-php

or add this library in your composer.json, (*3)

{
    "require": {
        "pyyoshi/shortuuid-php": "*"
    }
}

Usage

import, (*4)

require dirname(__DIR__) . "/vendor/autoload.php";
require_once 'ShortUUID/Autoloader.php';
\ShortUUID\Autoloader::register();

You can then generate a short UUID:, (*5)

use ShortUUID\ShortUUID;

$su = new ShortUUID();
$su->uuid();
=> "rkQdp5ikpXjraCsrSaysaT"

If you prefer a version 5 UUID, you can pass a name (DNS or URL) to the call and it will be used as a namespace (uuid.NAMESPACE_DNS or uuid.NAMESPACE_URL) for the resulting UUID:, (*6)

use ShortUUID\ShortUUID;

$su = new ShortUUID();
$su->uuid('example.com');
=> "wpsWLdLt9nscn2jbTD3uxe"
$su->uuid('http://www.example.com/');
=> "VSPugLzk4dD4WC7yfAQUzn"

To see the alphabet that is being used to generate new UUIDs:, (*7)

use ShortUUID\ShortUUID;

$su = new ShortUUID();
$su->getAlphabet();
=> "23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"

If you want to use your own alphabet to generate UUIDs, use setAlphabet():, (*8)

use ShortUUID\ShortUUID;

$su = new ShortUUID();
$su->setAlphabet('aaaaabcdefgh1230123');
$su->uuid();
=> "ee120aeh2h3bb010fdfedef2c03efcf3h1ca"

shortuuid-php will automatically sort and remove duplicates from your alphabet to ensure consistency:, (*9)

use ShortUUID\ShortUUID;

$su = new ShortUUID();
$su->setAlphabet('aaaaabcdefgh1230123');
$su->getAlphabet();
=> "0123abcdefgh"

If the default 22 digits are too long for you, you can get shorter IDs by just truncating the string to the desired length. The IDs won't be universally unique any longer, but the probability of a collision will still be very low., (*10)

To serialize existing UUIDs, use encode() and decode():, (*11)

use Ramsey\Uuid\Uuid;
use ShortUUID\ShortUUID;

$u = Uuid::uuid4();
$su = new ShortUUID();
$s = $su->encode($u);

$su->decode($s) == $u;
=> true

License

shortuuid-php is distributed under the BSD license., (*12)

The Versions

06/12 2017

dev-master

9999999-dev https://github.com/PyYoshi/shortuuid-php

  Sources   Download

BSD

The Requires

 

The Development Requires

uuid identifier guid

06/12 2017

1.0.7

1.0.7.0 https://github.com/PyYoshi/shortuuid-php

  Sources   Download

BSD

The Requires

 

The Development Requires

uuid identifier guid

21/01 2017

1.0.6

1.0.6.0 https://github.com/PyYoshi/shortuuid-php

  Sources   Download

BSD

The Requires

 

The Development Requires

uuid identifier guid

21/01 2017

1.0.5

1.0.5.0 https://github.com/PyYoshi/shortuuid-php

  Sources   Download

BSD

The Requires

 

The Development Requires

uuid identifier guid

01/12 2015

1.0.4

1.0.4.0 https://github.com/PyYoshi/shortuuid-php

  Sources   Download

BSD

The Requires

 

The Development Requires

uuid identifier guid

12/10 2015

1.0.3

1.0.3.0 https://github.com/PyYoshi/shortuuid-php

  Sources   Download

BSD

The Requires

 

The Development Requires

uuid identifier guid

12/10 2015

1.0.2

1.0.2.0 https://github.com/PyYoshi/shortuuid-php

  Sources   Download

BSD

The Requires

 

The Development Requires

uuid identifier guid

24/06 2015

1.0.1

1.0.1.0 https://github.com/PyYoshi/shortuuid-php

  Sources   Download

BSD

The Requires

 

The Development Requires

uuid identifier guid

11/02 2015

1.0.0

1.0.0.0 https://github.com/PyYoshi/shortuuid-php

  Sources   Download

BSD

The Requires

 

The Development Requires

uuid identifier guid