|
1
|
|
|
<?php |
|
2
|
|
|
/* (c) Anton Medvedev <[email protected]> |
|
3
|
|
|
* |
|
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
5
|
|
|
* file that was distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Deployer\Documentation; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class DocRecipe |
|
13
|
|
|
{ |
|
14
|
|
|
public $recipeName; |
|
15
|
|
|
public $recipePath; |
|
16
|
|
|
public $comment; |
|
17
|
|
|
/** |
|
18
|
|
|
* @var string[] |
|
19
|
|
|
*/ |
|
20
|
|
|
public $require = []; |
|
21
|
|
|
/** |
|
22
|
|
|
* @var DocConfig[] |
|
23
|
|
|
*/ |
|
24
|
|
|
public $config = []; |
|
25
|
|
|
/** |
|
26
|
|
|
* @var DocTask[] |
|
27
|
|
|
*/ |
|
28
|
|
|
public $tasks = []; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct($recipeName, $recipePath) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->recipeName = $recipeName; |
|
33
|
|
|
$this->recipePath = $recipePath; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function parse($content) |
|
37
|
|
|
{ |
|
38
|
|
|
$comment = ''; |
|
39
|
|
|
$first = true; |
|
40
|
|
|
$desc = ''; |
|
41
|
|
|
$currentTask = null; |
|
42
|
|
|
|
|
43
|
|
|
$state = 'root'; |
|
44
|
|
|
foreach (explode("\n", $content) as $i => $line) { |
|
45
|
|
|
$m = []; |
|
46
|
|
|
$match = function ($regexp) use ($line, &$m) { |
|
47
|
|
|
return preg_match("#$regexp#", $line, $m); |
|
48
|
|
|
}; |
|
49
|
|
|
switch ($state) { |
|
50
|
|
|
case 'root': |
|
51
|
|
|
if ($match('^/\*\*?')) { |
|
52
|
|
|
$state = 'comment'; |
|
53
|
|
|
$comment .= trimComment($line) . "\n"; |
|
54
|
|
|
break; |
|
55
|
|
|
} |
|
56
|
|
|
if ($match('^//')) { |
|
57
|
|
|
$comment .= trimComment($line) . "\n"; |
|
58
|
|
|
break; |
|
59
|
|
|
} |
|
60
|
|
|
if ($match('^require.+?[\'"](?<recipe>.+?)[\'"]')) { |
|
61
|
|
|
$this->require[] = dirname($this->recipePath) . $m['recipe']; |
|
62
|
|
|
break; |
|
63
|
|
|
} |
|
64
|
|
|
if ($match('^set\([\'"](?<config_name>[\w_:]+?)[\'"]')) { |
|
65
|
|
|
$set = new DocConfig(); |
|
66
|
|
|
$set->name = $m['config_name']; |
|
67
|
|
|
$set->comment = trim($comment); |
|
68
|
|
|
$comment = ''; |
|
69
|
|
|
$set->recipePath = $this->recipePath; |
|
70
|
|
|
$set->lineNumber = $i + 1; |
|
71
|
|
|
$this->config[$set->name] = $set; |
|
72
|
|
|
break; |
|
73
|
|
|
} |
|
74
|
|
|
if ($match('^desc\([\'"](?<desc>.+?)[\'"]\);$')) { |
|
75
|
|
|
$desc = $m['desc']; |
|
76
|
|
|
break; |
|
77
|
|
|
} |
|
78
|
|
|
if ($match('^task\([\'"](?<task_name>[\w_:]+?)[\'"],\s\[$')) { |
|
79
|
|
|
$task = new DocTask(); |
|
80
|
|
|
$task->name = $m['task_name']; |
|
81
|
|
|
$task->desc = $desc; |
|
82
|
|
|
$task->comment = trim($comment); |
|
83
|
|
|
$comment = ''; |
|
84
|
|
|
$task->group = []; |
|
85
|
|
|
$task->recipePath = $this->recipePath; |
|
86
|
|
|
$task->lineNumber = $i + 1; |
|
87
|
|
|
$this->tasks[$task->name] = $task; |
|
88
|
|
|
$state = 'group_task'; |
|
89
|
|
|
$currentTask = $task; |
|
90
|
|
|
break; |
|
91
|
|
|
} |
|
92
|
|
|
if ($match('^task\([\'"](?<task_name>[\w_:]+?)[\'"]')) { |
|
93
|
|
|
$task = new DocTask(); |
|
94
|
|
|
$task->name = $m['task_name']; |
|
95
|
|
|
$task->desc = $desc; |
|
96
|
|
|
$task->comment = trim($comment); |
|
97
|
|
|
$comment = ''; |
|
98
|
|
|
$task->recipePath = $this->recipePath; |
|
99
|
|
|
$task->lineNumber = $i + 1; |
|
100
|
|
|
$this->tasks[$task->name] = $task; |
|
101
|
|
|
break; |
|
102
|
|
|
} |
|
103
|
|
|
if ($match('^<\?php')) { |
|
104
|
|
|
break; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
$desc = ''; |
|
108
|
|
|
if($first && $comment !== '') { |
|
109
|
|
|
$this->comment = $comment; |
|
110
|
|
|
} |
|
111
|
|
|
$first = false; |
|
112
|
|
|
$comment = ''; |
|
113
|
|
|
break; |
|
114
|
|
|
|
|
115
|
|
|
case 'comment': |
|
116
|
|
|
if ($match('\*/\s*$')) { |
|
117
|
|
|
$state = 'root'; |
|
118
|
|
|
break; |
|
119
|
|
|
} |
|
120
|
|
|
$comment .= trimComment($line) . "\n"; |
|
121
|
|
|
break; |
|
122
|
|
|
|
|
123
|
|
|
case 'group_task': |
|
124
|
|
|
if ($match('^\s+\'(?<task_name>[\w_:]+?)\',$')) { |
|
125
|
|
|
$currentTask->group[] = $m['task_name']; |
|
126
|
|
|
break; |
|
127
|
|
|
} |
|
128
|
|
|
$state = 'root'; |
|
129
|
|
|
break; |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|