ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
XML_RPC2_Server_Method Class Reference
+ Collaboration diagram for XML_RPC2_Server_Method:

Public Member Functions

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

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

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 $param, and _limitPHPType().

{
$hidden = false;
$docs = $method->getDocComment();
if (!$docs) {
$hidden = true;
}
$docs = explode("\n", $docs);
$parameters = array();
$methodname = null;
$returns = 'mixed';
$shortdesc = '';
$paramcount = -1;
$prefix = $defaultPrefix;
// Extract info from Docblock
$paramDocs = array();
foreach ($docs as $i => $doc) {
$doc = trim($doc, " \r\t/*");
if (strlen($doc) && strpos($doc, '@') !== 0) {
if ($shortdesc) {
$shortdesc .= "\n";
}
$shortdesc .= $doc;
continue;
}
if (strpos($doc, '@xmlrpc.hidden') === 0) {
$hidden = true;
}
if ((strpos($doc, '@xmlrpc.prefix') === 0) && preg_match('/@xmlrpc.prefix( )*(.*)/', $doc, $matches)) {
$prefix = $matches[2];
}
if ((strpos($doc, '@xmlrpc.methodname') === 0) && preg_match('/@xmlrpc.methodname( )*(.*)/', $doc, $matches)) {
$methodname = $matches[2];
}
if (strpos($doc, '@param') === 0) { // Save doctag for usage later when filling parameters
$paramDocs[] = $doc;
}
if (strpos($doc, '@return') === 0) {
$param = preg_split("/\s+/", $doc);
if (isset($param[1])) {
$param = $param[1];
$returns = $param;
}
}
}
$this->_numberOfRequiredParameters = $method->getNumberOfRequiredParameters(); // we don't use isOptional() because of bugs in the reflection API
// Fill in info for each method parameter
foreach ($method->getParameters() as $parameterIndex => $parameter) {
// Parameter defaults
$newParameter = array('type' => 'mixed');
// Attempt to extract type and doc from docblock
if (array_key_exists($parameterIndex, $paramDocs) &&
preg_match('/@param\s+(\S+)(\s+(.+))/', $paramDocs[$parameterIndex], $matches)) {
if (strpos($matches[1], '|')) {
$newParameter['type'] = XML_RPC2_Server_Method::_limitPHPType(explode('|', $matches[1]));
} else {
$newParameter['type'] = XML_RPC2_Server_Method::_limitPHPType($matches[1]);
}
$tmp = '$' . $parameter->getName() . ' ';
if (strpos($matches[2], '$' . $tmp) === 0) {
$newParameter['doc'] = $matches[2];
} else {
// The phpdoc comment is something like "@param string $param description of param"
// Let's keep only "description of param" as documentation (remove $param)
$newParameter['doc'] = substr($matches[2], strlen($tmp));
}
}
$parameters[$parameter->getName()] = $newParameter;
}
if (is_null($methodname)) {
$methodname = $prefix . $method->getName();
}
$this->_internalMethod = $method->getName();
$this->_parameters = $parameters;
$this->_returns = $returns;
$this->_help = $shortdesc;
$this->_name = $methodname;
$this->_hidden = $hidden;
}

+ Here is the call graph for this function:

Member Function Documentation

static XML_RPC2_Server_Method::_limitPHPType (   $type)
staticprivate

Definition at line 358 of file Method.php.

References $type.

Referenced by __construct(), and matchesSignature().

{
$tmp = strtolower($type);
$convertArray = array(
'int' => 'integer',
'i4' => 'integer',
'integer' => 'integer',
'string' => 'string',
'str' => 'string',
'char' => 'string',
'bool' => 'boolean',
'boolean' => 'boolean',
'array' => 'array',
'float' => 'double',
'double' => 'double',
'array' => 'array',
'struct' => 'array',
'assoc' => 'array',
'structure' => 'array',
'datetime' => 'mixed',
'datetime.iso8601' => 'mixed',
'iso8601' => 'mixed',
'base64' => 'string'
);
if (isset($convertArray[$tmp])) {
return $convertArray[$tmp];
}
return 'mixed';
}

+ Here is the caller graph for this function:

XML_RPC2_Server_Method::autoDocument ( )

Print a complete HTML description of the method.

Definition at line 323 of file Method.php.

References $name, $type, getHTMLSignature(), and getName().

{
$name = $this->getName();
$signature = $this->getHTMLSignature();
$id = md5($name);
$help = nl2br(htmlentities($this->_help));
print " <h3><a name=\"$id\">$signature</a></h3>\n";
print " <p><b>Description :</b></p>\n";
print " <div class=\"description\">\n";
print " $help\n";
print " </div>\n";
if (count($this->_parameters)>0) {
print " <p><b>Parameters : </b></p>\n";
if (count($this->_parameters)>0) {
print " <table>\n";
print " <tr><td><b>Type</b></td><td><b>Name</b></td><td><b>Documentation</b></td></tr>\n";
while (list($name, $parameter) = each($this->_parameters)) {
$type = $parameter['type'];
$doc = htmlentities($parameter['doc']);
print " <tr><td>$type</td><td>$name</td><td>$doc</td></tr>\n";
}
reset($this->_parameters);
print " </table>\n";
}
}
}

+ Here is the call graph for this function:

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, $name, $result, and $type.

Referenced by autoDocument().

{
$returnType = $this->_returns;
$result = "<span class=\"type\">($returnType)</span> ";
$result .= "<span class=\"name\">$name</span>";
$result .= "<span class=\"other\">(</span>";
$first = true;
$nbr = 0;
while (list($name, $parameter) = each($this->_parameters)) {
$nbr++;
if ($nbr == $this->_numberOfRequiredParameters + 1) {
$result .= "<span class=\"other\"> [ </span>";
}
if ($first) {
$first = false;
} else {
$result .= ', ';
}
$type = $parameter['type'];
$result .= "<span class=\"paratype\">($type) </span>";
$result .= "<span class=\"paraname\">$name</span>";
}
reset($this->_parameters);
if ($nbr > $this->_numberOfRequiredParameters) {
$result .= "<span class=\"other\"> ] </span>";
}
$result .= "<span class=\"other\">)</span>";
return $result;
}

+ Here is the caller graph for this function:

XML_RPC2_Server_Method::getInternalMethod ( )

internalMethod getter

Returns
string internalMethod

Definition at line 120 of file Method.php.

References $_internalMethod.

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().

{
return $this->_name;
}

+ Here is the caller graph for this function:

XML_RPC2_Server_Method::isHidden ( )

hidden getter

Returns
boolean hidden value

Definition at line 133 of file Method.php.

References $_hidden.

{
}
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 $param, and _limitPHPType().

{
if ($methodName != $this->_name) return false;
if (count($callParams) < $this->_numberOfRequiredParameters) return false;
if (count($callParams) > $this->_parameters) return false;
$paramIndex = 0;
foreach($this->_parameters as $param) {
$paramIndex++;
if ($paramIndex <= $this->_numberOfRequiredParameters) {
// the parameter is not optional
$callParamType = XML_RPC2_Server_Method::_limitPHPType(gettype($callParams[$paramIndex-1]));
if ((!($param['type'] == 'mixed')) and ($param['type'] != $callParamType)) {
return false;
}
}
}
return true;
}

+ Here is the call graph for this function:

Field Documentation

XML_RPC2_Server_Method::$_help
private

Definition at line 82 of file Method.php.

XML_RPC2_Server_Method::$_hidden
private

Definition at line 96 of file Method.php.

Referenced by isHidden().

XML_RPC2_Server_Method::$_internalMethod
private

Definition at line 89 of file Method.php.

Referenced by getInternalMethod().

XML_RPC2_Server_Method::$_name
private

Definition at line 103 of file Method.php.

Referenced by getHTMLSignature(), and getName().

XML_RPC2_Server_Method::$_numberOfRequiredParameters
private

Definition at line 110 of file Method.php.

XML_RPC2_Server_Method::$_parameters
private

Definition at line 68 of file Method.php.

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: