Cheetah
Functions
xmlrpc_wrappers.inc File Reference

Go to the source code of this file.

Functions

 php_2_xmlrpc_type ($phptype)
 
 xmlrpc_2_php_type ($xmlrpctype)
 
 wrap_php_function ($funcname, $newfuncname='', $extra_options=array())
 
 wrap_xmlrpc_method ($client, $methodname, $extra_options=0, $timeout=0, $protocol='', $newfuncname='')
 
 wrap_xmlrpc_server ($client, $extra_options=array())
 
 build_remote_method_wrapper_code ($client, $methodname, $xmlrpcfuncname, $msig, $mdesc='', $timeout=0, $protocol='', $client_copy_mode=0, $prefix='xmlrpc', $decode_php_objects=false, $encode_php_objects=false, $decode_fault=false, $fault_response='')
 
 build_client_wrapper_code ($client, $verbatim_client_copy, $prefix='xmlrpc')
 

Function Documentation

◆ build_client_wrapper_code()

build_client_wrapper_code (   $client,
  $verbatim_client_copy,
  $prefix = 'xmlrpc' 
)

Given necessary info, generate php code that will rebuild a client object Take care that no full checking of input parameters is done to ensure that valid php code is emitted. @access private

Definition at line 796 of file xmlrpc_wrappers.inc.

◆ build_remote_method_wrapper_code()

build_remote_method_wrapper_code (   $client,
  $methodname,
  $xmlrpcfuncname,
  $msig,
  $mdesc = '',
  $timeout = 0,
  $protocol = '',
  $client_copy_mode = 0,
  $prefix = 'xmlrpc',
  $decode_php_objects = false,
  $encode_php_objects = false,
  $decode_fault = false,
  $fault_response = '' 
)

Given the necessary info, build php code that creates a new function to invoke a remote xmlrpc method. Take care that no full checking of input parameters is done to ensure that valid php code is emitted. Note: real spaghetti code follows... @access private

Definition at line 694 of file xmlrpc_wrappers.inc.

◆ php_2_xmlrpc_type()

php_2_xmlrpc_type (   $phptype)

PHP-XMLRPC "wrapper" functions Generate stubs to transparently access xmlrpc methods as php functions and viceversa

Version
Id
xmlrpc_wrappers.inc,v 1.12 2008/03/06 18:58:44 ggiunta Exp
Author
Gaetano Giunta

Given a string defining a php type or phpxmlrpc type (loosely defined: strings accepted come from javadoc blocks), return corresponding phpxmlrpc type. NB: for php 'resource' types returns empty string, since resources cannot be serialized; for php class names returns 'struct', since php objects can be serialized as xmlrpc structs

Parameters
string$phptype
Returns
string

Definition at line 28 of file xmlrpc_wrappers.inc.

◆ wrap_php_function()

wrap_php_function (   $funcname,
  $newfuncname = '',
  $extra_options = array() 
)

Given a user-defined PHP function, create a PHP 'wrapper' function that can be exposed as xmlrpc method from an xmlrpc_server object and called from remote clients (as well as its corresponding signature info).

Since php is a typeless language, to infer types of input and output parameters, it relies on parsing the javadoc-style comment block associated with the given function. Usage of xmlrpc native types (such as datetime.dateTime.iso8601 and base64) in the

Parameters
tagis also allowed, if you need the php function to receive/send data in that particular format (note that base64 encoding/decoding is transparently carried out by the lib, while datetime vals are passed around as strings)

Known limitations:

  • requires PHP 5.0.3 +
  • only works for user-defined functions, not for PHP internal functions (reflection does not support retrieving number/type of params for those)
  • functions returning php objects will generate special xmlrpc responses: when the xmlrpc decoding of those responses is carried out by this same lib, using the appropriate param in php_xmlrpc_decode, the php objects will be rebuilt. In short: php objects can be serialized, too (except for their resource members), using this function. Other libs might choke on the very same xml that will be generated in this case (i.e. it has a nonstandard attribute on struct element tags)
  • usage of javadoc
    Parameters
    tagsusing param names in a different order from the function prototype is not considered valid (to be fixed?)
    Note that since rel. 2.0RC3 the preferred method to have the server call 'standard' php functions (ie. functions not expecting a single xmlrpcmsg obj as parameter) is by making use of the functions_parameters_type class member.
Parameters
string$funcnamethe name of the PHP user function to be exposed as xmlrpc method; array($obj, 'methodname') might be ok too, in the future...
string$newfuncname(optional) name for function to be created
array$extra_options(optional) array of options for conversion. valid values include: bool return_source when true, php code w. function definition will be returned, not evaluated bool encode_php_objs let php objects be sent to server using the 'improved' xmlrpc notation, so server can deserialize them as php objects bool decode_php_objs — WARNING !!! possible security hazard. only use it with trusted servers — bool suppress_warnings remove from produced xml any runtime warnings due to the php function being invoked
Returns
false on error, or an array containing the name of the new php function, its signature and docs, to be used in the server dispatch map

Definition at line 142 of file xmlrpc_wrappers.inc.

◆ wrap_xmlrpc_method()

wrap_xmlrpc_method (   $client,
  $methodname,
  $extra_options = 0,
  $timeout = 0,
  $protocol = '',
  $newfuncname = '' 
)

Given an xmlrpc client and a method name, register a php wrapper function that will call it and return results using native php types for both params and results. The generated php function will return an xmlrpcresp oject for failed xmlrpc calls

Known limitations:

  • server must support system.methodsignature for the wanted xmlrpc method
  • for methods that expose many signatures, only one can be picked (we could in priciple check if signatures differ only by number of params and not by type, but it would be more complication than we can spare time)
  • nested xmlrpc params: the caller of the generated php function has to encode on its own the params passed to the php function if these are structs or arrays whose (sub)members include values of type datetime or base64

Notes: the connection properties of the given client will be copied and reused for the connection used during the call to the generated php function. Calling the generated php function 'might' be slow: a new xmlrpc client is created on every invocation and an xmlrpc-connection opened+closed. An extra 'debug' param is appended to param list of xmlrpc method, useful for debugging purposes.

Parameters
xmlrpc_client$clientan xmlrpc client set up correctly to communicate with target server
string$methodnamethe xmlrpc method to be mapped to a php function
array$extra_optionsarray of options that specify conversion details. valid ptions include integer signum the index of the method signature to use in mapping (if method exposes many sigs) integer timeout timeout (in secs) to be used when executing function/calling remote method string protocol 'http' (default), 'http11' or 'https' string new_function_name the name of php function to create. If unsepcified, lib will pick an appropriate name string return_source if true return php code w. function definition instead fo function name bool encode_php_objs let php objects be sent to server using the 'improved' xmlrpc notation, so server can deserialize them as php objects bool decode_php_objs — WARNING !!! possible security hazard. only use it with trusted servers — mixed return_on_fault a php value to be returned when the xmlrpc call fails/returns a fault response (by default the xmlrpcresp object is returned in this case). If a string is used, 'faultCode' and 'faultString' tokens will be substituted with actual error values bool debug set it to 1 or 2 to see debug results of querying server for method synopsis
Returns
string the name of the generated php function (or false) - OR AN ARRAY...

Definition at line 437 of file xmlrpc_wrappers.inc.

◆ wrap_xmlrpc_server()

wrap_xmlrpc_server (   $client,
  $extra_options = array() 
)

Similar to wrap_xmlrpc_method, but will generate a php class that wraps all xmlrpc methods exposed by the remote server as own methods. For more details see wrap_xmlrpc_method.

Parameters
xmlrpc_client$clientthe client obj all set to query the desired server
array$extra_optionslist of options for wrapped code
Returns
mixed false on error, the name of the created class if all ok or an array with code, class name and comments (if the appropriatevoption is set in extra_options)

Definition at line 576 of file xmlrpc_wrappers.inc.

◆ xmlrpc_2_php_type()

xmlrpc_2_php_type (   $xmlrpctype)

Given a string defining a phpxmlrpc type return corresponding php type.

Parameters
string$xmlrpctype
Returns
string

Definition at line 69 of file xmlrpc_wrappers.inc.