diff --git a/src/Action.php b/src/AbstractTask.php similarity index 100% rename from src/Action.php rename to src/AbstractTask.php diff --git a/src/Tasks.php b/src/Tasks.php new file mode 100644 index 0000000..c78f9ad --- /dev/null +++ b/src/Tasks.php @@ -0,0 +1,77 @@ + $stack The tasks stack */ + private array $stack = []; + + /** + * Contructor load cleaners. + */ + public function __construct() + { + # --BEHAVIOR-- improveTaskAdd: Tasks + dcCore::app()->callBehavior('improveTaskAdd', $this); + + uasort($this->stack, fn ($a, $b) => $a->name() <=> $b->name()); + uasort($this->stack, fn ($a, $b) => $a->priority() <=> $b->priority()); + } + + /** + * Add an task. + * + * @param AbstractTask $task The task instance + * + * @return Tasks Self instance + */ + public function add(AbstractTask $task): Tasks + { + if (!isset($this->stack[$task->id()])) { + $this->stack[$task->id()] = $task; + } + + return $this; + } + + /** + * Get all tasks. + * + * @return array The tasks stack + */ + public function dump(): array + { + return $this->stack; + } + + /** + * Get a task. + * + * @param string $id The task id + * + * @return null|AbstractTask The task + */ + public function get(string $id): ?AbstractTask + { + return $this->stack[$id] ?? null; + } +}