2017 © Pedro Peláez
 

cakephp-plugin cakephp-hashid

A CakePHP plugin to allow using hashids instead of numeric primary keys.

image

dereuromark/cakephp-hashid

A CakePHP plugin to allow using hashids instead of numeric primary keys.

  • Friday, April 20, 2018
  • by dereuromark
  • Repository
  • 3 Watchers
  • 34 Stars
  • 3,078 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 7 Forks
  • 2 Open issues
  • 13 Versions
  • 12 % Grown

The README.md

Hashid Plugin for CakePHP

Build Status Coverage Status Latest Stable Version Minimum PHP Version License Total Downloads Coding Standards, (*1)

Exposes hashids as drop-in replacement for your numeric primary keys., (*2)

DEPRECATED This plugin is deprecated in favor of the more robust and future proof solution through exposing a dedicated field. See Expose plugin., (*3)

A CakePHP plugin to

  • cloak the actual numeric primary key behind the record (assuming you use a non public salt) for URLs, APIs and alike
  • build short unique IDs (Even PHP_INT_MAX 2.147.483.647 becomes lXQAALg for example, so length <= 7 for the hashid)

This branch is for use with CakePHP 3.6+. See version map for details., (*4)

Why hashids?

  • They are super short, especially for the URL
  • They are lightweight and fast. They work on the fly and require no table fields, no code changes. No overhead involved except for enabling the behavior.
  • You do not lose sorting capability as with UUIDs.
  • You can use hashids if you do not want to expose your database ids to the user - while not compromising speed - as a balance trait-off.

Why not UUIDS?

  • UUIDs can be up to 200x slower with growing DB tables, complex or heavy joins and especially with CakePHP default char(36). But even with the recommended binary(16) it would not be ideal.
  • UUIDS often times completely replace the primary key, making it impossible to sort anymore on those records. This is especially problematic with data that gets inserted at the same time (same datetime for created).
  • UUIDS are often used to just cloak the numeric primary keys visibility of how much gets inserted over time. But that is not what they should be used for. If you want to synch data across DBs, then they are useful. But they should not be abused for other things.

UPDATE This is actually not true if you combine both AIID and UUIDs and use UUIDs only for external lookup but keep AIID for all internal joins and operations. As such the Expose plugin fully replaces this now., (*5)

Demo

See https://sandbox3.dereuromark.de/sandbox/hashids, (*6)

Setup

composer require dereuromark/cakephp-hashid

and, (*7)

bin/cake plugin load Hashid

Usage

See Documentation., (*8)

Alternatives

See this nice article on a different approach that would use both -allowing "int" for internal and "uuid" for external reference., (*9)

The Versions

20/04 2018

dev-master

9999999-dev https://github.com/dereuromark/cakephp-hashid

A CakePHP plugin to allow using hashids instead of numeric primary keys.

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin cakephp behavior hashids

04/12 2017

1.2.1

1.2.1.0 https://github.com/dereuromark/cakephp-hashid

A CakePHP plugin to allow using hashids instead of numeric primary keys.

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin cakephp behavior hashids

15/09 2017

dev-master-exists

dev-master-exists https://github.com/dereuromark/cakephp-hashid

A CakePHP plugin to allow using hashids instead of numeric primary keys.

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin cakephp behavior hashids

21/02 2017

1.2.0

1.2.0.0 https://github.com/dereuromark/cakephp-hashid

A CakePHP plugin to allow using hashids instead of numeric primary keys.

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin cakephp behavior hashids

21/07 2016

1.1.3

1.1.3.0 https://github.com/dereuromark/cakephp-hashid

A CakePHP plugin to allow using hashids instead of numeric primary keys.

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin cakephp behavior hashids

29/04 2016

1.1.2

1.1.2.0 https://github.com/dereuromark/cakephp-hashid

A CakePHP plugin to allow using hashids instead of numeric primary keys.

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin cakephp behavior hashids

25/04 2016

1.1.1

1.1.1.0 https://github.com/dereuromark/cakephp-hashid

A CakePHP plugin to allow using hashids instead of numeric primary keys.

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin cakephp behavior hashids

25/04 2016

1.1.0

1.1.0.0 https://github.com/dereuromark/cakephp-hashid

A CakePHP plugin to allow using hashids instead of numeric primary keys.

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin cakephp behavior hashids

14/02 2016

1.0.0

1.0.0.0 https://github.com/dereuromark/cakephp-hashid

A CakePHP plugin to allow using hashids instead of numeric primary keys.

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin cakephp behavior hashids

19/01 2016

0.4

0.4.0.0 https://github.com/dereuromark/cakephp-hashid

A CakePHP plugin to allow using hashids instead of numeric primary keys.

  Sources   Download

MIT

The Requires

 

plugin cakephp behavior hashids

19/01 2016

0.3

0.3.0.0 https://github.com/dereuromark/cakephp-hashid

A CakePHP plugin to allow using hashids instead of numeric primary keys.

  Sources   Download

MIT

The Requires

 

plugin cakephp behavior hashids

18/01 2016

0.2

0.2.0.0 https://github.com/dereuromark/cakephp-hashid

A CakePHP plugin to allow using hashids instead of numeric primary keys.

  Sources   Download

MIT

The Requires

 

plugin cakephp behavior hashids

18/01 2016

0.1

0.1.0.0 https://github.com/dereuromark/cakephp-hashid

A CakePHP plugin to allow using hashids instead of numeric primary keys.

  Sources   Download

MIT

The Requires

 

plugin cakephp behavior hashids