|
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
|
|
|
/** @var Config\Container */ |
|
17
|
|
|
private $container; |
|
18
|
|
|
|
|
19
|
|
|
/** @var array|NULL */ |
|
20
|
|
|
private $arguments; |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
15 |
|
public function __construct(Config\Container $container, array $arguments = NULL) |
|
24
|
|
|
{ |
|
25
|
15 |
|
$this->container = $container; |
|
26
|
15 |
|
$this->arguments = $arguments; |
|
27
|
15 |
|
} |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @return Config\Container |
|
32
|
|
|
*/ |
|
33
|
3 |
|
public function getContainer() |
|
34
|
|
|
{ |
|
35
|
3 |
|
return $this->container; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @return array|NULL |
|
41
|
|
|
*/ |
|
42
|
4 |
|
public function getArguments() |
|
43
|
|
|
{ |
|
44
|
4 |
|
return $this->arguments; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Back compatibility. |
|
49
|
|
|
* @TODO: remove in version 3.x |
|
50
|
|
|
* @codeCoverageIgnoreStart |
|
51
|
|
|
*/ |
|
52
|
|
|
public function &__get($name) |
|
53
|
|
|
{ |
|
54
|
|
|
if(in_array($name, ['container', 'arguments'])){ |
|
55
|
|
|
$method = 'get' . ucfirst($name); |
|
56
|
|
|
trigger_error("Property '$name' is deprecated, use method $method() instead.", E_USER_WARNING); |
|
57
|
|
|
$var = $this->$method(); |
|
58
|
|
|
return $var; |
|
59
|
|
|
} |
|
60
|
|
|
trigger_error(E_USER_WARNING, "Property '$name' is not defined."); |
|
61
|
|
|
}//@codeCoverageIgnoreEnd |
|
62
|
|
|
|
|
63
|
9 |
|
public function setup() |
|
64
|
|
|
{ |
|
65
|
9 |
|
} |
|
66
|
|
|
|
|
67
|
|
|
|
|
68
|
3 |
|
public function runDefault() |
|
69
|
|
|
{ |
|
70
|
3 |
|
$helpCommand = new Commands\Help; |
|
71
|
3 |
|
foreach ($this->detectAvailableTasks() as $section => $tasks) { |
|
72
|
3 |
|
if (!$helpCommand->hasSection($section)) { |
|
73
|
3 |
|
$helpCommand->addSection($section); |
|
74
|
3 |
|
} |
|
75
|
3 |
|
$helpCommand->setSectionTasks($section, $tasks); |
|
76
|
3 |
|
} |
|
77
|
3 |
|
$helpCommand->execute(); |
|
78
|
3 |
|
} |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
3 |
|
protected function detectAvailableTasks() |
|
82
|
1 |
|
{ |
|
83
|
3 |
|
$tasks = []; |
|
84
|
3 |
|
$classReflection = new \ReflectionClass($this); |
|
85
|
3 |
|
foreach ($classReflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { |
|
86
|
3 |
|
if (preg_match('#^run(.*)#', $method->name, $match)) { |
|
87
|
3 |
|
$doc = $method->getDocComment(); |
|
88
|
3 |
|
$section = NULL; |
|
89
|
3 |
|
if (preg_match('#@section ?([^\s]*)\s#s', $doc, $m)) { |
|
90
|
3 |
|
$section = trim($m[1]); |
|
91
|
3 |
|
} |
|
92
|
3 |
|
$description = NULL; |
|
93
|
3 |
|
if (preg_match('#([^@][a-zA-Z0-9]+)+#', $doc, $m)) { |
|
94
|
3 |
|
$description = trim($m[0]); |
|
95
|
3 |
|
} |
|
96
|
3 |
|
$tasks[$section][lcfirst($match[1])] = $description != '' ? $description : NULL; |
|
97
|
3 |
|
} |
|
98
|
3 |
|
} |
|
99
|
3 |
|
return $tasks; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
|
|
103
|
1 |
|
protected function error($message) |
|
104
|
|
|
{ |
|
105
|
1 |
|
throw new ErrorException($message); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
|
|
109
|
3 |
|
protected function logSection($message) |
|
110
|
|
|
{ |
|
111
|
3 |
|
echo Cli::getColoredString("=> " . $message, 'green') . PHP_EOL; |
|
112
|
3 |
|
} |
|
113
|
|
|
|
|
114
|
|
|
|
|
115
|
7 |
|
protected function log($message) |
|
116
|
|
|
{ |
|
117
|
7 |
|
echo $message . PHP_EOL; |
|
118
|
7 |
|
} |
|
119
|
|
|
|
|
120
|
|
|
} |