|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Conveyor package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Jeroen Fiege <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Webcreate\Conveyor\Factory; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
15
|
|
|
use Webcreate\Conveyor\Config\YamlConfig; |
|
16
|
|
|
use Webcreate\Conveyor\IO\IOInterface; |
|
17
|
|
|
use Webcreate\Conveyor\Task\TaskRunner; |
|
18
|
|
|
|
|
19
|
|
|
class TaskRunnerFactory |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @param string $taskConfigPath path to the tasks configuration in the conveyor.yml config |
|
23
|
|
|
* @param TaskFactory $taskFactory |
|
24
|
|
|
* @param YamlConfig $config |
|
25
|
|
|
* @param IOInterface $io |
|
26
|
|
|
* @param EventDispatcherInterface $dispatcher |
|
27
|
|
|
* @return TaskRunner |
|
28
|
|
|
*/ |
|
29
|
|
|
public static function get($taskConfigPath, TaskFactory $taskFactory, YamlConfig $config, IOInterface $io, EventDispatcherInterface $dispatcher = null) |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
$_config = $config->getConfig(); |
|
32
|
|
|
|
|
33
|
|
|
$taskRunner = new TaskRunner($io, $dispatcher); |
|
34
|
|
|
|
|
35
|
|
|
foreach ((array) self::getTasksConfig($_config, $taskConfigPath) as $t => $taskConfig) { |
|
36
|
|
|
$task = $taskFactory->get($taskConfig['type'], $taskConfig); |
|
37
|
|
|
$taskRunner->addTask($task); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
return $taskRunner; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param array $config |
|
45
|
|
|
* @param string $taskConfigPath |
|
46
|
|
|
* @return array |
|
47
|
|
|
*/ |
|
48
|
|
|
protected static function getTasksConfig(array $config, $taskConfigPath) |
|
49
|
|
|
{ |
|
50
|
|
|
$path = explode('.', $taskConfigPath); |
|
51
|
|
|
|
|
52
|
|
|
$currentConfig = $config; |
|
53
|
|
|
|
|
54
|
|
|
foreach ($path as $p => $_path) { |
|
55
|
|
|
if (!isset($currentConfig[$_path])) { |
|
56
|
|
|
return array(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$currentConfig = $currentConfig[$_path]; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return $currentConfig; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.