diff --git a/src/mg/PAGI/Node/MockedNode.php b/src/mg/PAGI/Node/MockedNode.php index 82cf298..57b2771 100644 --- a/src/mg/PAGI/Node/MockedNode.php +++ b/src/mg/PAGI/Node/MockedNode.php @@ -299,6 +299,7 @@ protected function callClientMethods($methods, $stopWhen = null) { $client = $this->getClient(); $logger = $client->getLogger(); + $result = null; foreach ($methods as $callInfo) { foreach ($callInfo as $name => $arguments) { switch($name) @@ -324,23 +325,47 @@ protected function callClientMethods($methods, $stopWhen = null) default: break; } + $result = parent::callClientMethod($name, $arguments); + if ($stopWhen !== null) { + if ($stopWhen($result)) { + return $result; + } + } } } - return parent::callClientMethods($methods, $stopWhen); + return $result; } + /** + * Execute a callback before invoking the real callback for valid input. + * + * @param \Closure $callback + * + * @return \PAGI\Node\MockedNode + */ public function doBeforeValidInput(\Closure $callback) { $this->validInputCallback = $callback; return $this; } + /** + * Execute a callback before invoking the real callback for failed input. + * + * @param \Closure $callback + * + * @return \PAGI\Node\MockedNode + */ public function doBeforeFailedInput(\Closure $callback) { $this->failedInputCallback = $callback; return $this; } + /** + * (non-PHPdoc) + * @see PAGI\Node.Node::beforeOnValidInput() + */ protected function beforeOnValidInput() { if ($this->validInputCallback !== null) { @@ -349,6 +374,10 @@ protected function beforeOnValidInput() } } + /** + * (non-PHPdoc) + * @see PAGI\Node.Node::beforeOnInputFailed() + */ protected function beforeOnInputFailed() { if ($this->failedInputCallback !== null) { diff --git a/src/mg/PAGI/Node/Node.php b/src/mg/PAGI/Node/Node.php index 52969a3..a0d9ca5 100644 --- a/src/mg/PAGI/Node/Node.php +++ b/src/mg/PAGI/Node/Node.php @@ -872,6 +872,20 @@ public function isComplete() return $this->state == self::STATE_COMPLETE; } + /** + * Call a specific method on a client. + * + * @param string $name + * @param string[] $arguments + * + * @return IResult + */ + protected function callClientMethod($name, array $arguments = array()) + { + $this->logDebug("$name(" . implode(",", $arguments) . ")"); + return call_user_func_array(array($this->_client, $name), $arguments); + } + /** * Calls methods in the PAGI client. * @@ -888,10 +902,7 @@ protected function callClientMethods($methods, $stopWhen = null) $result = null; foreach ($methods as $callInfo) { foreach ($callInfo as $name => $arguments) { - $this->logDebug("$name(" . implode(",", $arguments) . ")"); - $result = call_user_func_array( - array($this->_client, $name), $arguments - ); + $result = $this->callClientMethod($name, $arguments); if ($stopWhen !== null) { if ($stopWhen($result)) { return $result;