jeyroik / extas-repositories-fields-uuid
UUID fields support for extas
Installs: 2 095
Dependents: 5
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
Requires (Dev)
This package is auto-updated.
Last update: 2024-11-10 03:00:22 UTC
README
Описание
Allow to auto-fill fields on create with uuid.
Usage
- Add plugin for your repo create stage.
- Install plugin.
- Place field marker (see below) into field value.
Applicable field markers
@uuid6
@uuid4
@uuid5.<namespace>.<name>
Example
Prepare repository + item class.
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" } ] }
Usage
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
Notice
Your repository should allow create before stage
(this is by default).
See extas\components\repositories\Repository::isAllowCreateBeforeStage
property for details.