jeyroik / extas-repositories-uuid-fields
该软件包最新版本(1.0.0)没有提供许可信息。
extas 的 UUID 字段支持
1.0.0
2020-09-02 16:10 UTC
Requires
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-29 05:36:09 UTC
README
描述
允许在创建时自动填充 UUID 字段。
用法
- 为您的仓库创建阶段添加插件。
- 安装插件。
- 将字段标记(见下文)放入字段值中。
适用字段标记
@uuid6
@uuid4
@uuid5.<namespace>.<name>
示例
准备仓库 + 项目类。
namespace example; use extas\components\repositories\Repository; use extas\components\Item; use extas\components\THasId; class Example extends Item { use THasId; public function getUuid() { return $this->config['uuid'] ?? ''; } protected function getSubjectForExtension() : string { return 'example'; } } class ExampleRepo extends Repository { protected string $name = 'example'; protected string $itemClass = Example::class; }
extas.json
{ "plugins": [ { "class": "extas\\components\\plugins\\repositories\\PluginUUidField", "stage": "extas.example.create.before" } ] }
用法
use example\Example; use example\ExampleRepo; $example = new Example(['uuid' => '@uuid4']); $repo = new ExampleRepo(); $created = $repo->create($example); echo $created->getUuid(); // something like af29a3f4-f865-3a4a-8a87-dc8dc0b813cr
注意
您的仓库应允许 create before stage
(默认情况下是这样)。
有关详细信息,请参阅 extas\components\repositories\Repository::isAllowCreateBeforeStage
属性。