From a650a35dd6141cded564c28bfe92734137297125 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Tue, 15 Jan 2013 14:01:16 +0000 Subject: [PATCH] Move processorCall method to RequestProcessor class --- .../webim/libs/classes/request_processor.php | 34 ++++++++++++------ .../webim/libs/classes/thread_processor.php | 36 ++++--------------- 2 files changed, 30 insertions(+), 40 deletions(-) diff --git a/src/messenger/webim/libs/classes/request_processor.php b/src/messenger/webim/libs/classes/request_processor.php index f335cc95..b1469bab 100644 --- a/src/messenger/webim/libs/classes/request_processor.php +++ b/src/messenger/webim/libs/classes/request_processor.php @@ -452,6 +452,30 @@ abstract class RequestProcessor { ); } + /** + * Dispatcher of the functions, provided by the RequestProcessor (or inherited) classes as an external API. + * + * All API methods names starts with 'api' prefix. + * It calls before 'FunctionCall' event triggers. + * + * @param array &$func Function array equals to array, passed to the 'FunctionCall' event. + * @see RequestProcessor::registerEvents() + * @todo Create some unit tests + */ + protected function processorCall(&$func) { + $method_name = 'api' . ucfirst($func['function']); + if (is_callable(array($this, $method_name))) { + try { + $func['results'] = $this->$method_name($func['arguments']); + } catch(RequestProcessorException $e) { + $func['results'] = array( + 'errorCode' => $e->getCode(), + 'errorMessage' => $e->getMessage() + ); + } + } + } + /** * Sends synchronous request * @@ -496,16 +520,6 @@ abstract class RequestProcessor { * @return MibewAPI */ protected abstract function getMibewAPIInstance(); - - /** - * Dispatcher of the functions, provided by the RequestProcessor (or inherited) classes as an external API. - * - * It calls before 'FunctionCall' event triggers. - * - * @param array &$func Function array equals to array, passed to the 'FunctionCall' event. - * @see RequestProcessor::registerEvents() - */ - protected abstract function processorCall(&$func); } class RequestProcessorException extends Exception { diff --git a/src/messenger/webim/libs/classes/thread_processor.php b/src/messenger/webim/libs/classes/thread_processor.php index ef61417f..f260abb6 100644 --- a/src/messenger/webim/libs/classes/thread_processor.php +++ b/src/messenger/webim/libs/classes/thread_processor.php @@ -122,30 +122,6 @@ class ThreadProcessor extends RequestProcessor { return MibewAPI::getAPI('MibewAPIChatInteraction'); } - /** - * Dispatcher of the functions, provided by the RequestProcessor (or inherited) classes as an external API. - * - * All API methods names starts with 'api' prefix. - * It calls before 'threadFunctionCall' event triggers. - * - * @param array &$func Function array equals to array, passed to the 'FunctionCall' event. - * @see RequestProcessor::registerEvents() - * @todo Add function to auto create errors to the MibewAPI - */ - protected function processorCall(&$func) { - $method_name = 'api' . ucfirst($func['function']); - if (is_callable(array($this, $method_name))) { - try { - $func['results'] = $this->$method_name($func['arguments']); - } catch(ThreadProcessorException $e) { - $func['results'] = array( - 'errorCode' => $e->getCode(), - 'errorMessage' => $e->getMessage() - ); - } - } - } - /** * Sends asynchronous responses * @@ -153,11 +129,11 @@ class ThreadProcessor extends RequestProcessor { */ protected function sendAsyncResponses($responses) { header("Content-type: text/plain; charset=UTF-8"); - echo($this->mibewAPI->encodePackage( - $responses, - $this->config['signature'], - true - )); + echo($this->mibewAPI->encodePackage( + $responses, + $this->config['signature'], + true + )); } /** @@ -436,7 +412,7 @@ class ThreadProcessor extends RequestProcessor { } } -class ThreadProcessorException extends Exception { +class ThreadProcessorException extends RequestProcessorException { /** * Wrong arguments set for an API function */