2017 © Pedro Peláez
 

library guid-doctrine

Use of a ramsey/uuid UUID with GUID codec as Doctrine field type.

image

gubler/guid-doctrine

Use of a ramsey/uuid UUID with GUID codec as Doctrine field type.

  • Thursday, April 19, 2018
  • by dev88
  • Repository
  • 1 Watchers
  • 0 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 80 % Grown

The README.md

gubler/guid-doctrine

This is based off of the ramsey/uuid-doctrine project. The only thing this project does differently is return GUIDs. This to handle Active Directory GUIDs., (*1)


The gubler/guid-doctrine package provides the ability to use ramsey/uuid as a Doctrine field type., (*2)

This project adheres to a Contributor Code of Conduct. By participating in this project and its community, you are expected to uphold this code., (*3)

Installation

The preferred method of installation is via Packagist and Composer. Run the following command to install the package and add it as a requirement to your project's composer.json:, (*4)

composer require gubler/guid-doctrine

Examples

Configuration

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

``` php \Doctrine\DBAL\Types\Type::addType('uuid', 'Gubler\Guid\Doctrine\GuidType');, (*6)

In Symfony:
 ``` yaml
# config/packages/doctrine.yaml
doctrine:
    dbal:
        types:
            guid:  Gubler\Guid\Doctrine\GuidType

In Zend Framework:, (*7)

<?php 
// module.config.php
use Gubler\Guid\Doctrine\GuidType;

return [
    'doctrine' => [
        'configuration' => [
            'orm_default' => [
                'types' => [
                    GuidType::NAME => GuidType::class,

Usage

Then, in your models, you may annotate properties by setting the @Column type to guid, and defining a custom generator of Gubler\Guid\GuidGenerator. Doctrine will handle the rest., (*8)

``` php /** * @Entity * @Table(name="products") */ class Product { /** * @var \Ramsey\Uuid\Uuid * * @Id * @Column(type="guid", unique=true) * @GeneratedValue(strategy="CUSTOM") * @CustomIdGenerator(class="Gubler\Guid\Doctrine\GuidGenerator") */ protected $id;, (*9)

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

}, (*10)


If you use the XML Mapping instead of PHP annotations. ``` XML <id name="id" column="id" type="guid"> <generator strategy="CUSTOM"/> <custom-id-generator class="Gubler\Guid\Doctrine\GuidGenerator"/> </id>

You can also use the YAML Mapping. ``` yaml id: id: type: guid generator: strategy: CUSTOM customIdGenerator: class: Gubler\Guid\Doctrine\GuidGenerator, (*11)


### Binary Database Columns In the previous example, Doctrine will create a database column of type `CHAR(36)`, but you may also use this library to store GUIDs as binary strings. The `GuidBinaryType` helps accomplish this. In your bootstrap, place the following: ``` php \Doctrine\DBAL\Types\Type::addType('guid_binary', 'Gubler\Guid\Doctrine\GuidBinaryType'); $entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('guid_binary', 'binary');

In Symfony: ``` yaml, (*12)

config/packages/doctrine.yaml

doctrine: dbal: types: guid_binary: Gubler\Guid\Doctrine\GuidBinaryType mapping_types: guid_binary: binary ```, (*13)

Then, when annotating model class properties, use guid_binary instead of guid:, (*14)

@Column(type="guid_binary")

More Information

For more information on getting started with Doctrine, check out the "Getting Started with Doctrine" tutorial., (*15)

Contributing

Contributions are welcome! Please read CONTRIBUTING for details., (*16)

The gubler/guid-doctrine library is copyright © Daryl Gubler and licensed for use under the MIT License (MIT). Please see LICENSE for more information., (*17)

The Versions

19/04 2018

dev-master

9999999-dev https://github.com/gubler/guid-doctrine

Use of a ramsey/uuid UUID with GUID codec as Doctrine field type.

  Sources   Download

MIT

The Requires

 

The Development Requires

uuid identifier guid doctrine

19/04 2018

v0.1.0

0.1.0.0 https://github.com/gubler/guid-doctrine

Use of a ramsey/uuid UUID with GUID codec as Doctrine field type.

  Sources   Download

MIT

The Requires

 

The Development Requires

uuid identifier guid doctrine