2017 © Pedro Pelรกez
 

library niceid

PHP library to generate short, non-sequential, URL-friendly hashes of incremental IDs. Similar to YouTube (https://www.youtube.com/watch?v=dQw4w9WgXcQ) and Bitly (http://bit.ly/1D0CAzd) URLs.

image

diarmuidie/niceid

PHP library to generate short, non-sequential, URL-friendly hashes of incremental IDs. Similar to YouTube (https://www.youtube.com/watch?v=dQw4w9WgXcQ) and Bitly (http://bit.ly/1D0CAzd) URLs.

  • Monday, September 18, 2017
  • by diarmuidie
  • Repository
  • 2 Watchers
  • 9 Stars
  • 945 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 8 Versions
  • 1 % Grown

The README.md

diarmuidie/niceid

PHP library to generate short, non-sequential, URL-friendly hashes of incremental IDs. Similar to YouTube https://www.youtube.com/watch?v=dQw4w9WgXcQ and Bitly http://bit.ly/1D0CAzd URLs., (*1)

Developed by Diarmuid., (*2)

Latest Stable Version License Build Status SensioLabsInsight , (*3)

Features

  • Non-sequential IDs (i.e. difficult, but not impossible, to guess the next one).
  • URL friendly.
  • No external dependencies.
  • PSR-4 compatible.
  • Compatible with PHP >= 5.6

Installation

You can install NiceID through Composer:, (*4)

$ composer require diarmuidie/niceid

Usage

Generate an ID from a int:, (*5)

require 'vendor/autoload.php';

use Diarmuidie\NiceID\NiceID;

$niceid = new NiceID('Some Random Secret Value');
echo $niceid->encode(123); // uSdqd

Notice that a secret is passed to the NiceID constructor. This secret is used to encode and decode the IDs. If the secret changes then IDs cannot be decoded., (*6)

Use the decode method to decode the NiceID back to an int., (*7)

echo $niceid->decode('uSdqd'); // 123

You can also change the min length of the NiceID (Defaults to 5 if not specified):, (*8)

$niceid->setMinLength(10);
echo $niceid->encode(123); // uccccccu8p

To specify the characters to use in the encoded string use the setCharacters() method., (*9)

$niceid->setCharacters('abcde');
echo $niceid->encode(123); // adcce

The default character set is: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_, (*10)

You can even specify a UTF-8 character set if you want:, (*11)

$niceid->setCharacters('โ“โ“‘โ“’โ““โ“”โ“•โ“–โ“—โ“˜โ“™โ“šโ“›โ“œโ“โ“žโ“Ÿโ“ โ“กโ“ขโ“ฃโ“คโ“ฅโ“ฆโ“งโ“จโ“ฉ');
echo $niceid->encode(123); // โ“–โ“‘โ“ฅโ“˜โ“˜โ“ 

To Do

  • [x] Add library to packagist.
  • [x] Setup Travis to run unit tests.
  • [x] Better handle UTF-8 chars in character string.
  • [x] 100% Code coverage for unit tests.
  • [x] Refactor BaseConvert::convert() method.
  • [x] Handle PHP_INT_MAX overflow.
  • [ ] Implement BCMath support for integers larger than PHP_INT_MAX.
  • [x] Setup Drone.io to run unit tests.

Contributing

Feel free to contribute features, bug fixes or just helpful advice :smile:, (*12)

  1. Fork this repo
  2. Create a feature branch
  3. Submit a PR ...
  4. Profit :sunglasses:

Changelog

See the CHANGELOG.md file., (*13)

Authors

License

The MIT License (MIT), (*14)

Copyright (c) 2015 Diarmuid, (*15)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:, (*16)

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software., (*17)

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE., (*18)

The Versions

18/09 2017

dev-master

9999999-dev http://github.com/diarmuidie/niceid

PHP library to generate short, non-sequential, URL-friendly hashes of incremental IDs. Similar to YouTube (https://www.youtube.com/watch?v=dQw4w9WgXcQ) and Bitly (http://bit.ly/1D0CAzd) URLs.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

id hash obfuscate url friendly

18/09 2017

v1.1.0

1.1.0.0 http://github.com/diarmuidie/niceid

PHP library to generate short, non-sequential, URL-friendly hashes of incremental IDs. Similar to YouTube (https://www.youtube.com/watch?v=dQw4w9WgXcQ) and Bitly (http://bit.ly/1D0CAzd) URLs.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

id hash obfuscate url friendly

18/09 2017

dev-new-release-php-5-4

dev-new-release-php-5-4 http://github.com/diarmuidie/niceid

PHP library to generate short, non-sequential, URL-friendly hashes of incremental IDs. Similar to YouTube (https://www.youtube.com/watch?v=dQw4w9WgXcQ) and Bitly (http://bit.ly/1D0CAzd) URLs.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

id hash obfuscate url friendly

27/08 2015

v1.0.0

1.0.0.0 http://github.com/diarmuidie/niceid

PHP library to generate short, non-sequential, URL-friendly hashes of incremental IDs. Similar to YouTube (https://www.youtube.com/watch?v=dQw4w9WgXcQ) and Bitly (http://bit.ly/1D0CAzd) URLs.

  Sources   Download

MIT

The Development Requires

id hash obfuscate url friendly

16/05 2015

v0.2.2

0.2.2.0 http://github.com/diarmuidie/niceid

Convert numeric ID to non-sequential short URL-friendly IDs

  Sources   Download

MIT

The Development Requires

id url friendly

06/04 2015

v0.2.1

0.2.1.0 http://github.com/diarmuidie/niceid

Convert numeric ID to non-sequential short URL-friendly IDs

  Sources   Download

MIT

The Development Requires

id url friendly

28/03 2015

v0.2.0

0.2.0.0 http://github.com/diarmuidie/niceid

Convert numeric ID to non-sequential short URL-friendly IDs

  Sources   Download

MIT

The Development Requires

id url friendly

23/03 2015

0.1.0

0.1.0.0 http://github.com/diarmuidie/niceid

Convert numeric ID to non-sequential short URL-friendly IDs

  Sources   Download

MIT

The Development Requires

id url friendly