mihai-stancu / doctrine-types-extra
Doctrine2 storing `UUID()` as BINARY(16) and `UUID_SHORT()` as BIGINT for MySQL.
Installs: 1 843
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 2
Open Issues: 0
Type:bundle
pkg:composer/mihai-stancu/doctrine-types-extra
Requires
- php: >=5.5.9
- doctrine/orm: ^2
- symfony/config: ~2|~3
- symfony/debug: ~2|~3
- symfony/dependency-injection: ~2|~3
- symfony/event-dispatcher: ~2|~3
- symfony/filesystem: ~2|~3
- symfony/http-foundation: ~2|~3
- symfony/http-kernel: ~2|~3
This package is not auto-updated.
Last update: 2025-10-25 23:07:09 UTC
README
Doctrine2's default GUID works as a native data type for platforms that support it (Oracle, MSSQL, PostgreSQL) but falls back to VARCHAR in others (MySQL, SQLite).
- BINARY:
binary_guidis an alternative of the defaultguidtype which uses BINARY(16) on all platforms (or VARBINARY(16) on platforms without fixed length binary). The default GeneratedValue (UUID) is used as the generator function andhex2bin/bin2hexconverters are used.BinaryGuidTypeextendsBinaryType. - SHORT:
short_guidis an extension of the defaultguidtype which uses BIGINT as a fallback type for UUIDs in MySQL instead of VARCHAR. TheUUID_SHORT()function from MySQL is used as the generator function and the results are handled as integers.ShortGuidTypeextendsGuidType.
N.B.: !!! MySQl's short UUIDs are not standard UUIDs and they are not guaranteed to be unique across (...more than 256...) servers.
Sets and enums are not supported in Doctrine2 by default but they can be treated as strings in most scenarios.
- SET:
setis a naive implementation of MySQL'ssetdata type represented in PHP as an array of strings. The type only supports generating create statements and implode / explode converters.SetTypeextendsSimpleArrayType.
Usage
Adding the following lines in your app/config.yml (for Symfony2 projects) should do the trick:
doctrine:
dbal:
types:
binary_guid: MS\DoctrineTypes\DBAL\Types\BinaryGuidType
short_guid: MS\DoctrineTypes\DBAL\Types\ShortGuidType
set: MS\DoctrineTypes\DBAL\Types\SetType
mapping_types:
binary_guid: binary_guid
short_guid: short_guid
set: set
And adding the following Annotation comments in your entity definitions should finish the job:
/**
* @Id
* @Column(type="binary_guid")
* @GeneratedValue(strategy="UUID")
*/
or
/**
* @Id
* @Column(type="short_guid")
* @GeneratedValue(strategy="CUSTOM")
* @CustomIdGenerator(class="MS\DoctrineTypes\ORM\Id\ShortGuidGenerator")
*/
or
/**
* @Column(type="set", options={ "values"={"value1", "value2"} })
*/