2017 © Pedro Peláez
 

library keypack

Pack/unpack integer and GUID keys to shorter strings

image

mindplay/keypack

Pack/unpack integer and GUID keys to shorter strings

  • Monday, August 15, 2016
  • by mindplay.dk
  • Repository
  • 1 Watchers
  • 2 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

mindplay/keypack

This library packs integer, UUID and GUID keys to shorter strings, e.g. for use in user-facing URLs., (*1)

PHP Version Build Status, (*2)

Usage

Three classes, IntPacker, UUIDPacker and GUIDPacker are provided, each capable of packing/unpacking a particular type of ID. Each class has essentially the same interface, but accepting/returning different types of keys., (*3)

Here's an example of packing/unpacking a UUID to a shorter string:, (*4)

$packer = new UUIDPacker();

echo $packer->pack("7eb6de1e-65ef-4fb7-baff-c0732c1c4614"); // => "py6dWN6dgKR8cGVz73zDiT"

echo $packer->unpack("py6dWN6dgKR8cGVz73zDiT"); // => "7eb6de1e-65ef-4fb7-baff-c0732c1c4614" 

You can pack keys using different notations. The default is legible, which produces human-readable and reasonably short keys - see here for more options., (*5)

You can also add redundancy to packed keys, to prevent typos make it harder to guess a packed key., (*6)

Here's an example packing an integer key to base64 with 4 bytes of redundancy:, (*7)

$packer = new IntPacker('base64');

$packer->setRedundancy(4, 'super secret salt');

echo $packer->pack(123456); // => "7yg6HR"

echo $packer->unpack("7yg6HR"); // => (int) 123456

Note that unpack() will return null if the redundancy check fails., (*8)

The Versions

15/08 2016

dev-master

9999999-dev

Pack/unpack integer and GUID keys to shorter strings

  Sources   Download

MIT

The Requires

 

The Development Requires

15/08 2016

1.0.0

1.0.0.0

Pack/unpack integer and GUID keys to shorter strings

  Sources   Download

MIT

The Requires

 

The Development Requires