riesenia/cakephp-duplicatable
Composer 安装命令:
composer require riesenia/cakephp-duplicatable
包简介
CakePHP ORM plugin for duplicating entities (including related entities)
关键字:
README 文档
README
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
_joinDataproperty inBelongsToManyrelations should be preserved - defaults tofalsedue 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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 riesenia/cakephp-duplicatable 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
CakePHP 4.x AdminLTE Theme.
Avoiding Duplicate Content. Extension for Contao Open Source CMS
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
Email Toolkit Plugin for CakePHP
A fork of the great myclabs/DeepCopy bundle for Symfony
统计信息
- 总下载量: 409.98k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 51
- 点击次数: 31
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-11-06