PluginProbe
The Innovative Form Builder – IvyForms / 0.2
The Innovative Form Builder – IvyForms v0.2
1.5.1 1.5 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 All 27 releases
ivyforms / backend / src / Factory / Notification / NotificationFactory.php

NotificationFactory.php in The Innovative Form Builder – IvyForms 0.2, at backend/src/Factory/Notification/NotificationFactory.php

84 lines 2.2 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\Notification;
4
5 // phpcs:disable PSR1.Files.SideEffects
6 if (!defined('ABSPATH')) {
7 exit; // Exit if accessed directly
8 }
9
10 use IvyForms\Common\Exceptions\InvalidArgumentException;
11 use IvyForms\Entity\Notification\Notification as NotificationEntity;
12 use IvyForms\ValueObjects\Notification\Notification;
13
14 /**
15 * Class NotificationFactory
16 *
17 * @package IvyForms\Factory\Notification
18 */
19 class NotificationFactory
20 {
21 /**
22 * Create a NotificationEntity from an array of data.
23 *
24 * @param array<string, mixed> $data
25 *
26 * @return NotificationEntity
27 * @throws InvalidArgumentException
28 */
29 public static function create(array $data): NotificationEntity
30 {
31 $notificationValueObject = new Notification(
32 $data['id'] ?? 0,
33 $data['name'] ?? '',
34 $data['sender'] ?? '',
35 $data['receiver'] ?? '',
36 $data['enabled'] ?? true,
37 $data['subject'] ?? '',
38 $data['message'] ?? '',
39 $data['smartLogic'] ?? false,
40 $data['formId'] ?? 0
41 );
42
43 $notificationEntity = new NotificationEntity($notificationValueObject);
44
45 if (isset($data['id'])) {
46 $notificationEntity->setId($data['id']);
47 }
48
49 if (isset($data['name'])) {
50 $notificationEntity->setName($data['name']);
51 }
52
53 if (isset($data['sender'])) {
54 $notificationEntity->setSender($data['sender']);
55 }
56
57 if (isset($data['receiver'])) {
58 $notificationEntity->setReceiver($data['receiver']);
59 }
60
61 if (isset($data['enabled'])) {
62 $notificationEntity->setEnabled($data['enabled']);
63 }
64
65 if (isset($data['subject'])) {
66 $notificationEntity->setSubject($data['subject']);
67 }
68
69 if (isset($data['message'])) {
70 $notificationEntity->setMessage($data['message']);
71 }
72
73 if (isset($data['smartLogic'])) {
74 $notificationEntity->setSmartLogic($data['smartLogic']);
75 }
76
77 if (isset($data['formId'])) {
78 $notificationEntity->setFormId($data['formId']);
79 }
80
81 return $notificationEntity;
82 }
83 }
84