riesenia/cakephp-duplicatable 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

riesenia/cakephp-duplicatable

Composer 安装命令:

composer require riesenia/cakephp-duplicatable

包简介

CakePHP ORM plugin for duplicating entities (including related entities)

README 文档

README

CI Coverage Status Latest Version Total Downloads Software License

This plugin contains a behavior that handles duplicating entities including related data.

Installation

Using composer

composer require riesenia/cakephp-duplicatable

Load plugin using

bin/cake plugin load Duplicatable

Usage

This behavior provides multiple methods for your Table objects.

Method duplicate

This behavior provides a duplicate method for the table. It takes the primary key of the record to duplicate as its only argument. Using this method will clone the record defined by the primary key provided as well as all related records as defined in the configuration.

Method duplicateEntity

This behavior provides a duplicateEntity method for the table. It mainly acts as the duplicate method except it does not save the duplicated record but returns the Entity to be saved instead. This is useful if you need to manipulate the Entity before saving it.

Configuration options:

  • finder - finder to use to get entities. Set it to "translations" to fetch and duplicate translations, too. Defaults to "all". It is possible to set an array for more finders.
  • contain - set related entities that will be duplicated
  • remove - fields that will be removed from the entity
  • set - fields that will be set to provide value or callable to modify the value. If you provide a callable, it will take the entity being cloned as the only argument
  • prepend - fields that will have value prepended by the provided text
  • append - fields that will have value appended by provided text
  • saveOptions - options for save on primary table
  • preserveJoinData - if _joinData property in BelongsToMany relations should be preserved - defaults to false due to tricky nature of this association

Examples

class InvoicesTable extends Table
{
    public function initialize(array $config): void
    {
        parent::initialize($config);

        // add Duplicatable behavior
        $this->addBehavior('Duplicatable.Duplicatable', [
            // table finder
            'finder' => 'all',
            // duplicate also items and their properties
            'contain' => ['InvoiceItems.InvoiceItemProperties'],
            // remove created field from both invoice and items
            'remove' => ['created', 'invoice_items.created'],
            // mark invoice as copied
            'set' => [
                'name' => function($entity) {
                    return md5($entity->name) . ' ' . $entity->name;
                },
                'copied' => true
            ],
            // prepend properties name
            'prepend' => ['invoice_items.invoice_items_properties.name' => 'NEW '],
            // append copy to the name
            'append' => ['name' => ' - copy']
        ]);

        // associations (InvoiceItems table hasMany InvoiceItemProperties)
        $this->hasMany('InvoiceItems', [
            'foreignKey' => 'invoice_id',
            'className' => 'InvoiceItems'
        ]);
    }
}

// ... somewhere in the controller
$this->Invoices->duplicate(4);

Sometimes you need to access the original entity, e.g. for setting an ancestor/parent id reference. In this case you can leverage the $original entity being passed in as 2nd argument:

'set' => [
    'ancestor_id' => function ($entity, $original) {
        return $original->id;
    },
],

riesenia/cakephp-duplicatable 适用场景与选型建议

riesenia/cakephp-duplicatable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 409.98k 次下载、GitHub Stars 达 51, 最近一次更新时间为 2015 年 11 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 riesenia/cakephp-duplicatable 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 409.98k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 51
  • 点击次数: 31
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 51
  • Watchers: 8
  • Forks: 18
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-11-06