| 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(wp_unslash($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 |
|