blake/laraveldoctrine-hashids

Hashid type for Doctrine
89 10
Install
composer require blake/laraveldoctrine-hashids
Latest Version:v1.0.1
PHP:>=5.5.9
License:MIT
Last Updated:Feb 27, 2016
Links: GitHub  ·  Packagist
Maintainer: Panoptisis

Laravel Doctrine Hashids

This package uses vinkla's Hashids bridge for Laravel to provide a Doctrine type that obfuscates integer IDs using Hashids.

Installation

Before installing this package, install and configure the vinkla/hashids package.

Require this package using composer:

composer require "blake/laraveldoctrine-hashids:~1.0"

The next step is enabling the Doctrine type. If you are using the laravel-doctrine/orm package, add this to your config/doctrine.php file:

    'custom_types'              => [
        // ...
        'hashid' => Blake\Dbal\Types\HashidType::class,
    ],

Usage

Anywhere you are using an integer in your entities you may safely replace with the hashid type:

<?php

namespace App\Entities;

use Doctrine\ORM\Mapping AS ORM;

/**
 * @ORM\Entity
 * @ORM\Table
 */
class User
{
    /**
     * @var string
     * @ORM\Id
     * @ORM\Column(type="hashid", nullable=false)
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    protected $id;
    
    // ...
}

Interacting with the entity manager is as you'd expect. Simply replace where you'd use lame integer IDs with their obfuscated version:

$user = EntityManager::find(User::class, 'dlGRfgH73');

The ID will be decoded before it hits the database, and it will be encoded on the way out. This allows you to use performant integer IDs while obfuscating details about your database and making URLs that point to objects slightly prettier.

Configuration

vinkla/hashids allows you to set up multiple "connections". This package will look for a doctrine connection and use main as a fallback if the doctrine connection doesn't exist.

Related Packages

vinkla/hashids

A Hashids bridge for Laravel

15,667,926 2,053
oskarstark/doctrine-postgres-public-schema-listener

An migration EventSubscriber which ensures public namespace is only added if nee...

130,115 1
panguktd/laravel-doctrine-orm

Doctrine 2.5 For Laravel .

7 0
beberlei/doctrineextensions

A set of extensions to Doctrine 2 that add support for additional query function...

85,572,900 2,103

Version History

Version Released PHP License
v1.0.1 >=5.5.9 MIT
v1.0.0 >=5.5.9 MIT