mirror of
				https://github.com/Mibew/java.git
				synced 2025-10-31 18:41:09 +03:00 
			
		
		
		
	Move processorCall method to RequestProcessor class
This commit is contained in:
		
							parent
							
								
									95bc033817
								
							
						
					
					
						commit
						a650a35dd6
					
				| @ -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 '<eventPrefix>FunctionCall' event triggers. | ||||
| 	 * | ||||
| 	 * @param array &$func Function array equals to array, passed to the '<eventPrefix>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 '<eventPrefix>FunctionCall' event triggers. | ||||
| 	 * | ||||
| 	 * @param array &$func Function array equals to array, passed to the '<eventPrefix>FunctionCall' event. | ||||
| 	 * @see RequestProcessor::registerEvents() | ||||
| 	 */ | ||||
| 	protected abstract function processorCall(&$func); | ||||
| } | ||||
| 
 | ||||
| class RequestProcessorException extends Exception { | ||||
|  | ||||
| @ -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 '<eventPrefix>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
 | ||||
| 	 */ | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user