-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathfunctions.php
70 lines (63 loc) · 1.46 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
function builder() {
if (!isset(phake\Builder::$global)) {
phake\Builder::$global = new phake\Builder;
}
return phake\Builder::$global;
}
function task() {
$deps = func_get_args();
$name = array_shift($deps);
if ($deps[count($deps) - 1] instanceof Closure) {
$work = array_pop($deps);
} else {
$work = null;
}
builder()->add_task($name, $work, $deps);
}
function group($name, $lambda = null) {
$thrown = null;
builder()->push_group($name);
try {
if ($lambda instanceof Closure) $lambda();
} catch (\Exception $e) {
$thrown = $e;
}
builder()->pop_group();
if ($thrown) {
throw $e;
}
}
function before($task, $lambda) {
builder()->before($task, $lambda);
}
function after($task, $lambda) {
builder()->after($task, $lambda);
}
function desc($description) {
builder()->desc($description);
}
/**
* Writes arguments to stdout, each separated by a space
* @param string $str...
*/
function write() {
$out = '';
$was_newline = true;
foreach (func_get_args() as $ix => $str) {
if (!$was_newline) {
$out .= ' ';
}
$out .= $str;
$was_newline = $str[strlen($str)-1] == "\n";
}
echo $out;
}
/**
* Writes arguments to stdout, each separated by a space, then starts a new line
* @param string $str...
*/
function writeln() {
call_user_func_array('write', func_get_args());
echo "\n";
}