Automation.php
2 months ago
AutomationRun.php
1 year ago
AutomationRunLog.php
1 year ago
AutomationStatistics.php
9 months ago
AutomationTemplate.php
6 months ago
AutomationTemplateCategory.php
2 years ago
Field.php
2 years ago
Filter.php
3 years ago
FilterGroup.php
2 months ago
Filters.php
2 months ago
NextStep.php
2 years ago
Step.php
2 months ago
StepRunArgs.php
2 years ago
StepValidationArgs.php
3 years ago
Subject.php
3 years ago
SubjectEntry.php
3 years ago
index.php
3 years ago
Subject.php
49 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Automation\Engine\Data; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Automation\Engine\Utils\Json; |
| 9 | |
| 10 | class Subject { |
| 11 | /** @var string */ |
| 12 | private $key; |
| 13 | |
| 14 | /** @var array */ |
| 15 | private $args; |
| 16 | |
| 17 | public function __construct( |
| 18 | string $key, |
| 19 | array $args |
| 20 | ) { |
| 21 | $this->key = $key; |
| 22 | $this->args = $args; |
| 23 | } |
| 24 | |
| 25 | public function getKey(): string { |
| 26 | return $this->key; |
| 27 | } |
| 28 | |
| 29 | public function getArgs(): array { |
| 30 | return $this->args; |
| 31 | } |
| 32 | |
| 33 | public function getHash(): string { |
| 34 | return md5($this->getKey() . serialize($this->getArgs())); |
| 35 | } |
| 36 | |
| 37 | public function toArray(): array { |
| 38 | return [ |
| 39 | 'key' => $this->getKey(), |
| 40 | 'args' => Json::encode($this->getArgs()), |
| 41 | 'hash' => $this->getHash(), |
| 42 | ]; |
| 43 | } |
| 44 | |
| 45 | public static function fromArray(array $data): self { |
| 46 | return new self($data['key'], Json::decode($data['args'])); |
| 47 | } |
| 48 | } |
| 49 |