Added error handling to the RequestProcessor class

This commit is contained in:
Dmitriy Simushev 2012-09-04 14:23:28 +00:00
parent fd108b1334
commit e5ed85ed3f

View File

@ -65,9 +65,8 @@ abstract class RequestProcessor {
* - 'trusted_signatures': array of trusted signatures. Uses for identify another * - 'trusted_signatures': array of trusted signatures. Uses for identify another
* side of interaction. * side of interaction.
* And may contains following (if not default values will be used) * And may contains following (if not default values will be used)
* - 'event_prefixport': prefix that uses for all registered by the class events. The default value is the class * - 'event_prefix': prefix that uses for all registered by the class events. The default value is the class
* name with first character in lower case * name with first character in lower case
* @todo think about errors' level
*/ */
public function __construct($config) { public function __construct($config) {
// Check signature // Check signature
@ -334,7 +333,10 @@ abstract class RequestProcessor {
if (is_null($result_function)) { if (is_null($result_function)) {
// Execute functions // Execute functions
foreach ($request['functions'] as $function) { foreach ($request['functions'] as $function) {
$this->processFunction($function, $context); if (! $this->processFunction($function, $context)) {
// Stop if errorCode is set and not equals to 0
break;
}
} }
return $context->getResults(); return $context->getResults();
} else { } else {
@ -347,8 +349,8 @@ abstract class RequestProcessor {
* Process function * Process function
* *
* @param array $function 'Function' array. See Mibew API for details * @param array $function 'Function' array. See Mibew API for details
* @param MibewAPIExecutionContext Execution context * @param MibewAPIExecutionContext &$context Execution context
* @return array Result of function call * @return boolean lase if function returns errorCode and errorCode differs from 0.
*/ */
protected function processFunction($function, MibewAPIExecutionContext &$context) { protected function processFunction($function, MibewAPIExecutionContext &$context) {
// Get function arguments with replaced references // Get function arguments with replaced references
@ -372,6 +374,9 @@ abstract class RequestProcessor {
// Add function results to execution context // Add function results to execution context
$context->storeFunctionResults($function, $results); $context->storeFunctionResults($function, $results);
// Check errorCode
return empty($results['errorCode']);
} }
/** /**