AtLeastOneTriggerRule.php
3 years ago
ConsistentStepMapRule.php
3 years ago
NoCycleRule.php
2 years ago
NoDuplicateEdgesRule.php
2 years ago
NoJoinRule.php
2 years ago
NoUnreachableStepsRule.php
2 years ago
TriggerNeedsToBeFollowedByActionRule.php
2 years ago
TriggersUnderRootRule.php
2 years ago
UnknownStepRule.php
3 years ago
ValidStepArgsRule.php
3 years ago
ValidStepFiltersRule.php
2 years ago
ValidStepOrderRule.php
3 years ago
ValidStepRule.php
2 months ago
ValidStepValidationRule.php
3 years ago
index.php
3 years ago
ValidStepOrderRule.php
61 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Automation\Engine\Validation\AutomationRules; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Automation\Engine\Control\SubjectTransformerHandler; |
| 9 | use MailPoet\Automation\Engine\Data\Automation; |
| 10 | use MailPoet\Automation\Engine\Data\Step; |
| 11 | use MailPoet\Automation\Engine\Exceptions; |
| 12 | use MailPoet\Automation\Engine\Registry; |
| 13 | use MailPoet\Automation\Engine\Validation\AutomationGraph\AutomationNode; |
| 14 | use MailPoet\Automation\Engine\Validation\AutomationGraph\AutomationNodeVisitor; |
| 15 | |
| 16 | class ValidStepOrderRule implements AutomationNodeVisitor { |
| 17 | /** @var Registry */ |
| 18 | private $registry; |
| 19 | |
| 20 | /** @var SubjectTransformerHandler */ |
| 21 | private $subjectTransformerHandler; |
| 22 | |
| 23 | public function __construct( |
| 24 | Registry $registry, |
| 25 | SubjectTransformerHandler $subjectTransformerHandler |
| 26 | ) { |
| 27 | $this->registry = $registry; |
| 28 | $this->subjectTransformerHandler = $subjectTransformerHandler; |
| 29 | } |
| 30 | |
| 31 | public function initialize(Automation $automation): void { |
| 32 | } |
| 33 | |
| 34 | public function visitNode(Automation $automation, AutomationNode $node): void { |
| 35 | $step = $node->getStep(); |
| 36 | $registryStep = $this->registry->getStep($step->getKey()); |
| 37 | if (!$registryStep) { |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | // triggers don't require any subjects (they provide them) |
| 42 | if ($step->getType() === Step::TYPE_TRIGGER) { |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | $requiredSubjectKeys = $registryStep->getSubjectKeys(); |
| 47 | if (!$requiredSubjectKeys) { |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | $subjectKeys = $this->subjectTransformerHandler->getSubjectKeysForAutomation($automation); |
| 52 | $missingSubjectKeys = array_diff($requiredSubjectKeys, $subjectKeys); |
| 53 | if (count($missingSubjectKeys) > 0) { |
| 54 | throw Exceptions::missingRequiredSubjects($step, $missingSubjectKeys); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | public function complete(Automation $automation): void { |
| 59 | } |
| 60 | } |
| 61 |