Add registry service for workflow triggers and actions
[MAILPOET-4136]
This commit is contained in:
48
mailpoet/lib/Automation/Engine/Registry.php
Normal file
48
mailpoet/lib/Automation/Engine/Registry.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace MailPoet\Automation\Engine;
|
||||
|
||||
use MailPoet\Automation\Engine\Workflows\Action;
|
||||
use MailPoet\Automation\Engine\Workflows\Trigger;
|
||||
|
||||
class Registry {
|
||||
/** @var array<string, Trigger> */
|
||||
private $triggers = [];
|
||||
|
||||
/** @var array<string, Action> */
|
||||
private $actions = [];
|
||||
|
||||
public function addTrigger(Trigger $trigger): void {
|
||||
$key = $trigger->getKey();
|
||||
if (isset($this->triggers[$key])) {
|
||||
throw new \Exception(); // TODO
|
||||
}
|
||||
$this->triggers[$key] = $trigger;
|
||||
}
|
||||
|
||||
public function getTrigger(string $key): ?Trigger {
|
||||
return $this->triggers[$key] ?? null;
|
||||
}
|
||||
|
||||
/** @return array<string, Trigger> */
|
||||
public function getTriggers(): array {
|
||||
return $this->triggers;
|
||||
}
|
||||
|
||||
public function addAction(Action $action): void {
|
||||
$key = $action->getKey();
|
||||
if (isset($this->actions[$key])) {
|
||||
throw new \Exception(); // TODO
|
||||
}
|
||||
$this->actions[$key] = $action;
|
||||
}
|
||||
|
||||
public function getAction(string $key): ?Action {
|
||||
return $this->actions[$key] ?? null;
|
||||
}
|
||||
|
||||
/** @return array<string, Action> */
|
||||
public function getActions(): array {
|
||||
return $this->actions;
|
||||
}
|
||||
}
|
@@ -110,6 +110,7 @@ class ContainerConfigurator implements IContainerConfigurator {
|
||||
$container->autowire(\MailPoet\Automation\Engine\Builder\CreateWorkflowController::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Automation\Engine\Engine::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Automation\Engine\Migrations\Migrator::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Automation\Engine\Registry::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Automation\Engine\Storage\WorkflowStorage::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Automation\Engine\WordPress::class)->setPublic(true);
|
||||
// Config
|
||||
|
Reference in New Issue
Block a user