Created
July 9, 2012 14:35
-
-
Save kwk/3076902 to your computer and use it in GitHub Desktop.
Base class for RPC modules that provides getMethods() functionality.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This is the base class for all Json RPC Modules. | |
* | |
* @author Konrad Kleine (kwk) | |
*/ | |
abstract class JsonRpcModule { | |
/** | |
* Returns the methods available in the concrete RPC Module implementation. | |
* All final public methods are returned this way: | |
* | |
* \code | |
* array( | |
* "methodName0" => array() | |
* "methodName1" => array("paramName1", "paramName2", ...), | |
* "methodName2" => array("paramName1", ...) | |
* ) | |
* \endcode | |
* | |
* @return array | |
*/ | |
final public function getMethods() { | |
$methods = array(); | |
$className = get_class($this); | |
$reflection = new ReflectionClass($className); | |
$methodObjects = $reflection->getMethods( | |
ReflectionMethod::IS_PUBLIC | |
); | |
foreach ($methodObjects as $methodObj) { | |
$methodName = $methodObj->name; | |
$params = array(); | |
foreach($reflection->getMethod($methodName)->getParameters() as $param) { | |
$params[] = $param->name; | |
} | |
$method = array($methodName => $params); | |
$methods[] = $method; | |
} | |
return $methods; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment