ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
XML_RPC2_Server_Method Class Reference
+ Collaboration diagram for XML_RPC2_Server_Method:

Public Member Functions

 getInternalMethod ()
 internalMethod getter More...
 
 isHidden ()
 hidden getter More...
 
 getName ()
 name getter More...
 
 __construct (ReflectionMethod $method, $defaultPrefix)
 Create a new XML-RPC method by introspecting a PHP method. More...
 
 matchesSignature ($methodName, $callParams)
 Check if method matches provided call signature. More...
 
 getHTMLSignature ()
 Return a HTML signature of the method. More...
 
 autoDocument ()
 Print a complete HTML description of the method. More...
 

Static Private Member Functions

static _limitPHPType ($type)
 

Private Attributes

 $_parameters
 
 $_returns
 
 $_help
 
 $_internalMethod
 
 $_hidden
 
 $_name
 
 $_numberOfRequiredParameters
 

Detailed Description

Definition at line 59 of file Method.php.

Constructor & Destructor Documentation

◆ __construct()

XML_RPC2_Server_Method::__construct ( ReflectionMethod  $method,
  $defaultPrefix 
)

Create a new XML-RPC method by introspecting a PHP method.

Parameters
ReflectionMethodThe PHP method to introspect
stringdefault prefix

Definition at line 160 of file Method.php.

References _limitPHPType().

161  {
162  $hidden = false;
163  $docs = $method->getDocComment();
164  if (!$docs) {
165  $hidden = true;
166  }
167  $docs = explode("\n", $docs);
168 
169  $parameters = array();
170  $methodname = null;
171  $returns = 'mixed';
172  $shortdesc = '';
173  $paramcount = -1;
174  $prefix = $defaultPrefix;
175 
176  // Extract info from Docblock
177  $paramDocs = array();
178  foreach ($docs as $i => $doc) {
179  $doc = trim($doc, " \r\t/*");
180  if (strlen($doc) && strpos($doc, '@') !== 0) {
181  if ($shortdesc) {
182  $shortdesc .= "\n";
183  }
184  $shortdesc .= $doc;
185  continue;
186  }
187  if (strpos($doc, '@xmlrpc.hidden') === 0) {
188  $hidden = true;
189  }
190  if ((strpos($doc, '@xmlrpc.prefix') === 0) && preg_match('/@xmlrpc.prefix( )*(.*)/', $doc, $matches)) {
191  $prefix = $matches[2];
192  }
193  if ((strpos($doc, '@xmlrpc.methodname') === 0) && preg_match('/@xmlrpc.methodname( )*(.*)/', $doc, $matches)) {
194  $methodname = $matches[2];
195  }
196  if (strpos($doc, '@param') === 0) { // Save doctag for usage later when filling parameters
197  $paramDocs[] = $doc;
198  }
199 
200  if (strpos($doc, '@return') === 0) {
201  $param = preg_split("/\s+/", $doc);
202  if (isset($param[1])) {
203  $param = $param[1];
204  $returns = $param;
205  }
206  }
207  }
208  $this->_numberOfRequiredParameters = $method->getNumberOfRequiredParameters(); // we don't use isOptional() because of bugs in the reflection API
209  // Fill in info for each method parameter
210  foreach ($method->getParameters() as $parameterIndex => $parameter) {
211  // Parameter defaults
212  $newParameter = array('type' => 'mixed');
213 
214  // Attempt to extract type and doc from docblock
215  if (array_key_exists($parameterIndex, $paramDocs) &&
216  preg_match('/@param\s+(\S+)(\s+(.+))/', $paramDocs[$parameterIndex], $matches)) {
217  if (strpos($matches[1], '|')) {
218  $newParameter['type'] = XML_RPC2_Server_Method::_limitPHPType(explode('|', $matches[1]));
219  } else {
220  $newParameter['type'] = XML_RPC2_Server_Method::_limitPHPType($matches[1]);
221  }
222  $tmp = '$' . $parameter->getName() . ' ';
223  if (strpos($matches[2], '$' . $tmp) === 0) {
224  $newParameter['doc'] = $matches[2];
225  } else {
226  // The phpdoc comment is something like "@param string $param description of param"
227  // Let's keep only "description of param" as documentation (remove $param)
228  $newParameter['doc'] = substr($matches[2], strlen($tmp));
229  }
230  }
231 
232  $parameters[$parameter->getName()] = $newParameter;
233  }
234 
235  if (is_null($methodname)) {
236  $methodname = $prefix . $method->getName();
237  }
238 
239  $this->_internalMethod = $method->getName();
240  $this->_parameters = $parameters;
241  $this->_returns = $returns;
242  $this->_help = $shortdesc;
243  $this->_name = $methodname;
244  $this->_hidden = $hidden;
245  }
static _limitPHPType($type)
Definition: Method.php:358
+ Here is the call graph for this function:

Member Function Documentation

◆ _limitPHPType()

static XML_RPC2_Server_Method::_limitPHPType (   $type)
staticprivate

Definition at line 358 of file Method.php.

Referenced by __construct(), and matchesSignature().

359  {
360  $tmp = strtolower($type);
361  $convertArray = array(
362  'int' => 'integer',
363  'i4' => 'integer',
364  'integer' => 'integer',
365  'string' => 'string',
366  'str' => 'string',
367  'char' => 'string',
368  'bool' => 'boolean',
369  'boolean' => 'boolean',
370  'array' => 'array',
371  'float' => 'double',
372  'double' => 'double',
373  'array' => 'array',
374  'struct' => 'array',
375  'assoc' => 'array',
376  'structure' => 'array',
377  'datetime' => 'mixed',
378  'datetime.iso8601' => 'mixed',
379  'iso8601' => 'mixed',
380  'base64' => 'string'
381  );
382  if (isset($convertArray[$tmp])) {
383  return $convertArray[$tmp];
384  }
385  return 'mixed';
386  }
+ Here is the caller graph for this function:

◆ autoDocument()

XML_RPC2_Server_Method::autoDocument ( )

Print a complete HTML description of the method.

Definition at line 323 of file Method.php.

References getHTMLSignature(), and getName().

324  {
325  $name = $this->getName();
326  $signature = $this->getHTMLSignature();
327  $id = md5($name);
328  $help = nl2br(htmlentities($this->_help));
329  print " <h3><a name=\"$id\">$signature</a></h3>\n";
330  print " <p><b>Description :</b></p>\n";
331  print " <div class=\"description\">\n";
332  print " $help\n";
333  print " </div>\n";
334  if (count($this->_parameters)>0) {
335  print " <p><b>Parameters : </b></p>\n";
336  if (count($this->_parameters)>0) {
337  print " <table>\n";
338  print " <tr><td><b>Type</b></td><td><b>Name</b></td><td><b>Documentation</b></td></tr>\n";
339  while (list($name, $parameter) = each($this->_parameters)) {
340  $type = $parameter['type'];
341  $doc = htmlentities($parameter['doc']);
342  print " <tr><td>$type</td><td>$name</td><td>$doc</td></tr>\n";
343  }
344  reset($this->_parameters);
345  print " </table>\n";
346  }
347  }
348  }
getHTMLSignature()
Return a HTML signature of the method.
Definition: Method.php:287
getName()
name getter
Definition: Method.php:146
+ Here is the call graph for this function:

◆ getHTMLSignature()

XML_RPC2_Server_Method::getHTMLSignature ( )

Return a HTML signature of the method.

Returns
string HTML signature

Definition at line 287 of file Method.php.

References $_name, $_returns, and $result.

Referenced by autoDocument().

288  {
289  $name = $this->_name;
290  $returnType = $this->_returns;
291  $result = "<span class=\"type\">($returnType)</span> ";
292  $result .= "<span class=\"name\">$name</span>";
293  $result .= "<span class=\"other\">(</span>";
294  $first = true;
295  $nbr = 0;
296  while (list($name, $parameter) = each($this->_parameters)) {
297  $nbr++;
298  if ($nbr == $this->_numberOfRequiredParameters + 1) {
299  $result .= "<span class=\"other\"> [ </span>";
300  }
301  if ($first) {
302  $first = false;
303  } else {
304  $result .= ', ';
305  }
306  $type = $parameter['type'];
307  $result .= "<span class=\"paratype\">($type) </span>";
308  $result .= "<span class=\"paraname\">$name</span>";
309  }
310  reset($this->_parameters);
311  if ($nbr > $this->_numberOfRequiredParameters) {
312  $result .= "<span class=\"other\"> ] </span>";
313  }
314  $result .= "<span class=\"other\">)</span>";
315  return $result;
316  }
$result
+ Here is the caller graph for this function:

◆ getInternalMethod()

XML_RPC2_Server_Method::getInternalMethod ( )

internalMethod getter

Returns
string internalMethod

Definition at line 120 of file Method.php.

References $_internalMethod.

121  {
122  return $this->_internalMethod;
123  }

◆ getName()

XML_RPC2_Server_Method::getName ( )

name getter

Returns
string name

Definition at line 146 of file Method.php.

References $_name.

Referenced by XML_RPC2_Server_CallHandler\addMethod(), and autoDocument().

147  {
148  return $this->_name;
149  }
+ Here is the caller graph for this function:

◆ isHidden()

XML_RPC2_Server_Method::isHidden ( )

hidden getter

Returns
boolean hidden value

Definition at line 133 of file Method.php.

References $_hidden.

134  {
135  return $this->_hidden;
136  }

◆ matchesSignature()

XML_RPC2_Server_Method::matchesSignature (   $methodName,
  $callParams 
)

Check if method matches provided call signature.

Compare the provided call signature with this methods' signature and return true iff they match.

Parameters
stringSignature to compare method name
arrayArray of parameter values for method call.
Returns
boolean True if call matches signature, false otherwise

Definition at line 260 of file Method.php.

References _limitPHPType().

261  {
262  if ($methodName != $this->_name) return false;
263  if (count($callParams) < $this->_numberOfRequiredParameters) return false;
264  if (count($callParams) > $this->_parameters) return false;
265  $paramIndex = 0;
266  foreach($this->_parameters as $param) {
267  $paramIndex++;
268  if ($paramIndex <= $this->_numberOfRequiredParameters) {
269  // the parameter is not optional
270  $callParamType = XML_RPC2_Server_Method::_limitPHPType(gettype($callParams[$paramIndex-1]));
271  if ((!($param['type'] == 'mixed')) and ($param['type'] != $callParamType)) {
272  return false;
273  }
274  }
275  }
276  return true;
277  }
static _limitPHPType($type)
Definition: Method.php:358
+ Here is the call graph for this function:

Field Documentation

◆ $_help

XML_RPC2_Server_Method::$_help
private

Definition at line 82 of file Method.php.

◆ $_hidden

XML_RPC2_Server_Method::$_hidden
private

Definition at line 96 of file Method.php.

Referenced by isHidden().

◆ $_internalMethod

XML_RPC2_Server_Method::$_internalMethod
private

Definition at line 89 of file Method.php.

Referenced by getInternalMethod().

◆ $_name

XML_RPC2_Server_Method::$_name
private

Definition at line 103 of file Method.php.

Referenced by getHTMLSignature(), and getName().

◆ $_numberOfRequiredParameters

XML_RPC2_Server_Method::$_numberOfRequiredParameters
private

Definition at line 110 of file Method.php.

◆ $_parameters

XML_RPC2_Server_Method::$_parameters
private

Definition at line 68 of file Method.php.

◆ $_returns

XML_RPC2_Server_Method::$_returns
private

Definition at line 75 of file Method.php.

Referenced by getHTMLSignature().


The documentation for this class was generated from the following file: