Download the PHP package nepada/consistence-doctrine without Composer
On this page you can find all versions of the php package nepada/consistence-doctrine. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nepada/consistence-doctrine
More information about nepada/consistence-doctrine
Files in nepada/consistence-doctrine
Package consistence-doctrine
Short Description Consistence Enum types for Doctrine.
License BSD-3-Clause
Informations about the package consistence-doctrine
Consistence Enum Doctrine types
Package abandoned
This package is considered obsolete and abandoned. Since PHP 8.1 introduced native enum support, there is no need for user-land implementation of enums, neither their custom integration into Doctrine.
Installation
Via Composer:
Usage
Define Doctrine type for the enum
You can choose to inherit from StringEnumType
, IntegerEnumType
, FloatEnumType
or BooleanEnumType
depending on the enum values.
Register the created type in Doctrine
In Nette with nettrine/dbal integration, you can register the types in your configuration:
Use the type in entity
Use enum in query builder
PHPStan support (via phpstan/phpstan-doctrine
)
The abstract enum type classes are anotated as PHPStan generics and define proper typehints for their convert*
methods. This means you can teach PHPStan your custom enum types via ReflectionDescriptor
:
Differences from the official consistence/consistence-doctrine
The official integration consistence/consistence-doctrine
uses postload entity event to convert data stored in database to enum instances.
The main advantage of that approach is that you don't need to create and register new doctrine type for every enum.
The disadvantages are:
- You can't use native property typehints for entity enum attributes.
- When you're not hydrating entites, you will get enum values instead of enum instances.
- There is no easy way how to make PHPStan understand and check doctrine and PHP types of your enum fields.
All versions of consistence-doctrine with dependencies
consistence/consistence Version ^2.0@dev
doctrine/dbal Version ^2.6@dev || ^3.0@dev