1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Genesis; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use Genesis\Commands; |
8
|
|
|
use Genesis\Config; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author Adam Bisek <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class Build implements IBuild |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
protected $container; |
17
|
|
|
|
18
|
|
|
protected $arguments; |
19
|
|
|
|
20
|
|
|
|
21
|
14 |
|
public function __construct(Config\Container $container, array $arguments = NULL) |
22
|
|
|
{ |
23
|
14 |
|
$this->container = $container; |
24
|
14 |
|
$this->arguments = $arguments; |
25
|
14 |
|
} |
26
|
|
|
|
27
|
|
|
|
28
|
9 |
|
public function setup() |
29
|
|
|
{ |
30
|
9 |
|
} |
31
|
|
|
|
32
|
|
|
|
33
|
3 |
|
public function runDefault() |
34
|
|
|
{ |
35
|
3 |
|
$helpCommand = new Commands\Help; |
36
|
3 |
|
foreach ($this->detectAvailableTasks() as $section => $tasks) { |
37
|
3 |
|
if (!$helpCommand->hasSection($section)) { |
38
|
3 |
|
$helpCommand->addSection($section); |
39
|
3 |
|
} |
40
|
3 |
|
$helpCommand->setSectionTasks($section, $tasks); |
41
|
3 |
|
} |
42
|
3 |
|
$helpCommand->execute(); |
43
|
3 |
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
3 |
|
protected function detectAvailableTasks() |
47
|
|
|
{ |
48
|
3 |
|
$tasks = []; |
49
|
3 |
|
$classReflection = new \ReflectionClass($this); |
50
|
3 |
|
foreach ($classReflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { |
51
|
3 |
|
if (preg_match('#^run(.*)#', $method->name, $match)) { |
52
|
3 |
|
$doc = $method->getDocComment(); |
53
|
3 |
|
$section = NULL; |
54
|
3 |
|
if (preg_match('#@section ?([^\s]*)\s#s', $doc, $m)) { |
55
|
3 |
|
$section = trim($m[1]); |
56
|
3 |
|
} |
57
|
3 |
|
$description = NULL; |
58
|
3 |
|
if (preg_match('#([^@][a-zA-Z0-9]+)+#', $doc, $m)) { |
59
|
3 |
|
$description = trim($m[0]); |
60
|
3 |
|
} |
61
|
3 |
|
$tasks[$section][lcfirst($match[1])] = $description != '' ? $description : NULL; |
62
|
3 |
|
} |
63
|
3 |
|
} |
64
|
3 |
|
return $tasks; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
1 |
|
protected function error($message) |
69
|
|
|
{ |
70
|
1 |
|
throw new ErrorException($message); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
3 |
|
protected function logSection($message) |
75
|
|
|
{ |
76
|
3 |
|
echo Cli::getColoredString("=> " . $message, 'green') . PHP_EOL; |
77
|
3 |
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
8 |
|
protected function log($message) |
81
|
|
|
{ |
82
|
8 |
|
echo $message . PHP_EOL; |
83
|
7 |
|
} |
84
|
|
|
|
85
|
|
|
} |