Download the PHP package consistence/consistence-doctrine-symfony without Composer
On this page you can find all versions of the php package consistence/consistence-doctrine-symfony. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download consistence/consistence-doctrine-symfony
More information about consistence/consistence-doctrine-symfony
Files in consistence/consistence-doctrine-symfony
Package consistence-doctrine-symfony
Short Description Symfony Bundle integrating Consistence library with Doctrine ORM
License MIT
Informations about the package consistence-doctrine-symfony
Symfony Bundle integrating Consistence library with Doctrine ORM
This is a Symfony bundle providing integration for the standalone package
consistence/consistence-doctrine
, if you are not using Symfony, follow instructions there.
This bundle provides integration of Consistence value objects for Doctrine ORM so that you can use them in your entities.
For now, the only integration which is needed is for Enums, see the examples below.
Usage
Enums represent predefined set of values and of course, you will want to store these values in your database as well. Since Enums
are objects and you only want to store the represented value, there has to be some mapping.
You can see it in this example where you want to store sex for your User
s:
To use the Sex
enum in your User
entity notice the type="enum<Consistence\Doctrine\Example\User\Sex>"
in ORM\Column
- this will be used for mapping the value to and from your database. You can specify any other parameters for ORM\Column
as you would usually (nullability, length...).
Before this will work with database, we need to register Doctrine DBAL type for each enum. This can be done using the configuration:
We used string
because the Sex
enum uses strings for its values. There are also integer
, float
and boolean
- depending on what scalar values are used in the enum.
If you use the same enum in multiple places configure it only once.
Now everything is ready to be used, when you call flush
, only female
will be saved:
And when you retrieve the entity back from database, you will receive the Sex
enum object again:
This means that the objects API is symmetrical (you get the same type as you set) and you can start benefiting from Enums advantages such as being sure, that what you get is already a valid value and having the possibility to define methods on top of the represented values.
Configuration
Configuration structure with listed default values:
Installation
1) Install package consistence/consistence-doctrine-symfony
with Composer:
2) Register the bundle in your application:
3) Configure needed DBAL types (see Usage
section above).
That's all, you are good to go!
All versions of consistence-doctrine-symfony with dependencies
consistence/consistence Version ^1.0|^2.0
consistence/consistence-doctrine Version ^3.0
doctrine/dbal Version ^2.13.1|^3.0
symfony/config Version ^4.4|^5.0
symfony/dependency-injection Version ^4.4|^5.0
symfony/http-kernel Version ^4.4|^5.0