From 2039237aef3f57e42dea4032e8d7357d8eeee480 Mon Sep 17 00:00:00 2001 From: Kamil Kuzminski Date: Wed, 8 Feb 2017 17:31:41 +0100 Subject: [PATCH 1/2] Added the support for custom tasks --- src/Task/TaskFactory.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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); + } + } + } + } + } } From 6f3fd93d4c913e0524afa6b0ade006a09fccb10a Mon Sep 17 00:00:00 2001 From: Kamil Kuzminski Date: Wed, 8 Feb 2017 19:03:13 +0100 Subject: [PATCH 2/2] Bump the test code coverage --- tests/Resources/testhost-custom-task.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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