We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 9abf626 + 3590b29 commit 0b817f7Copy full SHA for 0b817f7
src/Models/Behaviors/Uuid.php
@@ -0,0 +1,33 @@
1
+<?php
2
+declare(strict_types=1);
3
+
4
+namespace Canvas\Models\Behaviors;
5
6
+use Phalcon\Mvc\Model\Behavior;
7
+use Phalcon\Mvc\ModelInterface;
8
+use Phalcon\Security\Random;
9
10
+class Uuid extends Behavior
11
+{
12
+ /**
13
+ * Behavior implementation for Uuid.
14
+ *
15
+ * @param string $eventType
16
+ * @param ModelInterface $model
17
18
+ * @return void
19
+ */
20
+ public function notify(string $eventType, ModelInterface $model) : void
21
+ {
22
+ $random = new Random();
23
24
+ $options = $this->getOptions();
25
+ $field = $options['field'] ?? 'uuid';
26
27
+ switch ($eventType) {
28
+ case 'beforeValidationOnCreate':
29
+ $model->writeAttribute($field, $random->uuid());
30
+ break;
31
+ }
32
33
+}
0 commit comments