PAGI\Node\Node::run PHP Method

run() public method

Executes this node.
public run ( ) : Node
return Node
    public function run()
    {
        $this->inputAttemptsUsed = 0;
        if ($this->executeBeforeRun !== null) {
            $callback = $this->executeBeforeRun;
            $callback($this);
        }
        for ($attempts = 0; $attempts < $this->totalAttemptsForInput; $attempts++) {
            $this->doInput();
            if ($this->wasCancelled()) {
                if ($this->cancelWithInputRetriesInput && $this->hasInput()) {
                    $this->logDebug("Cancelled input, retrying");
                    continue;
                }
                $this->logDebug("Cancelled node, quitting");
                break;
            }
            // dont play on last attempt by default
            if ($this->onNoInputMessage !== null && !$this->hasInput() && ($this->playOnNoInputInLastAttempt || $attempts != $this->totalAttemptsForInput - 1)) {
                $this->addPrePromptMessage($this->onNoInputMessage);
                continue;
            }
            if ($this->hasInput()) {
                if ($this->validate()) {
                    $this->logDebug("Input validated");
                    if ($this->executeOnValidInput !== null) {
                        $callback = $this->executeOnValidInput;
                        $this->beforeOnValidInput();
                        $callback($this);
                    }
                    break;
                } elseif ($this->executeAfterFailedValidation !== null) {
                    $callback = $this->executeAfterFailedValidation;
                    $callback($this);
                }
            }
        }
        $result = $this->playPrePromptMessages();
        if ($this->minInput > 0 && $attempts == $this->totalAttemptsForInput) {
            $this->logDebug("Max attempts reached");
            $this->state = self::STATE_MAX_INPUTS_REACHED;
            if ($this->onMaxValidInputAttempts !== null) {
                $this->callClientMethods(array(array('streamFile' => array($this->onMaxValidInputAttempts, self::DTMF_ANY))));
            }
        }
        if (!$this->isComplete() && $this->executeOnInputFailed !== null) {
            $callback = $this->executeOnInputFailed;
            $this->beforeOnInputFailed();
            $callback($this);
        }
        if ($this->executeAfterRun !== null) {
            $callback = $this->executeAfterRun;
            $callback($this);
        }
        $this->logDebug($this);
        return $this;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * (non-PHPdoc)
  * @see PAGI\Node.Node::run()
  */
 public function run()
 {
     $result = parent::run();
     foreach ($this->expectedSay as $semiHash => $times) {
         $data = unserialize($semiHash);
         $what = array_shift($data);
         $arguments = array_shift($data);
         $doneTimes = 0;
         if (isset($this->doneSay[$semiHash])) {
             $doneTimes = $this->doneSay[$semiHash];
         }
         if ($times != $doneTimes) {
             throw new MockedException("{$what} (" . implode(",", $arguments) . ") expected to be" . " called {$times} times, was called {$doneTimes} times");
         }
     }
     if ($this->expectedState != Node::STATE_NOT_RUN) {
         if ($this->expectedState != $this->state) {
             throw new MockedException("Expected state: " . parent::stateToString($this->expectedState) . " vs. Current: " . parent::stateToString($this->state));
         }
     }
     return $result;
 }