ezcWorkflowExecution::execute PHP Method

execute() protected method

The workflow engine's main execution loop. It is started by start() and resume().
protected execute ( )
    protected function execute()
    {
        // Try to execute nodes while there are executable nodes on the stack.
        do {
            // Flag that indicates whether a node has been executed during the
            // current iteration of the loop.
            $executed = false;
            // Iterate the stack of activated nodes.
            foreach ($this->activatedNodes as $key => $node) {
                // Only try to execute a node if the execution of the
                // workflow instance has not ended yet.
                if ($this->cancelled && $this->ended) {
                    // @codeCoverageIgnoreStart
                    break;
                    // @codeCoverageIgnoreEnd
                }
                // The current node is an end node but there are still
                // activated nodes on the stack.
                if ($node instanceof ezcWorkflowNodeEnd && !$node instanceof ezcWorkflowNodeCancel && $this->numActivatedNodes != $this->numActivatedEndNodes) {
                    continue;
                }
                // Execute the current node and check whether it finished
                // executing.
                if ($node->execute($this)) {
                    // Remove current node from the stack of activated
                    // nodes.
                    unset($this->activatedNodes[$key]);
                    $this->numActivatedNodes--;
                    // Notify plugins that the node has been executed.
                    if (!$this->cancelled && !$this->ended) {
                        foreach ($this->plugins as $plugin) {
                            $plugin->afterNodeExecuted($this, $node);
                        }
                    }
                    // Toggle flag (see above).
                    $executed = true;
                }
            }
        } while (!empty($this->activatedNodes) && $executed);
        // The stack of activated nodes is not empty but at the moment none of
        // its nodes can be executed.
        if (!$this->cancelled && !$this->ended) {
            $this->suspend();
        }
    }