sergeil/doctrine-entity-data-mapper-bundle
Composer 安装命令:
composer require sergeil/doctrine-entity-data-mapper-bundle
包简介
Makes it easy to map data coming from client-side onto your Doctrine ORM managed entities.
关键字:
README 文档
README
Bundle provides tools that simplify mapping data coming from client-side onto Doctrine ORM managed entities.
Features:
- All basic scalar types mapping (boolean, numbers ...)
- All types of associations are supported (+bidirectional aspect of relations is taken care of out of the box)
- Complex data types transformation and mapping - when a value before being mapped onto an entity is transformed
- Additional DI services injection to a setter method when a value is mapped
- Flexible mapping of date/datetimes
Teaser with ManyToMany relation
For an illustration purpose let's take a classical example of User and Group entities and assume that they are bidirectionally linked to each other.
Now, let's take a look at several sample array data-structures that you may pass to EntityDataMapperService and have it properly mapped data onto your entity. For the illustration purpose we assume that we have two users - "Jane Doe" and "John Doe" with corresponding IDs of 1 and 2, and three groups: "Admins", "Users", "Moderators" with IDs 1, 2, 3.
$em = $container->get('doctrine.orm.entity_manager'); $mapper = $container->get('sli_doctrine_entity_data_mapper.mapping.entity_data_mapper'); $adminsGroup = $em->find('MyBundle:Group', 1); $usersGroup = $em->find('MyBundle:Group', 2); $moderatorsGroup = $em->find('MyBundle:Group', 3); $john = new User('John Doe'); $jane = new User('Jane Doe'); $userParams = array( 'groups' => [1, 2] ); $mapper->mapEntity($john, $userParams, array_keys($userParams)); $em->persist($john); $em->persist($jane); $em->flush(); echo count($john->groups); // two elements, groups "Admins" and "Users" were fetched from database by their IDs echo count($adminGroup->users); // one element echo count($usersGroup->users); // one element echo count($moderatorsGroup->users); // zero elements
Now let's presume that during next request we want that $john user would belong only to "Moderators" group:
$userParams = array( 'groups' => [3] ); $mapper->mapEntity($john, $userParams, array_keys($userParams));
Several things just happened:
- "Admins" and "Users" group were removed from User's side Collection
- "John Doe" was removed from "Admins" and "Users" Group's Collections
- "John Doe" was added to "Moderators" group
- "Moderators" group was added to John Doe's groups collection
Installation
Add this dependency to your composer.json:
"sergeil/doctrine-entity-data-mapper-bundle": "dev-develop"
Update your AppKernel class and add this:
new Sli\DoctrineEntityDataMapperBundle\SliDoctrineEntityDataMapperBundle(),
Documentation
See Resources/doc/index.md.
Licensing
This bundle is under the MIT license. See the complete license in the bundle: Resources/meta/LICENSE
sergeil/doctrine-entity-data-mapper-bundle 适用场景与选型建议
sergeil/doctrine-entity-data-mapper-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 76 次下载、GitHub Stars 达 1, 最近一次更新时间为 2014 年 12 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「doctrine」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sergeil/doctrine-entity-data-mapper-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sergeil/doctrine-entity-data-mapper-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sergeil/doctrine-entity-data-mapper-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Make pimcore migration simple
Plugins for Tactician commands using Doctrine, like wrapping every command in a transaction
Use FileMaker through CWP as your backend database
Data migration mechanism for php using dbal do doctrine with pdo, schema and queryBuilder
统计信息
- 总下载量: 76
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 14
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-12-24
