Coder Social home page Coder Social logo

cakephp-hashid's Introduction

Hashid Plugin for CakePHP

Build Status Coverage Status Latest Stable Version Minimum PHP Version License Total Downloads Coding Standards

Exposes hashids as drop-in replacement for your numeric primary keys.

A CakePHP 3.x 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)

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.

Demo

See http://sandbox.dereuromark.de/sandbox/hashids

Setup

composer require dereuromark/cakephp-hashid

and

bin/cake plugin load Hashid

Usage

See Documentation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.