2017 © Pedro PelĂĄez
 

library shortid-doctrine

Doctrine type for shortid-php

image

pugx/shortid-doctrine

Doctrine type for shortid-php

  • Saturday, May 19, 2018
  • by garak
  • Repository
  • 10 Watchers
  • 2 Stars
  • 2,045 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 7 Versions
  • 10 % Grown

The README.md

ShortId Doctrine Type

Total Downloads Build Status Code Climate, (*1)

A Doctrine field type for ShortId for PHP., (*2)

Installation

Run the following command:, (*3)

composer require pugx/shortid-doctrine

Note: if you use Symfony, you should require pugx/shortid-doctrine-bundle instead., (*4)

Examples

To configure Doctrine to use shortid as a field type, you'll need to set up the following in your bootstrap:, (*5)

``` php <?php, (*6)

\Doctrine\DBAL\Types\Type::addType('shortid', 'PUGX\Shortid\Doctrine\ShortidType'); $entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('shortid', 'shortid');, (*7)


Then, in your entities, you may annotate properties by setting the `@Column` type to `shortid`. You can generate a `PUGX\Shortid\Shortid` object for the property in your constructor, or use the built-in generator. Example with ShortId created manually in constructor: ``` php <?php use PUGX\Shortid\Shortid; /** * @Entity * @Table */ class Product { /** * @var Shortid * * @Id * @Column(type="shortid") * @GeneratedValue(strategy="NONE") */ private $id; public function __construct(?Shortid $id = null) { $this->id = $id ?? Shortid::generate(); } public function getId(): Shortid { return $this->id; } }

Example with auto-generated shortid:, (*8)

``` php <?php, (*9)

use PUGX\Shortid\Shortid;, (*10)

/** * @Entity * @Table */ class Product { /** * @var Shortid * * @Id * @Column(type="shortid") * @GeneratedValue(strategy="CUSTOM") * @CustomIdGenerator(class="PUGX\Shortid\Doctrine\Generator\ShortidGenerator") */ private $id;, (*11)

public function getId(): Shortid
{
    return $this->id;
}

}, (*12)


If you want to customize ShortId length, you can use the `length` option in the Column annotation. Example: ``` php <?php use PUGX\Shortid\Shortid; /** * @Entity * @Table */ class Product { /** * @var Shortid * * @Id * @Column(type="shortid", length=5) * @GeneratedValue(strategy="NONE") */ private $id; public function __construct() { $this->id = Shortid::generate(5); } }

If you want to customize alphabet and/or to use the built-in generator, you need to setup ShortId in your bootstrap:, (*13)

``` php <?php, (*14)

\Doctrine\DBAL\Types\Type::addType('shortid', 'PUGX\Shortid\Doctrine\ShortidType'); $entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('shortid', 'shortid');, (*15)

$factory = new \PUGX\Shortid\Factory(); // alphabet must be 64 characters long $factory->setAlphabet('Ă©123456789Ă bcdefghĂŹjklmnĂČpqrstĂčvwxyzABCDEFGHIJKLMNOPQRSTUVWX.!@|'); // length must be between 2 and 20 $factory->setLength(5); PUGX\Shortid\Shortid::setFactory($factory); ```, (*16)

Then, you must pay attention to configure every ShortId property with the same length (5 in this example)., (*17)

The Versions

19/05 2018

dev-master

9999999-dev http://pugx.org/

Doctrine type for shortid-php

  Sources   Download

MIT

The Requires

 

The Development Requires

uuid doctrine id shortid

08/08 2017

v0.3.0

0.3.0.0 http://pugx.org/

Doctrine type for shortid-php

  Sources   Download

MIT

The Requires

 

The Development Requires

uuid doctrine id shortid

21/03 2017

v0.2.2

0.2.2.0 http://pugx.org/

Doctrine type for shortid-php

  Sources   Download

MIT

The Requires

 

The Development Requires

uuid doctrine id shortid

20/03 2017

v0.2.1

0.2.1.0 http://pugx.org/

Doctrine type for shortid-php

  Sources   Download

MIT

The Requires

 

The Development Requires

uuid doctrine id shortid

18/01 2017

v0.2.0

0.2.0.0 http://pugx.org/

Doctrine type for shortid-php

  Sources   Download

MIT

The Requires

 

The Development Requires

uuid doctrine id shortid

13/03 2016

v0.1.0

0.1.0.0 http://pugx.org/

Doctrine type for shortid-php

  Sources   Download

MIT

The Requires

 

uuid doctrine id shortid

06/12 2015

dev-analysis-q17M18

dev-analysis-q17M18 http://pugx.org/

Doctrine type for shortid-php

  Sources   Download

MIT

The Requires

 

The Development Requires

uuid doctrine id shortid