PluginProbe
The Innovative Form Builder – IvyForms / 0.8
The Innovative Form Builder – IvyForms v0.8
1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 1.2 1.3
ivyforms / backend / src / Factory / EntryField / EntryFieldFactory.php

EntryFieldFactory.php in The Innovative Form Builder – IvyForms 0.8, at backend/src/Factory/EntryField/EntryFieldFactory.php

46 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Factory\EntryField;
4
5 use IvyForms\Common\Exceptions\ValidationException;
6 use IvyForms\Common\Sanitizer\Sanitizer;
7 use IvyForms\Entity\EntryField\EntryField as EntryFieldEntity;
8 use IvyForms\ValueObjects\Entry\EntryField as EntryFieldValueObject;
9
10 class EntryFieldFactory
11 {
12 /**
13 * Create an EntryField entity from array data.
14 *
15 * @param array<mixed> $data
16 * @return EntryFieldEntity
17 * @throws ValidationException
18 */
19 public static function create(array $data): EntryFieldEntity
20 {
21 $normalizedFieldValue = Sanitizer::normalizeFieldValue($data['fieldValue'] ?? '');
22 $entryFieldObject = new EntryFieldValueObject(
23 $data['id'] ?? null,
24 $data['entryId'] ?? null,
25 $data['fieldId'] ?? '',
26 $normalizedFieldValue
27 );
28
29 $entryField = new EntryFieldEntity($entryFieldObject);
30
31 if (isset($data['id'])) {
32 $entryField->setId($data['id']);
33 }
34 if (isset($data['entryId'])) {
35 $entryField->setEntryId($data['entryId']);
36 }
37 if (isset($data['fieldId'])) {
38 $entryField->setFieldId($data['fieldId']);
39 }
40 if (isset($data['fieldValue'])) {
41 $entryField->setFieldValue($normalizedFieldValue);
42 }
43 return $entryField;
44 }
45 }
46