mirror of
https://github.com/andres-montanez/Magallanes
synced 2024-06-26 17:20:13 +02:00
Added the support for custom tasks
This commit is contained in:
parent
b36f90e80a
commit
2039237aef
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue