diff --git a/src/Task/TaskFactory.php b/src/Task/TaskFactory.php index 0a5950b..c56a9ca 100644 --- a/src/Task/TaskFactory.php +++ b/src/Task/TaskFactory.php @@ -42,6 +42,7 @@ class TaskFactory { $this->runtime = $runtime; $this->loadBuiltInTasks(); + $this->loadCustomTasks(); } /** @@ -114,4 +115,34 @@ class TaskFactory } } } + + /** + * Load the custom tasks + * + * @throws \RuntimeException + */ + protected function loadCustomTasks() + { + $config = $this->runtime->getConfiguration(); + + if (!isset($config['custom_tasks'])) { + return; + } + + if (!is_array($config['custom_tasks'])) { + throw new \RuntimeException('The "custom_tasks" configuration must be an array'); + } + + foreach ($config['custom_tasks'] as $class) { + if (class_exists($class)) { + $reflex = new ReflectionClass($class); + if ($reflex->isInstantiable()) { + $task = new $class(); + if ($task instanceof AbstractTask) { + $this->add($task); + } + } + } + } + } } diff --git a/tests/Resources/testhost-custom-task.yml b/tests/Resources/testhost-custom-task.yml index 8253e17..b804556 100644 --- a/tests/Resources/testhost-custom-task.yml +++ b/tests/Resources/testhost-custom-task.yml @@ -14,7 +14,9 @@ magephp: - composer/install - composer/dump-autoload on-deploy: - - Mage\Tests\Task\CustomTask + - custom on-release: post-release: - post-deploy: \ No newline at end of file + post-deploy: + custom_tasks: + - Mage\Tests\Task\CustomTask