ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
XML_RPC2_CachedServer Class Reference
+ Collaboration diagram for XML_RPC2_CachedServer:

Public Member Functions

 handleCall ()
 handle XML_RPC calls
 getResponse ()
 get the XML response of the XMLRPC server
 clean ()
 Clean all the cache.

Static Public Member Functions

static create ($callTarget, $options=array())
 "Emulated Factory" method to get the same API than XML_RPC2_Server class

Protected Member Functions

 __construct ($callTarget, $options=array())
 Constructor.
 getContentLength ($content)
 Gets the content legth of a serialized XML-RPC message in bytes.

Private Member Functions

 _setCacheOptions ($array)
 Set options for the caching process.
 _reflectionWork ($methodName)
 Work on reflection API to search for .caching tags into PHPDOC comments.
 _parseMethodName ($request)
 Parse the method name from the raw XMLRPC client request.
 _workWithoutCache ()
 Do the real stuff if no cache available.
 _makeCacheId ($raw_request)
 make a cache id depending on the raw xmlrpc client request but depending on "environnement" setting too

Private Attributes

 $_cacheByDefault = true
 $_cacheObject = null
 $_serverObject = null
 $_defaultCacheGroup = 'xml_rpc2_server'
 $_callHandler = null
 $_callTarget = ''
 $_prefix = ''
 $_options = array()
 $_cacheDebug = false
 $_encoding = 'iso-8859-1'

Detailed Description

Definition at line 56 of file CachedServer.php.

Constructor & Destructor Documentation

XML_RPC2_CachedServer::__construct (   $callTarget,
  $options = array() 
)
protected

Constructor.

Parameters
object$callHandlerthe call handler will receive a method call for each remote call received.

Definition at line 170 of file CachedServer.php.

References _setCacheOptions().

{
if (isset($options['cacheOptions'])) {
$cacheOptions = $options['cacheOptions'];
$this->_setCacheOptions($cacheOptions);
unset($options['cacheOptions']);
}
if (isset($options['cacheDebug'])) {
$this->_cacheDebug = $options['cacheDebug'];
unset($options['cacheDebug']); // 'cacheDebug' is not a standard option for XML/RPC2/Server
}
$this->_options = $options;
$this->_callTarget = $callTarget;
if (isset($this->_options['encoding'])) {
$this->_encoding = $this->_options['encoding'];
}
if (isset($this->_options['prefix'])) {
$this->_prefix = $this->_options['prefix'];
}
}

+ Here is the call graph for this function:

Member Function Documentation

XML_RPC2_CachedServer::_makeCacheId (   $raw_request)
private

make a cache id depending on the raw xmlrpc client request but depending on "environnement" setting too

Parameters
string$raw_request
Returns
string cache id

Definition at line 376 of file CachedServer.php.

Referenced by getResponse().

{
return md5($raw_request . serialize($this->_options));
}

+ Here is the caller graph for this function:

XML_RPC2_CachedServer::_parseMethodName (   $request)
private

Parse the method name from the raw XMLRPC client request.

NB : the prefix is removed from the method name

Parameters
string$requestraw XMLRPC client request
Returns
string method name

Definition at line 342 of file CachedServer.php.

References $res, and $results.

Referenced by getResponse().

{
// TODO : change for "simplexml"
$res = ereg('<methodName>' . $this->_prefix . '([a-zA-Z0-9\.,\/]*)</methodName>', $request, $results);
if ($res>0) {
return $results[1];
}
return false;
}

+ Here is the caller graph for this function:

XML_RPC2_CachedServer::_reflectionWork (   $methodName)
private

Work on reflection API to search for .caching tags into PHPDOC comments.

Parameters
string$methodNamemethod name
Returns
array array((boolean) weCache, (int) lifetime) => parameters to use for caching

Definition at line 298 of file CachedServer.php.

References $_cacheByDefault, $res, and $results.

Referenced by getResponse().

{
$lifetime = $this->_cacheOptions['lifetime'];
if (is_string($this->_callTarget)) {
$className = strtolower($this->_callTarget);
} else {
$className = get_class($this->_callTarget);
}
$class = new ReflectionClass($className);
$method = $class->getMethod($methodName);
$docs = explode("\n", $method->getDocComment());
foreach ($docs as $i => $doc) {
$doc = trim($doc, " \r\t/*");
$res = ereg('@xmlrpc.caching ([+-]{0,1}[a-zA-Z0-9]*)', $doc, $results); // TODO : better/faster regexp ?
if ($res>0) {
$value = $results[1];
if (($value=='yes') or ($value=='true') or ($value=='on')) {
$weCache = true;
} else if (($value=='no') or ($value=='false') or ($value=='off')) {
$weCache = false;
} else {
$lifetime = (int) $value;
if ($lifetime==-1) {
$weCache = false;
} else {
$weCache = true;
}
}
}
}
return array($weCache, $lifetime);
}

+ Here is the caller graph for this function:

XML_RPC2_CachedServer::_setCacheOptions (   $array)
private

Set options for the caching process.

See Cache_Lite constructor for options Specific options are 'cachedMethods', 'notCachedMethods', 'cacheByDefault', 'defaultCacheGroup' See corresponding properties for more informations

Parameters
array$array

Definition at line 144 of file CachedServer.php.

Referenced by __construct().

{
if (isset($array['defaultCacheGroup'])) {
$this->_defaultCacheGroup = $array['defaultCacheGroup'];
unset($array['defaultCacheGroup']); // this is a "non standard" option for Cache_Lite
}
if (isset($array['cacheByDefault'])) {
$this->_cacheByDefault = $array['cacheByDefault'];
unset($array['CacheByDefault']); // this is a "non standard" option for Cache_Lite
}
$array['automaticSerialization'] = false; // datas are already serialized in this class
if (!isset($array['lifetime'])) {
$array['lifetime'] = 3600; // we need a default lifetime
}
$this->_cacheOptions = $array;
$this->_cacheObject = new Cache_Lite($this->_cacheOptions);
}

+ Here is the caller graph for this function:

XML_RPC2_CachedServer::_workWithoutCache ( )
private

Do the real stuff if no cache available.

Returns
string the response of the real XML/RPC2 server

Definition at line 360 of file CachedServer.php.

References create().

Referenced by getResponse().

{
require_once('XML/RPC2/Server.php');
$this->_serverObject = XML_RPC2_Server::create($this->_callTarget, $this->_options);
return $this->_serverObject->getResponse();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

XML_RPC2_CachedServer::clean ( )

Clean all the cache.

Definition at line 387 of file CachedServer.php.

{
$this->_cacheObject->clean($this->_defaultCacheGroup, 'ingroup');
}
static XML_RPC2_CachedServer::create (   $callTarget,
  $options = array() 
)
static

"Emulated Factory" method to get the same API than XML_RPC2_Server class

Here, simply returns a new instance of XML_RPC2_CachedServer class

Parameters
mixed$callTargeteither a class name or an object instance.
array$optionsassociative array of options
Returns
object a server class instance

Definition at line 203 of file CachedServer.php.

Referenced by _workWithoutCache().

{
return new XML_RPC2_CachedServer($callTarget, $options);
}

+ Here is the caller graph for this function:

XML_RPC2_CachedServer::getContentLength (   $content)
protected

Gets the content legth of a serialized XML-RPC message in bytes.

Parameters
string$contentthe serialized XML-RPC message.
Returns
integer the content length in bytes.

Definition at line 402 of file CachedServer.php.

Referenced by handleCall().

{
if (extension_loaded('mbstring') && (ini_get('mbstring.func_overload') & 2) == 2) {
$length = mb_strlen($content, '8bit');
} else {
$length = strlen((binary)$content);
}
return $length;
}

+ Here is the caller graph for this function:

XML_RPC2_CachedServer::getResponse ( )

get the XML response of the XMLRPC server

Returns
string the XML response

Definition at line 232 of file CachedServer.php.

References $_cacheByDefault, $data, $GLOBALS, _makeCacheId(), _parseMethodName(), _reflectionWork(), and _workWithoutCache().

Referenced by handleCall().

{
if (isset($GLOBALS['HTTP_RAW_POST_DATA'])) {
$methodName = $this->_parseMethodName($GLOBALS['HTTP_RAW_POST_DATA']);
} else {
$methodName = null;
}
$lifetime = $this->_cacheOptions['lifetime'];
if ($this->_cacheDebug) {
if ($weCache) {
print "CACHE DEBUG : default values => weCache=true, lifetime=$lifetime\n";
} else {
print "CACHE DEBUG : default values => weCache=false, lifetime=$lifetime\n";
}
}
if ($methodName) {
// work on reflection API to search for @xmlrpc.caching tags into PHPDOC comments
list($weCache, $lifetime) = $this->_reflectionWork($methodName);
if ($this->_cacheDebug) {
if ($weCache) {
print "CACHE DEBUG : phpdoc comments => weCache=true, lifetime=$lifetime\n";
} else {
print "CACHE DEBUG : phpdoc comments => weCache=false, lifetime=$lifetime\n";
}
}
}
if (($weCache) and ($lifetime!=-1)) {
if (isset($GLOBALS['HTTP_RAW_POST_DATA'])) {
$cacheId = $this->_makeCacheId($GLOBALS['HTTP_RAW_POST_DATA']);
} else {
$cacheId = 'norawpostdata';
}
$this->_cacheObject = new Cache_Lite($this->_cacheOptions);
$this->_cacheObject->setLifetime($lifetime);
if ($data = $this->_cacheObject->get($cacheId, $this->_defaultCacheGroup)) {
// cache id hit
if ($this->_cacheDebug) {
print "CACHE DEBUG : cache is hit !\n";
}
} else {
// cache is not hit
if ($this->_cacheDebug) {
print "CACHE DEBUG : cache is not hit !\n";
}
$this->_cacheObject->save($data);
}
} else {
if ($this->_cacheDebug) {
print "CACHE DEBUG : we don't cache !\n";
}
}
return $data;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

XML_RPC2_CachedServer::handleCall ( )

handle XML_RPC calls

Definition at line 215 of file CachedServer.php.

References getContentLength(), and getResponse().

{
$response = $this->getResponse();
$encoding = 'iso-8859-1';
if (isset($this->_options['encoding'])) {
$encoding = $this->_options['encoding'];
}
header('Content-type: text/xml; charset=' . $encoding);
header('Content-length: ' . $this->getContentLength($response));
print $response;
}

+ Here is the call graph for this function:

Field Documentation

XML_RPC2_CachedServer::$_cacheByDefault = true
private

Definition at line 65 of file CachedServer.php.

Referenced by _reflectionWork(), and getResponse().

XML_RPC2_CachedServer::$_cacheDebug = false
private

Definition at line 123 of file CachedServer.php.

XML_RPC2_CachedServer::$_cacheObject = null
private

Definition at line 72 of file CachedServer.php.

XML_RPC2_CachedServer::$_callHandler = null
private

Definition at line 95 of file CachedServer.php.

XML_RPC2_CachedServer::$_callTarget = ''
private

Definition at line 102 of file CachedServer.php.

XML_RPC2_CachedServer::$_defaultCacheGroup = 'xml_rpc2_server'
private

Definition at line 86 of file CachedServer.php.

XML_RPC2_CachedServer::$_encoding = 'iso-8859-1'
private

Definition at line 130 of file CachedServer.php.

XML_RPC2_CachedServer::$_options = array()
private

Definition at line 116 of file CachedServer.php.

XML_RPC2_CachedServer::$_prefix = ''
private

Definition at line 109 of file CachedServer.php.

XML_RPC2_CachedServer::$_serverObject = null
private

Definition at line 79 of file CachedServer.php.


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