Fix bug in requests handling in RequestProcessor

This commit is contained in:
Dmitriy Simushev 2012-09-20 15:07:41 +00:00
parent 4aa44861b4
commit 69e08359c2

View File

@ -126,20 +126,46 @@ abstract class RequestProcessor {
// Clear responses // Clear responses
$this->responses = array(); $this->responses = array();
foreach ($package['requests'] as $request) { foreach ($package['requests'] as $request) {
if ($package['async']) {
// Asynchronous request
// Try to load callback function for this token // Try to load callback function for this token
$callback = $this->loadCallback($request['token']); $callback = $this->loadCallback($request['token']);
$need_result = ! is_null($callback);
$arguments = $this->processRequest($request, $need_result);
if ($need_result) { // Try to get result function
// There is callback function $result_function = $this->mibewAPI->getResultFunction($request['functions']);
// Callback exists but result function does not
if (! is_null($callback) && is_null($result_function)) {
throw new RequestProcessorException(
"There is no 'result' function in request",
RequestProcessorException::NO_RESULT_FUNCTION
);
}
if (! is_null($result_function)) {
if (! is_null($callback)) {
// There are callback function and result function
$arguments = $this->processRequest($request, true);
$function = $callback['function']; $function = $callback['function'];
$arguments += empty($callback['arguments']) $arguments += empty($callback['arguments'])
? array() ? array()
: unserialize($callback['arguments']); : $callback['arguments'];
call_user_func_array($function, $arguments); call_user_func_array($function, $arguments);
}
} else { } else {
// There is no callback function // Process request
$arguments = $this->processRequest($request, false);
// Send response
$this->responses[] = $this->mibewAPI->buildResult(
$request['token'],
$arguments
);
}
} else {
// Synchronous request
// Process request
$arguments = $this->processRequest($request, false);
// Send response
$this->responses[] = $this->mibewAPI->buildResult( $this->responses[] = $this->mibewAPI->buildResult(
$request['token'], $request['token'],
$arguments $arguments