Files
piratepoet/mailpoet/lib/Automation/Engine/Control/Steps/ActionStepRunner.php
John Oleksowicz 5227481a42 Revert to a simpler approach
Having separate objects for validation results is unnecessary and overly
 complicated at this point, and we should wait to introduce that kind of
  complexity only when/if it's clearly needed.

[MAILPOET-4191]
2022-04-18 09:10:23 +02:00

32 lines
901 B
PHP

<?php declare(strict_types = 1);
namespace MailPoet\Automation\Engine\Control\Steps;
use MailPoet\Automation\Engine\Exceptions\InvalidStateException;
use MailPoet\Automation\Engine\Registry;
use MailPoet\Automation\Engine\Workflows\Step;
use MailPoet\Automation\Engine\Workflows\Workflow;
use MailPoet\Automation\Engine\Workflows\WorkflowRun;
class ActionStepRunner {
/** @var Registry */
private $registry;
public function __construct(
Registry $registry
) {
$this->registry = $registry;
}
public function run(Step $step, Workflow $workflow, WorkflowRun $workflowRun): void {
$action = $this->registry->getAction($step->getKey());
if (!$action) {
throw new InvalidStateException();
}
if (!$action->hasRequiredSubjects($workflowRun->getSubjects())) {
throw new InvalidStateException();
}
$action->run($workflow, $workflowRun, $step);
}
}