tarifhaus/doctrine-nullable-embeddable
Composer 安装命令:
composer require tarifhaus/doctrine-nullable-embeddable
包简介
A workaround implementation for nullable embeddables in Doctrine entities.
README 文档
README
This listener enables you to have truly null values for your Doctrine embeddables.
The listener hooks into the postLoad lifecycle callback and replaces embeddable values that are null.
It implements a workaround for this open issue:
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
There are two things you have to do, in order to have this listener working correctly.
-
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:
<?php use Tarifhaus\Doctrine\ORM\NullableEmbeddableListenerFactory; $listener = NullableEmbeddableListenerFactory::createWithClosureNullator(); $listener->addMapping('App\Domain\User\Model\UserProfile', 'address');
-
Now the listener needs to be registered with the Doctrine
EventManager.<?php use Doctrine\Common\EventManager; use Doctrine\ORM\Events; use Tarifhaus\Doctrine\ORM\NullableEmbeddableListenerFactory; $listener = NullableEmbeddableListenerFactory::createWithClosureNullator(); $listener->addMapping('App\Domain\User\Model\UserProfile', 'address'); $evm = new EventManager(); $evm->addEventListener([Events::postLoad], $listener);
Tip: It's highly recommended to use Doctrine entity listener when configuring the listener, so it is only executed for the entities it actually applies to.
Symfony
In case you are using Symfony with Doctrine, you can register the listener as a service.
services: tarifhaus.doctrine.nullable_embeddable.property_accessor: public: false class: Tarifhaus\Doctrine\ORM\NullableEmbeddable\PropertyAccessor arguments: - '@property_accessor' tarifhaus.doctrine.nullable_embeddable_closure_nullator: public: false class: Tarifhaus\Doctrine\ORM\NullableEmbeddable\ClosureNullator tarifhaus.doctrine.nullable_embeddable_listener: public: false class: Tarifhaus\Doctrine\ORM\NullableEmbeddableListener arguments: - '@tarifhaus.doctrine.nullable_embeddable.property_accessor' - '@tarifhaus.doctrine.nullable_embeddable_closure_nullator' calls: - ['addMapping', ['App\Domain\User\Model\UserProfile', 'address']] tags: - { name: 'doctrine.orm.entity_listener', entity: '\App\Domain\User\Model\UserProfile', event: 'postLoad' }
tarifhaus/doctrine-nullable-embeddable 适用场景与选型建议
tarifhaus/doctrine-nullable-embeddable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 62.13k 次下载、GitHub Stars 达 23, 最近一次更新时间为 2017 年 03 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tarifhaus/doctrine-nullable-embeddable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tarifhaus/doctrine-nullable-embeddable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 62.13k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 23
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-03-28