Skip to content

Instantly share code, notes, and snippets.

@kwk
Created July 9, 2012 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwk/3076902 to your computer and use it in GitHub Desktop.
Save kwk/3076902 to your computer and use it in GitHub Desktop.
Base class for RPC modules that provides getMethods() functionality.
<?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