| 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['replyTo'] ?? '', |
| 36 |
$data['receiver'] ?? '', |
| 37 |
$data['enabled'] ?? true, |
| 38 |
$data['subject'] ?? '', |
| 39 |
$data['message'] ?? '', |
| 40 |
$data['smartLogic'] ?? false, |
| 41 |
$data['formId'] ?? 0 |
| 42 |
); |
| 43 |
|
| 44 |
$notificationEntity = new NotificationEntity($notificationValueObject); |
| 45 |
|
| 46 |
if (isset($data['id'])) { |
| 47 |
$notificationEntity->setId($data['id']); |
| 48 |
} |
| 49 |
|
| 50 |
if (isset($data['name'])) { |
| 51 |
$notificationEntity->setName($data['name']); |
| 52 |
} |
| 53 |
|
| 54 |
if (isset($data['sender'])) { |
| 55 |
$notificationEntity->setSender($data['sender']); |
| 56 |
} |
| 57 |
|
| 58 |
if (isset($data['replyTo'])) { |
| 59 |
$notificationEntity->setReplyTo($data['replyTo']); |
| 60 |
} |
| 61 |
|
| 62 |
if (isset($data['receiver'])) { |
| 63 |
$notificationEntity->setReceiver($data['receiver']); |
| 64 |
} |
| 65 |
|
| 66 |
if (isset($data['enabled'])) { |
| 67 |
$notificationEntity->setEnabled($data['enabled']); |
| 68 |
} |
| 69 |
|
| 70 |
if (isset($data['subject'])) { |
| 71 |
$notificationEntity->setSubject($data['subject']); |
| 72 |
} |
| 73 |
|
| 74 |
if (isset($data['message'])) { |
| 75 |
$notificationEntity->setMessage(wp_unslash($data['message'])); |
| 76 |
} |
| 77 |
|
| 78 |
if (isset($data['smartLogic'])) { |
| 79 |
$notificationEntity->setSmartLogic($data['smartLogic']); |
| 80 |
} |
| 81 |
|
| 82 |
if (isset($data['formId'])) { |
| 83 |
$notificationEntity->setFormId($data['formId']); |
| 84 |
} |
| 85 |
|
| 86 |
return $notificationEntity; |
| 87 |
} |
| 88 |
} |
| 89 |
|