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
Field.php
74 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\Integration\Payload; |
| 9 | |
| 10 | class Field { |
| 11 | public const TYPE_BOOLEAN = 'boolean'; |
| 12 | public const TYPE_INTEGER = 'integer'; |
| 13 | public const TYPE_NUMBER = 'number'; |
| 14 | public const TYPE_STRING = 'string'; |
| 15 | public const TYPE_ENUM = 'enum'; |
| 16 | public const TYPE_ENUM_ARRAY = 'enum_array'; |
| 17 | public const TYPE_DATETIME = 'datetime'; |
| 18 | |
| 19 | /** @var string */ |
| 20 | private $key; |
| 21 | |
| 22 | /** @var string */ |
| 23 | private $type; |
| 24 | |
| 25 | /** @var string */ |
| 26 | private $name; |
| 27 | |
| 28 | /** @var callable */ |
| 29 | private $factory; |
| 30 | |
| 31 | /** @var array */ |
| 32 | private $args; |
| 33 | |
| 34 | public function __construct( |
| 35 | string $key, |
| 36 | string $type, |
| 37 | string $name, |
| 38 | callable $factory, |
| 39 | array $args = [] |
| 40 | ) { |
| 41 | |
| 42 | $this->key = $key; |
| 43 | $this->type = $type; |
| 44 | $this->name = $name; |
| 45 | $this->factory = $factory; |
| 46 | $this->args = $args; |
| 47 | } |
| 48 | |
| 49 | public function getKey(): string { |
| 50 | return $this->key; |
| 51 | } |
| 52 | |
| 53 | public function getType(): string { |
| 54 | return $this->type; |
| 55 | } |
| 56 | |
| 57 | public function getName(): string { |
| 58 | return $this->name; |
| 59 | } |
| 60 | |
| 61 | public function getFactory(): callable { |
| 62 | return $this->factory; |
| 63 | } |
| 64 | |
| 65 | /** @return mixed */ |
| 66 | public function getValue(Payload $payload, array $params = []) { |
| 67 | return $this->getFactory()($payload, $params); |
| 68 | } |
| 69 | |
| 70 | public function getArgs(): array { |
| 71 | return $this->args; |
| 72 | } |
| 73 | } |
| 74 |