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 / Entry / EntryFactory.php

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

81 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @copyright © Melograno Venture Studio. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace IvyForms\Factory\Entry;
9
10 // phpcs:disable PSR1.Files.SideEffects
11 if (!defined('ABSPATH')) {
12 exit; // Exit if accessed directly
13 }
14
15 use IvyForms\Common\Exceptions\ValidationException;
16 use IvyForms\Entity\Entry\Entry as EntryEntity;
17 use IvyForms\Entity\EntryField\EntryField;
18 use IvyForms\Factory\EntryField\EntryFieldFactory;
19 use IvyForms\ValueObjects\Entry\Entry;
20
21 /**
22 * Class EntryFactory
23 *
24 * @package IvyForms\Factory\Entry
25 */
26 class EntryFactory
27 {
28 /**
29 * Create an EntryEntity from the provided data.
30 *
31 * @param array<string, mixed> $data The entry data.
32 *
33 * @return EntryEntity
34 *
35 * @throws ValidationException
36 */
37 public static function create(array $data): EntryEntity
38 {
39
40 $entryObject = new Entry(
41 $data['id'] ?? 0,
42 $data['formId'] ?? 0,
43 $data['userId'] ?? null,
44 $data['status'] ?? EntryEntity::DEFAULT_STATUS,
45 $data['ipAddress'] ?? null,
46 $data['userAgent'] ?? null,
47 $data['sourceURL'] ?? null,
48 );
49
50 $entry = new EntryEntity($entryObject);
51
52 if (isset($data['id'])) {
53 $entry->setId($data['id']);
54 }
55
56 if (isset($data['formId'])) {
57 $entry->setFormId($data['formId']);
58 }
59 if (isset($data['userId'])) {
60 $entry->setUserId($data['userId']);
61 }
62 if (isset($data['status'])) {
63 $entry->setStatus($data['status']);
64 }
65 if (isset($data['ipAddress'])) {
66 $entry->setIpAddress($data['ipAddress']);
67 }
68 if (isset($data['userAgent'])) {
69 $entry->setUserAgent($data['userAgent']);
70 }
71 if (isset($data['sourceURL'])) {
72 $entry->setSourceURL($data['sourceURL']);
73 }
74 if (isset($data['starred'])) {
75 $entry->setStarred($data['starred']);
76 }
77
78 return $entry;
79 }
80 }
81