Bob\Task::invoke PHP Method

invoke() public method

# Returns the callback's return value.
public invoke ( )
    function invoke()
    {
        if (!$this->enable) {
            if ($this->application->trace) {
                $this->application['log']->debug("{$this->inspect()} is not enabled");
            }
            return;
        }
        if (!$this->reenable and $this->application['invocation_chain']->has($this)) {
            return;
        }
        if (!$this->application->forceRun and !$this->isNeeded()) {
            $this->application->trace and $this->application['log']->debug("Skipping {$this->inspect()}");
            return;
        }
        $this->application['invocation_chain']->push($this);
        if ($this->application->trace) {
            $this->application['log']->debug("Invoke {$this->inspect()}");
        }
        $app = $this->application;
        itertools\walk(itertools\filter(itertools\to_iterator($this->prerequisites), function ($p) use($app) {
            return $app->taskDefined((string) $p);
        }), function ($p) use($app) {
            $app['tasks'][(string) $p]->invoke();
        });
        if ($this->prerequisites !== null) {
            $this->prerequisites->rewind();
        }
        $this->execute();
        $this->reenable = false;
    }

Usage Example

Example #1
0
File: TaskTest.php Project: chh/bob
 function testInvokeRunsActionsOnlyOnce()
 {
     $invoked = 0;
     $t = new Task('foo', new Application());
     $t->actions[] = function () use(&$invoked) {
         $invoked++;
     };
     $t->invoke();
     $t->invoke();
     $this->assertEquals(1, $invoked);
     $t->reenable();
     $t->invoke();
     $this->assertEquals(2, $invoked);
 }