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) {
// Try to load callback function for this token if ($package['async']) {
$callback = $this->loadCallback($request['token']); // Asynchronous request
$need_result = ! is_null($callback); // Try to load callback function for this token
$arguments = $this->processRequest($request, $need_result); $callback = $this->loadCallback($request['token']);
if ($need_result) { // Try to get result function
// There is callback function $result_function = $this->mibewAPI->getResultFunction($request['functions']);
$function = $callback['function'];
$arguments += empty($callback['arguments']) // Callback exists but result function does not
? array() if (! is_null($callback) && is_null($result_function)) {
: unserialize($callback['arguments']); throw new RequestProcessorException(
call_user_func_array($function, $arguments); "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'];
$arguments += empty($callback['arguments'])
? array()
: $callback['arguments'];
call_user_func_array($function, $arguments);
}
} else {
// Process request
$arguments = $this->processRequest($request, false);
// Send response
$this->responses[] = $this->mibewAPI->buildResult(
$request['token'],
$arguments
);
}
} else { } else {
// There is no callback function // 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