定制 tuscanicz/doctrine-data-applier 二次开发

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

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

tuscanicz/doctrine-data-applier

Composer 安装命令:

composer require tuscanicz/doctrine-data-applier

包简介

Symfony bundle for Doctrine Migrations of data using doctrine entities.

README 文档

README

Symfony bundle for Doctrine Migrations of data using doctrine entities. Use this tool to describe your database data by doctrine entities. It requires to modify your entities a bit but for that price, you'll get a mighty tool that will auto-merge entities in your application with those in your database.

This is very useful when you need to keep your data up-to-date in many environments and are necessary for your application to run.

Typical use-case is a user table with your administrator, content manager and other "obligatory" users or enumerations that are used across your app.

DataApplier will never affect any data that was not created by DataApplier so your user data can live next to data applier data together in one table.

How to use

Add composer dependency: composer require tuscanicz/doctrine-data-applier:dev-develop

Modify your Entity to be useful with Data Applier

You need to add some columns to doctrine entity to make them managable by data applier.

In order to do so you'll have to implement DataApplier\Entity\DataApplicableEntityInterface that will force you to use DataApplier\Entity\DataApplicableEntityTrait and present id column with setter and getter.

This id must be your primary key in database, see a typical annotation:

/**
 * @var int
 * @ORM\Column(type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue()
 */
private $id;

public function getId()
{
    return $this->id;
}

public function setId(int $id)
{
    $this->id = $id;
}

I expect that most of the doctrine entities have such column already defined. If you define your id with different name or consists of complex keys, you'll have to fork this repository and fix this limitation :)

Next, you'll have to decide what are the DataApplier identifier columns.

This tool will decide whether to delete the row, update the data or insert new by matching your database contents with entities in your application.

Annotate them with DataApplier\Annotation\DataApplierIdentifier:

/**
 * @var string
 * @ORM\Column(type="string")
 * @DataApplierIdentifier()
 */
private $key;

Then create a factory method /or factory class that will set all the necessary attributes to your entity. Don't include the primary key in database (id), these will differ on your environments.

Example:

public static function createNew($value, $key)
{
    $self = new self;
    $self->setKey($key);
    $self->setValue($value);

    return $self;
}

Update the database

Use doctrine:migrations to change the entities. Generating a diff will add a few columns that will help DataApplier to identify a source of data.

Create a DataApplier for your entity

Data applier consists of multiple DataAppliers that will implement DataApplier\Data\DataApplierInterface.

The only method applyData() will return an array of entities that you need to keep in your database:

class TestDataApplier1 implements DataApplierInterface
{
    public function applyData()
    {
        return [
            TestEntity::createNew('value1', 'key1'),
            TestEntity::createNew('value2', 'key2'),
            TestEntity::createNew('value3', 'key3'),
        ];
    }
}

You must register TestDataApplier1 as Symfony service and add doctrine.data_applier tag:

<service id="your_app.data.test_data_applier1" class="YourApp\Data\TestDataApplier1">
    <tag name="doctrine.data_applier"/>
</service>

Register DataApplier bundle

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            ...,
            new \DataApplier\DataApplierBundle()
        ];
    }
}

Run DataApplier

If you managed to go thru all the previous steps - congratulations. :)

You can now run your data applier via Symfony console: php bin/console data:apply

This will update your data in your database.

tuscanicz/doctrine-data-applier 适用场景与选型建议

tuscanicz/doctrine-data-applier 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 05 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 tuscanicz/doctrine-data-applier 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-05-30