3 * Moodle - Modular Object-Oriented Dynamic Learning Environment
5 * Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * @author Penny Leach <penny@liip.ch>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL
23 * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
25 * Introspection for amf - figures out where all the services are and
26 * returns a list of their available methods.
27 * Requires $CFG->amf_introspection = true for security.
32 * Provides a function to get details of methods available on another class.
36 class MethodDescriptor
{
41 static public $classnametointrospect;
44 public function __construct() {
48 private function setup() {
50 if (!empty($this->nothing
)) {
51 return; // we've already tried, no classes.
53 if (!empty($this->classes
)) { // we've already done it successfully.
56 /*if (empty($CFG->amf_introspection)) {
57 throw new Exception(get_string('amfintrospectiondisabled', 'local'));
60 //just one class here, possibility for expansion in future
61 $classes = array(MethodDescriptor
::$classnametointrospect);
63 $hugestructure = array();
65 foreach ($classes as $c) {
66 $r = new ReflectionClass($c);
68 if (!$methods = $r->getMethods()) {
71 $this->classes
[] = $c;
72 $hugestructure[$c] = array('docs' => $r->getDocComment(), 'methods' => array());
73 foreach ($methods as $method) {
74 if (!$method->isPublic()) {
78 foreach ($method->getParameters() as $param) {
79 $params[] = array('name' => $param->getName(), 'required' => !$param->isOptional());
81 $hugestructure[$c]['methods'][$method->getName()] = array(
82 'docs' => $method->getDocComment(),
87 $this->methods
= $hugestructure;
88 if (empty($this->classes
)) {
89 $this->nothing
= true;
93 public function getMethods() {
95 return $this->methods
;
98 public function getClasses() {
100 return $this->classes
;
103 public function isConnected() {