定制 orbitale/entity-merger 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

orbitale/entity-merger

最新稳定版本:v0.6.0

Composer 安装命令:

composer require orbitale/entity-merger

包简介

Merge arrays into your object entities

README 文档

README

⚠️ This package is unmaintained. Please look at better solutions, like serializers.

Entity Merger

Entity/object merger for PHP apps.

Installation

Install with Composer, it's the best packages manager you can have:

composer require orbitale/entity-merger

Requirements

Basic usage

Note: The EntityMerger only works with mapped objects. The properties must exist, and it cannot use magic methods to retrieve datas.

use Orbitale\Component\EntityMerger\EntityMerger;

$merger = new EntityMerger();

$object = new Object();
$object->setField(null);

$postedDatas = array('field' => 'value');

$merger->merge($object, $postedDatas);

echo $object->getField(); // Shows "value"

Using the Doctrine ORM ObjectManager

The EntityMerger accepts a Doctrine\ORM\ObjectManager as first argument, like the EntityManager for instance. This allows better and deeper merging when using ORM-mapped entities, by automatically using the Doctrine Metadatas to detect property types. If you are using the EntityMerger in an application that uses Doctrine, it is highly recommended to inject the ObjectManager to use your mapping as type reference for each of your class properties.

If no ObjectManager is used, the EntityMerger will perform its own checks with its own metadatas manager, but it is obviously less performant than the Doctrine one, because it cannot assume that you are attempting to merge an entity. It instead makes its checks based on PHPDoc, class imports and default parameters, so be sure to perfectly write your PHPDoc in your class if you do not want to use the ObjectManager!

Using the Serializer

The EntityMerger accepts a Serializer as second argument. It can both use the native Symfony Serializer and the powerful JMS Serializer.

Note: If you are using Symfony <2.5 and still want to use the serializer, then you'll have to switch to the JMS' one, or you may have some unexpected behavior because of the lack of the PropertyNormalizer class.

Using the Serializer allows you to merge two objects in the specified one by serializing the dataObject parameter into an array, and using it as values to merge in your object/entity.

Note: Of course you can use your own serialization method to inject the dataObject as array in your merge process.

Advanced usage

Merge two objects in the first one (must use any serializer):

use Orbitale\Component\EntityMerger\EntityMerger;

$merger = new EntityMerger(null, $serializer);

$baseObject = new Object;
$baseObject->field = null;

$anotherObject = new Object();
$anotherObject->field = 'value';

$merger->merge($baseObject, $anotherObject);

echo $baseObject->field; // Shows "value"

orbitale/entity-merger 适用场景与选型建议

orbitale/entity-merger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.96k 次下载、GitHub Stars 达 16, 最近一次更新时间为 2015 年 03 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「orm」 「symfony」 「doctrine」 「entity」 「merge」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 orbitale/entity-merger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 orbitale/entity-merger 我们能提供哪些服务?
定制开发 / 二次开发

基于 orbitale/entity-merger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 11.96k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 16
  • 点击次数: 24
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 16
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-03-14