Download the PHP package enumeum/doctrine-enums without Composer
On this page you can find all versions of the php package enumeum/doctrine-enums. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download enumeum/doctrine-enums
More information about enumeum/doctrine-enums
Files in enumeum/doctrine-enums
Package doctrine-enums
Short Description Doctrine extension to manage enumerations in PostgreSQL
License MIT
Informations about the package doctrine-enums
Doctrine Enums Extension
This package contains an extension for Doctrine ORM and DBAL which offer enum management functionality in a PostgreSQL database. Yes, enumerations in DB is bad practice, and you should avoid to use them. But sometimes DB management needs Enums as a simple constraint on certain fields. This package provides a transparent approach to adding PHP enums as database types and using them with appropriate fields in Doctrine entities.
Requirements
Minimum PHP version is 8.1.
Installation
composer require enumeum/doctrine-enums
Usage
Enumeum attribute for PHP enum:
- #[Enumeum\DoctrineEnum\Attribute\EnumType(name: 'type_name')] this attribute tells that this enum is database type. By default, it creates type in database with its own cases.
Enum setup
Entity setup
Please note that the configuration of the entity is no different from the usual one. Doctrine supports "enumType" property and converts it transparently.
DBAL Configuration
Additional types or directories can be added by the appropriate methods one or more
Filled loader provides Enumeum\DoctrineEnum\Definition\DefinitionRegistry instance with collection of enums definitions. Every call creates new Registry instance.
DBAL Schema manipulation needs to have new types loaded thus use special Enumeum\DoctrineEnum\Type\TypeRegistryLoader for that.
Next step is to create Enumeum\DoctrineEnum\EnumTool and use it to generate SQL queries for database Enums persistence or update Database directly.
ORM Configuration
ORM part needs just adding Enumeum\DoctrineEnum\EventSubscriber\PostGenerateSchemaSubscriber into Doctrine's EventManager
Usage
If you have changed enums values, their structure, adding or dropping types then use Enumeum\DoctrineEnum\EnumTool. It will generate SQL queries to synchronize configured enums or updates database directly. After that if it is required to change not just enums but also a schema then do schema diff/update.
Running Tests
To set up and run the tests, follow these steps:
- Install Docker and ensure you have
docker-compose
andmake
(optional) - From the project root, run
make start
to start containers in daemon mode (or usingdocker-compose up -d --build --remove-orphans --force-recreate
) - Enter the container via
make console
(or usingdocker-compose exec php bash
) - Check that you are in root directory
/var/www
, if neither then navigate using:cd /var/www
- Install Composer dependencies via
composer install
- Run the tests with
make test
from out of container (or usingbin/phpunit -c tests/
inside container)
Possible future feature
Command for removing Enum value without recreating. https://postgrespro.ru/list/thread-id/2388881
All versions of doctrine-enums with dependencies
doctrine/annotations Version ^1.13
doctrine/common Version ^2.13 || ^3.0
doctrine/event-manager Version ^1.0