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
AutomationTemplate.php
126 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Automation\Engine\Data; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | class AutomationTemplate { |
| 9 | public const TYPE_DEFAULT = 'default'; |
| 10 | public const TYPE_PREMIUM = 'premium'; |
| 11 | public const TYPE_COMING_SOON = 'coming-soon'; |
| 12 | |
| 13 | /** @var string */ |
| 14 | private $slug; |
| 15 | |
| 16 | /** @var string */ |
| 17 | private $category; |
| 18 | |
| 19 | /** @var string */ |
| 20 | private $name; |
| 21 | |
| 22 | /** @var string */ |
| 23 | private $description; |
| 24 | |
| 25 | /** @var callable(bool $preview=): Automation */ |
| 26 | private $automationFactory; |
| 27 | |
| 28 | /** @var array<string, int|bool> */ |
| 29 | private $requiredCapabilities; |
| 30 | |
| 31 | /** @var string */ |
| 32 | private $type; |
| 33 | |
| 34 | /** @var string|null */ |
| 35 | private $icon; |
| 36 | |
| 37 | /** @var string */ |
| 38 | private $iconType; |
| 39 | |
| 40 | /** @var bool */ |
| 41 | private $isRecommended; |
| 42 | |
| 43 | /** |
| 44 | * @param callable(bool $preview=): Automation $automationFactory |
| 45 | * @param array<string, int|bool> $requiredCapabilities |
| 46 | */ |
| 47 | public function __construct( |
| 48 | string $slug, |
| 49 | string $category, |
| 50 | string $name, |
| 51 | string $description, |
| 52 | callable $automationFactory, |
| 53 | array $requiredCapabilities = [], |
| 54 | string $type = self::TYPE_DEFAULT, |
| 55 | ?string $icon = null, |
| 56 | string $iconType = 'wordpress', |
| 57 | bool $isRecommended = false |
| 58 | ) { |
| 59 | $this->slug = $slug; |
| 60 | $this->category = $category; |
| 61 | $this->name = $name; |
| 62 | $this->description = $description; |
| 63 | $this->automationFactory = $automationFactory; |
| 64 | $this->requiredCapabilities = $requiredCapabilities; |
| 65 | $this->type = $type; |
| 66 | $this->icon = $icon; |
| 67 | $this->iconType = $iconType; |
| 68 | $this->isRecommended = $isRecommended; |
| 69 | } |
| 70 | |
| 71 | public function getSlug(): string { |
| 72 | return $this->slug; |
| 73 | } |
| 74 | |
| 75 | public function getName(): string { |
| 76 | return $this->name; |
| 77 | } |
| 78 | |
| 79 | public function getCategory(): string { |
| 80 | return $this->category; |
| 81 | } |
| 82 | |
| 83 | public function getType(): string { |
| 84 | return $this->type; |
| 85 | } |
| 86 | |
| 87 | public function getDescription(): string { |
| 88 | return $this->description; |
| 89 | } |
| 90 | |
| 91 | /** @return array<string, int|bool> */ |
| 92 | public function getRequiredCapabilities(): array { |
| 93 | return $this->requiredCapabilities; |
| 94 | } |
| 95 | |
| 96 | public function getIcon(): ?string { |
| 97 | return $this->icon; |
| 98 | } |
| 99 | |
| 100 | public function getIconType(): string { |
| 101 | return $this->iconType; |
| 102 | } |
| 103 | |
| 104 | public function isRecommended(): bool { |
| 105 | return $this->isRecommended; |
| 106 | } |
| 107 | |
| 108 | public function createAutomation(bool $preview = false): Automation { |
| 109 | return ($this->automationFactory)($preview); |
| 110 | } |
| 111 | |
| 112 | public function toArray(): array { |
| 113 | return [ |
| 114 | 'slug' => $this->getSlug(), |
| 115 | 'name' => $this->getName(), |
| 116 | 'category' => $this->getCategory(), |
| 117 | 'type' => $this->getType(), |
| 118 | 'required_capabilities' => $this->getRequiredCapabilities(), |
| 119 | 'description' => $this->getDescription(), |
| 120 | 'icon' => $this->getIcon(), |
| 121 | 'icon_type' => $this->getIconType(), |
| 122 | 'is_recommended' => $this->isRecommended(), |
| 123 | ]; |
| 124 | } |
| 125 | } |
| 126 |