Download the PHP package zlikavac32/php-enum-doctrine without Composer
On this page you can find all versions of the php package zlikavac32/php-enum-doctrine. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zlikavac32/php-enum-doctrine
More information about zlikavac32/php-enum-doctrine
Files in zlikavac32/php-enum-doctrine
Informations about the package php-enum-doctrine
PHP Enum Doctrine
Doctrine support for zlikavac32/php-enum.
Table of contents
- Installation
- Usage
- Custom column length
- Custom representation
- Limitations
- Further work
Installation
Recommended installation is through Composer.
Usage
Assumption is that there exists a valid enum \YesNoEnum
.
Create a new type that extends \Zlikavac32\DoctrineEnum\DBAL\Types\EnumType
.
Next, define protected function enumClass(): string
. This method should return FQN of the enum class that this type exposes to the Doctrine.
Define Doctrine method public function getName(): string
that defines type's name.
And that's it. Only thing left to do is to register the type using
You can now use enum_yes_no
type.
For more info on the custom Doctrine mapping types, check official documentation.
Custom column length
Internally this library uses varchar
type with the maximum length of 32
. If you want to fit the length to your own needs, just override method protected function columnLength(): int
.
Note that on types first usage, all enum elements names are checked against specified column length. If a name longer than maximum length is detected, a \LogicException
is thrown.
Custom representation
By default, name of the enum element is used for it's representation in the database. To change that behaviour, override methods enumToDatabaseValue()
and databaseValueToEnum()
.
Limitations
This library does not use platform dependent types like enum
in MySQL
or custom types in PostgresSQL
. Instead, varchar
is used.
Reasons for this are:
Doctrine
can not diff enum contents because that's types intrinsic property- for
PostgresSQL
we can't diff column because type is not in Doctrine control - column constraints can not be used because they break
ALTER
syntax
If you know how to avoid any of this, please let me know.
Further work
Figure out how to overcome issues in Limitations.