PHPackages                             tarifhaus/doctrine-nullable-embeddable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. tarifhaus/doctrine-nullable-embeddable

ActiveLibrary[Database &amp; ORM](/categories/database)

tarifhaus/doctrine-nullable-embeddable
======================================

A workaround implementation for nullable embeddables in Doctrine entities.

v2.0.0(8y ago)2362.1k10[1 issues](https://github.com/tarifhaus/doctrine-nullable-embeddable/issues)[2 PRs](https://github.com/tarifhaus/doctrine-nullable-embeddable/pulls)MITPHPPHP ^7.0

Since Mar 28Pushed 2y ago2 watchersCompare

[ Source](https://github.com/tarifhaus/doctrine-nullable-embeddable)[ Packagist](https://packagist.org/packages/tarifhaus/doctrine-nullable-embeddable)[ RSS](/packages/tarifhaus-doctrine-nullable-embeddable/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (2)Versions (5)Used By (0)

Doctrine: nullable embeddable
=============================

[](#doctrine-nullable-embeddable)

This listener enables you to have truly `null` values for your [Doctrine embeddables](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/embeddables.html). The listener hooks into the `postLoad` [lifecycle callback](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#postload) and replaces embeddable values that are null.

It implements a workaround for this open issue:

- [doctrine/orm#4568](https://github.com/doctrine/orm/issues/4568)
- [doctrine/orm#1275](https://github.com/doctrine/orm/pull/1275)

The listener depends on an `evaluator` to check whether to instruct a `nullator` to actually replace the embeddable with `null`. This helper library ships with different implementations and respective interfaces to roll your own.

The default `evaluator` requires the `embeddable` class to implement the `Tarifhaus\Doctrine\ORM\NullableEmbeddableInterface`. It contains a method `isNull(): bool` which tells the evaluator, whether the loaded embeddable should be treated as and therefore replaced with `null`.

The `nullator` actually replaces the embeddable with `null` in a specific way.

Configuration
-------------

[](#configuration)

There are two things you have to do, in order to have this listener working correctly.

1. An entry to the property map has to be made. This is done by calling the `\Tarifhaus\Doctrine\ORM\NullableEmbeddableListener::addMapping`. It receives the FQCN (fully qualified class name) of the entity and the name of the property the embeddable resides in.

    For example:

    ```
