Skip to content

Commit

Permalink
Merge branch 'mihu-nested'
Browse files Browse the repository at this point in the history
  • Loading branch information
jaz303 committed Oct 7, 2014
2 parents c54864a + 4c6df35 commit 432e11a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/functions.php
Expand Up @@ -19,13 +19,13 @@ function task() {

function group($name, $lambda = null) {
$thrown = null;
builder()->push_group($name);
$levels = builder()->push_group($name);
try {
if ($lambda instanceof Closure) $lambda();
} catch (\Exception $e) {
$thrown = $e;
}
builder()->pop_group();
builder()->pop_group($levels);
if ($thrown) {
throw $e;
}
Expand Down
10 changes: 7 additions & 3 deletions lib/phake/Builder.php
Expand Up @@ -53,11 +53,15 @@ public function add_task($name, $work, $deps) {
}

public function push_group($name) {
$this->target_node = $this->target_node->child_with_name($name);
$levels = 0;
$this->target_node = $this->target_node->child_with_name($name, $levels);
return $levels;
}

public function pop_group() {
$this->target_node = $this->target_node->get_parent();
public function pop_group($levels = 1) {
for ($i = 0; $i < $levels; $i++) {
$this->target_node = $this->target_node->get_parent();
}
}

public function before($name, $lambda) {
Expand Down
6 changes: 4 additions & 2 deletions lib/phake/Node.php
Expand Up @@ -49,7 +49,7 @@ public function get_root() {
return $root;
}

public function child_with_name($task_name) {
public function child_with_name($task_name, &$levels = 0) {
$parts = explode(':', $task_name);

$task = $this;
Expand All @@ -60,6 +60,8 @@ public function child_with_name($task_name) {
$task = $task->children[$part];
}

$levels = sizeof($parts);

return $task;
}

Expand Down Expand Up @@ -132,7 +134,7 @@ public function has_body() {

public function get_task($task_name) {
if ($task_name[0] != ':') {

$parts = explode(':', $task_name);

$task = $this;
Expand Down
1 change: 1 addition & 0 deletions tests/BuilderTest.php
Expand Up @@ -76,6 +76,7 @@ public function testGroups()
$this->expectOutputString(<<<EOF
a:b
b:a
y:z:a
EOF
);
Expand Down
6 changes: 5 additions & 1 deletion tests/fixtures/groups.php
@@ -1,9 +1,13 @@
<?php

group('y:z', function() {
task('a', function () { echo "y:z:a\n"; });
});

task('a:b', function () { echo "a:b\n"; });

group('b', function () {
task('a', function () { echo "b:a\n"; });
});

task('default', 'a:b', 'b:a');
task('default', 'a:b', 'b:a', 'y:z:a');

0 comments on commit 432e11a

Please sign in to comment.