Download the PHP package sspat/doctrine-nullable-embeddables without Composer
On this page you can find all versions of the php package sspat/doctrine-nullable-embeddables. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sspat/doctrine-nullable-embeddables
More information about sspat/doctrine-nullable-embeddables
Files in sspat/doctrine-nullable-embeddables
Package doctrine-nullable-embeddables
Short Description Patches doctrine/orm to allow usage of nullable embeddables
License MIT
Informations about the package doctrine-nullable-embeddables
Nullable embeddables for Doctrine
As soon as you start using embeddable value objects in your Doctrine entities there is chance you will run in the problem, that Doctrine will instantiate value objects even when the corressponding value in the database is null. This will lead to typing-related PHP errors.
Basic example:
If you want to use PHP 7.4 typed properties:
This problem was discussed in the doctrine/orm repository issue: https://github.com/doctrine/orm/issues/4568
The current consensus is that this feature will land in the 3.x versions only.
So this leaves you with the following options:
Make your value objects properties nullable.
This will break the entity and value objects invariants and introduce a lot of unnecessary checks in your code:
Use a Doctrine lifecycle callback to reset the entity properties to null after hydration.
You will still need to set the value object's properties as nullable to avoid errors during hydration and your nullable value objects will need some logic, for example implement a special interface, to allow the lifecycle callback to determine whether the hydrated value is null or not.
You will also need to configure each nullable value object for each entity to avoid running the lifecycle callback for all entity properties.
If you choose this path, there is an implementation available: https://github.com/tarifhaus/doctrine-nullable-embeddable
Fork Doctrine to implement your own hydration mechanism
This is pretty straightforward and the implications will be in maintaining your own fork and keeping up with the upstream changes.
Override specific Doctrine classes with your own
This is what this package is doing.
It will install doctrine/orm of a specific version. The version is always the same as of this package and is locked by it, so if you want to update Doctrine you will need to update this package to the same version as the Doctrine version you want. This locking is needed to ensure that there are no changes to the files this package is patching.
After installing doctrine/orm, a patch will be applyed to the Doctrine class Doctrine/ORM/Mapping/ReflectionEmbeddedProperty
using https://github.com/cweagans/composer-patches.
You can review the contents of this patch in patch/nullable_embeddables.patch
It works by analyzing the types of the properties of the entity and the value-object. If the entity property containing the value-object is declared as nullable and none of the value-object's properties that are not declared nullable get null values from the database - then the entity property will be hydrated with the value object. All other cases are considered an invalid state based on the provided typing and will result in hydrating to null on the corresponding property of the entity.
The tradeoffs of this approach will be:
- You can't update Doctrine directly, only update it with this package
- You will need PHP 7.4
- Your entities properties containing nullable value objects must be typed
- Your entities properties containing nullable value objects must be nullable
- Your nullable value objects properties must be typed
A working example would look like this:
If you choose this path, you can install this package in the following steps:
- add to your composer.json:
Then depending on the version of doctrine/orm you want to use:
- run
composer require sspat/doctrine-nullable-embeddables:v2.16.2 doctrine/orm:2.16.2
- run
composer require sspat/doctrine-nullable-embeddables:v2.16.1 doctrine/orm:2.16.1
- run
composer require sspat/doctrine-nullable-embeddables:v2.16.0 doctrine/orm:2.16.0
- run
composer require sspat/doctrine-nullable-embeddables:v2.15.5 doctrine/orm:2.15.5
- run
composer require sspat/doctrine-nullable-embeddables:v2.15.4 doctrine/orm:2.15.4
- run
composer require sspat/doctrine-nullable-embeddables:v2.15.3 doctrine/orm:2.15.3
- run
composer require sspat/doctrine-nullable-embeddables:v2.15.2 doctrine/orm:2.15.2
- run
composer require sspat/doctrine-nullable-embeddables:v2.15.1 doctrine/orm:2.15.1
- run
composer require sspat/doctrine-nullable-embeddables:v2.15.0 doctrine/orm:2.15.0
- run
composer require sspat/doctrine-nullable-embeddables:v2.14.3 doctrine/orm:2.14.3
- run
composer require sspat/doctrine-nullable-embeddables:v2.14.2 doctrine/orm:2.14.2
- run
composer require sspat/doctrine-nullable-embeddables:v2.14.1 doctrine/orm:2.14.1
- run
composer require sspat/doctrine-nullable-embeddables:v2.14.0 doctrine/orm:2.14.0
- run
composer require sspat/doctrine-nullable-embeddables:v2.13.5 doctrine/orm:2.13.5
- run
composer require sspat/doctrine-nullable-embeddables:v2.13.4 doctrine/orm:2.13.4
- run
composer require sspat/doctrine-nullable-embeddables:v2.13.3 doctrine/orm:2.13.3
- run
composer require sspat/doctrine-nullable-embeddables:v2.13.2 doctrine/orm:2.13.2
- run
composer require sspat/doctrine-nullable-embeddables:v2.13.1 doctrine/orm:2.13.1
- run
composer require sspat/doctrine-nullable-embeddables:v2.13.0 doctrine/orm:2.13.0
- run
composer require sspat/doctrine-nullable-embeddables:v2.12.4 doctrine/orm:2.12.4
- run
composer require sspat/doctrine-nullable-embeddables:v2.12.3 doctrine/orm:2.12.3
- run
composer require sspat/doctrine-nullable-embeddables:v2.12.2 doctrine/orm:2.12.2
- run
composer require sspat/doctrine-nullable-embeddables:v2.12.1 doctrine/orm:2.12.1
- run
composer require sspat/doctrine-nullable-embeddables:v2.12.0 doctrine/orm:2.12.0
- run
composer require sspat/doctrine-nullable-embeddables:v2.11.3 doctrine/orm:2.11.3
- run
composer require sspat/doctrine-nullable-embeddables:v2.11.2 doctrine/orm:2.11.2
- run
composer require sspat/doctrine-nullable-embeddables:v2.11.1 doctrine/orm:2.11.1
- run
composer require sspat/doctrine-nullable-embeddables:v2.11.0 doctrine/orm:2.11.0
- run
composer require sspat/doctrine-nullable-embeddables:v2.10.5 doctrine/orm:2.10.5
- run
composer require sspat/doctrine-nullable-embeddables:v2.10.4 doctrine/orm:2.10.4
- run
composer require sspat/doctrine-nullable-embeddables:v2.10.3 doctrine/orm:2.10.3
- run
composer require sspat/doctrine-nullable-embeddables:v2.10.2 doctrine/orm:2.10.2
- run
composer require sspat/doctrine-nullable-embeddables:v2.10.1 doctrine/orm:2.10.1
- run
composer require sspat/doctrine-nullable-embeddables:v2.10.0 doctrine/orm:2.10.0
- run
composer require sspat/doctrine-nullable-embeddables:v2.9.6 doctrine/orm:2.9.6
- run
composer require sspat/doctrine-nullable-embeddables:v2.9.5 doctrine/orm:2.9.5
- run
composer require sspat/doctrine-nullable-embeddables:v2.9.4 doctrine/orm:2.9.4
- run
composer require sspat/doctrine-nullable-embeddables:v2.9.3 doctrine/orm:2.9.3
- run
composer require sspat/doctrine-nullable-embeddables:v2.9.2 doctrine/orm:2.9.2
- run
composer require sspat/doctrine-nullable-embeddables:v2.9.1 doctrine/orm:2.9.1
- run
composer require sspat/doctrine-nullable-embeddables:v2.9.0 doctrine/orm:2.9.0
- run
composer require sspat/doctrine-nullable-embeddables:v2.8.5 doctrine/orm:2.8.5
- run
composer require sspat/doctrine-nullable-embeddables:v2.8.4 doctrine/orm:2.8.4
- run
composer require sspat/doctrine-nullable-embeddables:v2.8.3 doctrine/orm:2.8.3
- run
composer require sspat/doctrine-nullable-embeddables:v2.8.2 doctrine/orm:2.8.2
- run
composer require sspat/doctrine-nullable-embeddables:v2.8.1 doctrine/orm:2.8.1
- run
composer require sspat/doctrine-nullable-embeddables:v2.8.0 doctrine/orm:2.8.0
- run
composer require sspat/doctrine-nullable-embeddables:v2.7.5 doctrine/orm:2.7.5
- run
composer require sspat/doctrine-nullable-embeddables:v2.7.4 doctrine/orm:2.7.4
- run
composer require sspat/doctrine-nullable-embeddables:v2.7.3 doctrine/orm:2.7.3
- run
composer require sspat/doctrine-nullable-embeddables:v2.7.2 doctrine/orm:2.7.2
- run
composer require sspat/doctrine-nullable-embeddables:v2.7.1 doctrine/orm:2.7.1
- run
composer require sspat/doctrine-nullable-embeddables:v2.7.0 doctrine/orm:2.7.0
All versions of doctrine-nullable-embeddables with dependencies
cweagans/composer-patches Version ^1.6|^1.7
doctrine/orm Version 3.3.0