new: [UUID] behaviour added

- auto set UUIDs on objects
remotes/origin/main
iglocska 2020-06-09 15:58:49 +02:00
parent 28c2ac04ea
commit e8d5caefea
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,18 @@
<?php
namespace App\Model\Behavior;
use Cake\ORM\Behavior;
use Cake\Event\EventInterface;
use Cake\Datasource\EntityInterface;
use ArrayObject;
use Cake\Utility\Text;
class UUIDBehavior extends Behavior
{
public function beforeSave(EventInterface $event, EntityInterface $entity, ArrayObject $options)
{
if ($entity->isNew() && empty($entity['uuid'])) {
$entity['uuid'] = Text::uuid();
}
}
}