[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 18 /** 19 * Introspection for amf 20 * 21 * Figures out where all the services are and 22 * returns a list of their available methods. 23 * Requires $CFG->amf_introspection = true for security. 24 * 25 * @package webservice_amf 26 * @copyright 2009 Penny Leach <[email protected]> 27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 28 */ 29 30 31 /** 32 * Provides a function to get details of methods available on another class. 33 * 34 * @package webservice_amf 35 * @copyright HP 36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 37 */ 38 class MethodDescriptor { 39 40 /** @var array The details of the methods*/ 41 private $methods; 42 43 /** @var array Classes to introspect 44 * Note: setup() code has been written to introspect multiple classes. 45 * However the setup() only deal with $classnametointrospect. 46 */ 47 private $classes; 48 49 /** @var string Class to introspect */ 50 static public $classnametointrospect; 51 52 /** 53 * constructor 54 */ 55 public function __construct() { 56 $this->setup(); 57 } 58 59 /** 60 * Generate the class method descriptions. 61 * These description are assigned in the class properties 62 * 63 * @return void 64 */ 65 private function setup() { 66 global $CFG; 67 if (!empty($this->nothing)) { 68 return; // we've already tried, no classes. 69 } 70 if (!empty($this->classes)) { // we've already done it successfully. 71 return; 72 } 73 74 //TODO MDL-31148 most likely can be removed, but check if there is any interest, never know... 75 /*if (empty($CFG->amf_introspection)) { 76 throw new Exception(get_string('amfintrospectiondisabled', 'local')); 77 }*/ 78 79 //TODO MDL-31148 just one class here, possibility for expansion in future 80 $classes = array(MethodDescriptor::$classnametointrospect); 81 82 $hugestructure = array(); 83 84 foreach ($classes as $c) { 85 $r = new ReflectionClass($c); 86 87 if (!$methods = $r->getMethods()) { 88 continue; 89 } 90 $this->classes[] = $c; 91 $hugestructure[$c] = array('docs' => $r->getDocComment(), 'methods' => array()); 92 foreach ($methods as $method) { 93 if (!$method->isPublic()) { 94 continue; 95 } 96 $params = array(); 97 foreach ($method->getParameters() as $param) { 98 $params[] = array('name' => $param->getName(), 'required' => !$param->isOptional()); 99 } 100 $hugestructure[$c]['methods'][$method->getName()] = array( 101 'docs' => $method->getDocComment(), 102 'params' => $params, 103 ); 104 } 105 } 106 $this->methods = $hugestructure; 107 if (empty($this->classes)) { 108 $this->nothing = true; 109 } 110 } 111 112 /** 113 * Get the method descriptions 114 * 115 * @return array 116 */ 117 public function getMethods() { 118 $this->setup(); 119 return $this->methods; 120 } 121 122 /** 123 * Get the class descriptions 124 * 125 * @return array 126 */ 127 public function getClasses() { 128 $this->setup(); 129 return $this->classes; 130 } 131 132 /** 133 * As the class does not extend another class and as this function does nothing 134 * except return true, 135 * I guess this is just a function that was a copy/paste and it has been forgotten. 136 * TODO MDL-31148 this function is not called and most likely can be removed 137 * 138 * @return true 139 */ 140 public function isConnected() { 141 return true; 142 } 143 } 144
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |