. * * @package moodle * @author Penny Leach * @license http://www.gnu.org/copyleft/gpl.html GNU GPL * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com * * Introspection for amf - figures out where all the services are and * returns a list of their available methods. * Requires $CFG->amf_introspection = true for security. */ /** * Provides a function to get details of methods available on another class. * @author HP * */ class MethodDescriptor { private $methods; private $classes; static public $classnametointrospect; public function __construct() { $this->setup(); } private function setup() { global $CFG; if (!empty($this->nothing)) { return; // we've already tried, no classes. } if (!empty($this->classes)) { // we've already done it successfully. return; } /*if (empty($CFG->amf_introspection)) { throw new Exception(get_string('amfintrospectiondisabled', 'local')); }*/ //just one class here, possibility for expansion in future $classes = array(MethodDescriptor::$classnametointrospect); $hugestructure = array(); foreach ($classes as $c) { $r = new ReflectionClass($c); if (!$methods = $r->getMethods()) { continue; } $this->classes[] = $c; $hugestructure[$c] = array('docs' => $r->getDocComment(), 'methods' => array()); foreach ($methods as $method) { if (!$method->isPublic()) { continue; } $params = array(); foreach ($method->getParameters() as $param) { $params[] = array('name' => $param->getName(), 'required' => !$param->isOptional()); } $hugestructure[$c]['methods'][$method->getName()] = array( 'docs' => $method->getDocComment(), 'params' => $params, ); } } $this->methods = $hugestructure; if (empty($this->classes)) { $this->nothing = true; } } public function getMethods() { $this->setup(); return $this->methods; } public function getClasses() { $this->setup(); return $this->classes; } public function isConnected() { return true; } }