phake\Node::get_task PHP Метод

get_task() публичный Метод

public get_task ( $task_name )
    public function get_task($task_name)
    {
        if ($task_name[0] != ':') {
            $parts = explode(':', $task_name);
            $task = $this;
            foreach ($parts as $part) {
                if (isset($task->children[$part])) {
                    $task = $task->children[$part];
                } else {
                    $task = null;
                    break;
                }
            }
            if ($task !== null) {
                return $task;
            } else {
                if ($this->parent) {
                    return $this->parent->get_task($task_name);
                } else {
                    throw new TaskNotFoundException($task_name);
                }
            }
        } else {
            return $this->get_root()->get_task(substr($task_name, 1));
        }
    }

Usage Example

Пример #1
0
 public function testGroupedNodes()
 {
     $root = new Node();
     $ab = $root->child_with_name('a:b');
     $this->assertSame($ab, $root->get_task('a:b'));
     $a = $ab->get_parent();
     $this->assertSame($a, $root->get_task('a'));
     $this->assertEquals(array('a:b' => $ab), $a->get_tasks());
     $this->assertSame($root, $a->get_parent());
     $this->assertSame($root, $ab->get_root());
     $this->assertEquals(array('a' => $a, 'a:b' => $ab), $root->get_tasks());
 }