foleon/doctrine-orm-hydration-module
Composer 安装命令:
composer require foleon/doctrine-orm-hydration-module
包简介
Doctrine ORM hydrators for Laminas
README 文档
README
Doctrine Hydration Module
This module provides a configurable way to create new doctrine hydrators. By using the configurable API, it is easy to create a custom hydrator for any use case you want.
The basic hydrator from the doctrine laminas hydrator is being used. It is possible to configure your own strategies for complex objects like referenced entities.
Supported features
- 1.0.x: A rewrite and editing of phpro/zf-doctrine-hydration-module requiring PHP 7.4+
Installation
Add to composer.json
composer require api-skeletons/doctrine-orm-hydration-module
Add to application config
return array( 'modules' => array( 'ApiSkeletons\\DoctrineORMHydrationModule', // other libs... ), // Other config );
Hydrator configuration
return array( 'doctrine-hydrator' => array( 'hydrator-manager-key' => array( 'entity_class' => 'App\Entity\EntityClass', 'object_manager' => 'doctrine.objectmanager.key.in.servicelocator', 'by_value' => true, 'naming_strategy' => 'custom.naming.strategy.key.in.servicemanager', 'hydrator' => 'custom.hydrator.key.in.hydratormanager', 'strategies' => array( 'fieldname' => 'custom.strategy.key.in.servicemanager', ), 'filters' => array( 'custom_filter_name' => array( 'condition' => 'and', // optional, default is 'or' 'filter' => 'custom.hydrator.filter.key.in.servicemanager', ), ), ), ), );
entity_class
This property is used to specify the class of the entity that will be hydrated. You need to make sure that this entity is a mapped doctrine class.
object_manager
You can specify which object manager you want to use for the hydrator. The value is the key of the desired object manager in the service manager.
by_value
Specify if you want the hydrator to hydrate the entity by value or by reference.
naming_strategy
You can use a custom naming strategy for the hydrator. Specify the key of the naming strategy in the service manager.
Note that this naming strategy needs to implement NamingStrategyInterface.
hydrator
You can use a custom hydrator instead of the default DoctrineObject hydrator.
Make sure this hydrator implements HydratorInterface.
strategies
It is possible to customize the hydration strategy of specific properties.
Configure the property you want to customize with the key of the strategy in the service manager;
Note that this strategy needs to implement StrategyInterface.
filters
This property can be used to apply filters on the Hydrator.
You can specify a list of custom filters by defining the key of the filter in the service manager and the filter condition as described in the hydrator filter documentation.
Note that this filter needs to implement FilterInterface.
From here on, you can get the hydrator by calling get('hydrator-manager-key') on the HydratorManager.
Custom Filters
Custom filters allow you to fine-tune the results of the hydrator's extract functionality by determining which fields should be extracted.
To configure custom filters:
return array( 'doctrine-hydrator' => array( 'custom-hydrator' => array( // other config 'filters' => array( 'custom.filter.name' => array( 'condition' => 'and', //optional, default: FilterComposite::CONDITION_OR, 'filter' => 'custom.filter', // a name in the Service Manager ), ), ), ), );
In this example configuration, the hydrator factory will retrieve custom.filter from the Service Manager and inject it as a filter into the hydrator. The filter must implement Zend\Hydrator\Filter\FilterInterface.
The service's filter($fieldName) function will be called by the hydrator during extract and the field name being extracted will be passed as an argument. The filter() function must return a truthy value: if true then the field will NOT be extracted.
Override hydrator:
If the standard DoctrineHydrator is not flexible enough, you can set a custom hydrator. This allows you to use an extended DoctrineHydrator or another existing hydrator, and configure it with this module.`.
return array( 'doctrine-hydrator' => array( 'custom-hydrator' => array( // other config 'hydrator' => 'Zend\Hydrator\ArraySerializable' ), ), );
Testing
This package is fully tested with Cs fixer and PhpUnit. The MongoDB tests require mongodb to be installed on your machine. You can skip these tests by adding a testsuite to the command:
# Php coding standards: ./vendor/bin/phpcs # Phpunit: ./vendor/bin/phpunit
foleon/doctrine-orm-hydration-module 适用场景与选型建议
foleon/doctrine-orm-hydration-module 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.29k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 01 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「orm」 「doctrine」 「hydrator」 「laminas」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 foleon/doctrine-orm-hydration-module 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 foleon/doctrine-orm-hydration-module 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 foleon/doctrine-orm-hydration-module 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Hydrator to map or extract an extract object
Kinikit - PHP Application development framework MVC component
PHP Database ORM for Symfony1. Do NOT use for new projects: please move to a newest Symfony release and Doctrine2
A simple library that uses the hydration pattern to fill objects given different sources of data.
Doctrine ORM hydrators for Laminas
Generators for Doctrine's hydrators and proxies.
统计信息
- 总下载量: 6.29k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-01-08