2017 © Pedro PelĂĄez
 

library shortid-php

An implementation of shortid in PHP

image

pugx/shortid-php

An implementation of shortid in PHP

  • Sunday, July 22, 2018
  • by garak
  • Repository
  • 11 Watchers
  • 32 Stars
  • 10,222 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 7 Forks
  • 0 Open issues
  • 8 Versions
  • 30 % Grown

The README.md

ShortId

Latest Stable Version Total Downloads PHP Version Require Build Status Code Climate Test Coverage codecov License, (*1)

This library is an implementation of ShortId for PHP., (*2)

Installation

Install the library via Composer:, (*3)

composer require pugx/shortid-php

Usage

ShortId is a PHP library that generates short, unique, and random strings. It's useful in scenarios where you need concise identifiers, such as URL shortening or generating unique keys., (*4)

Basic usage

Just call PUGX\Shortid\Shortid::generate() to get a random string with default length 7, like "MfiYIvI"., (*5)

``` php use PUGX\Shortid\Shortid;, (*6)

require_once DIR.'/vendor/autoload.php';, (*7)

$id = Shortid::generate();, (*8)


## Advanced usage For more control, you can customize the alphabet and length using the Factory class. The default alphabet uses all letters (lowercase and uppercase), all numbers, underscore, and hyphen. ``` php use PUGX\Shortid\Factory; use PUGX\Shortid\Shortid; require_once __DIR__.'/vendor/autoload.php'; $factory = new Factory(); // alphabet string must be 64 characters long $factory->setAlphabet('Ă©123456789Ă bcdefghĂŹjklmnĂČpqrstĂčvwxyzABCDEFGHIJKLMNOPQRSTUVWX.!@|'); // length must be between 2 and 20 (default is 7) // of course, a lower length increases the clashing probability $factory->setLength(9); Shortid::setFactory($factory); $id = Shortid::generate();

As an alternative, you can customize single generations:, (*9)

``` php use PUGX\Shortid\Shortid;, (*10)

require_once DIR.'/vendor/autoload.php';, (*11)

$id9 = Shortid::generate(9, 'Ă©123456789Ă bcdefghĂŹjklmnĂČpqrstĂčvwxyzABCDEFGHIJKLMNOPQRSTUVWX.!@|'); $id5 = Shortid::generate(5);, (*12)


## More readable strings Sometimes, you want to avoid some ambiguous characters, like `B`/`8` or `I`/`l` (uppercase/lowercase). In this case, you can pass a third parameter `true` to `generate` method. Notice that in this case the alphabet will be ignored, so it makes sense to pass a null one. Example: ``` php use PUGX\Shortid\Shortid; require_once __DIR__.'/vendor/autoload.php'; $id = Shortid::generate(7, null, true);

Pre-defined values

If you need a deterministic string, instead of a random one, you can call directly the class constructor. This could be useful, for instance, when you need pre-defined data for testing purposes., (*13)

``` php use PUGX\Shortid\Shortid;, (*14)

require_once DIR.'/vendor/autoload.php';, (*15)

$myFixedId = new Shortid('5h0r71d'); $anotherFixedId = new Shortid('fooBarZ');, (*16)

```, (*17)

Doctrine

If you want to use ShortId with Doctrine ORM, take a look at ShortId Doctrine type., (*18)

Doctrine and Symfony

If you want to use ShortId with Doctrine ORM and Symfony framework, take a look to ShortId Doctrine type bundle., (*19)

Dependencies replacement

This library uses a polyfill, so it can be used in environments where the mbstring native extension is not available., (*20)

If, instead, your environment is offering that extension, you can avoid installing that polyfill by configuring a replace entry in your composer.json., (*21)

The same applies to the randomLib library: if you are using PHP 8.3 or higher, you can replace it, since this library uses the native Random class instead., (*22)

Contributing

Contributions are welcome. Feel free to open a Pull Request or file an issue here on GitHub! Please read the [contributing guidelines][7] first., (*23)

The Versions

22/07 2018

dev-master

9999999-dev http://pugx.org/

An implementation of shortid in PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

uuid id shortid

10/06 2018

v0.5.0

0.5.0.0 http://pugx.org/

An implementation of shortid in PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

uuid id shortid

08/02 2018

v0.4.0

0.4.0.0 http://pugx.org/

An implementation of shortid in PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

uuid id shortid

29/09 2017

v0.3.1

0.3.1.0 http://pugx.org/

An implementation of shortid in PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

uuid id shortid

08/08 2017

v0.3.0

0.3.0.0 http://pugx.org/

An implementation of shortid in PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

uuid id shortid

19/03 2017

v0.2.1

0.2.1.0 http://pugx.org/

An implementation of shortid in PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

uuid id shortid

04/01 2017

v0.2.0

0.2.0.0 http://pugx.org/

An implementation of shortid in PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

uuid id shortid

27/02 2016

v0.1.0

0.1.0.0 http://pugx.org/

An implementation of shortid in PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

uuid id shortid