ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
XML_RPC2_CachedServer Class Reference
+ Collaboration diagram for XML_RPC2_CachedServer:

Public Member Functions

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

Static Public Member Functions

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

Protected Member Functions

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

Private Member Functions

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

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

◆ __construct()

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.

171 {
172 if (isset($options['cacheOptions'])) {
173 $cacheOptions = $options['cacheOptions'];
174 $this->_setCacheOptions($cacheOptions);
175 unset($options['cacheOptions']);
176 }
177 if (isset($options['cacheDebug'])) {
178 $this->_cacheDebug = $options['cacheDebug'];
179 unset($options['cacheDebug']); // 'cacheDebug' is not a standard option for XML/RPC2/Server
180 }
181 $this->_options = $options;
182 $this->_callTarget = $callTarget;
183 if (isset($this->_options['encoding'])) {
184 $this->_encoding = $this->_options['encoding'];
185 }
186 if (isset($this->_options['prefix'])) {
187 $this->_prefix = $this->_options['prefix'];
188 }
189 }
_setCacheOptions($array)
Set options for the caching process.
if(!is_array($argv)) $options

References $options, and _setCacheOptions().

+ Here is the call graph for this function:

Member Function Documentation

◆ _makeCacheId()

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.

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

Referenced by getResponse().

+ Here is the caller graph for this function:

◆ _parseMethodName()

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.

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

References $res, and $results.

Referenced by getResponse().

+ Here is the caller graph for this function:

◆ _reflectionWork()

XML_RPC2_CachedServer::_reflectionWork (   $methodName)
private

Work on reflection API to search for @xmlrpc.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.

298 {
299 $weCache = $this->_cacheByDefault;
300 $lifetime = $this->_cacheOptions['lifetime'];
301 if (is_string($this->_callTarget)) {
302 $className = strtolower($this->_callTarget);
303 } else {
304 $className = get_class($this->_callTarget);
305 }
306 $class = new ReflectionClass($className);
307 $method = $class->getMethod($methodName);
308 $docs = explode("\n", $method->getDocComment());
309 foreach ($docs as $i => $doc) {
310 $doc = trim($doc, " \r\t/*");
311 $res = ereg('@xmlrpc.caching ([+-]{0,1}[a-zA-Z0-9]*)', $doc, $results); // TODO : better/faster regexp ?
312 if ($res>0) {
313 $value = $results[1];
314 if (($value=='yes') or ($value=='true') or ($value=='on')) {
315 $weCache = true;
316 } else if (($value=='no') or ($value=='false') or ($value=='off')) {
317 $weCache = false;
318 } else {
319 $lifetime = (int) $value;
320 if ($lifetime==-1) {
321 $weCache = false;
322 } else {
323 $weCache = true;
324 }
325 }
326 }
327 }
328 return array($weCache, $lifetime);
329 }

References $_cacheByDefault, $res, and $results.

Referenced by getResponse().

+ Here is the caller graph for this function:

◆ _setCacheOptions()

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.

145 {
146 if (isset($array['defaultCacheGroup'])) {
147 $this->_defaultCacheGroup = $array['defaultCacheGroup'];
148 unset($array['defaultCacheGroup']); // this is a "non standard" option for Cache_Lite
149 }
150 if (isset($array['cacheByDefault'])) {
151 $this->_cacheByDefault = $array['cacheByDefault'];
152 unset($array['CacheByDefault']); // this is a "non standard" option for Cache_Lite
153 }
154 $array['automaticSerialization'] = false; // datas are already serialized in this class
155 if (!isset($array['lifetime'])) {
156 $array['lifetime'] = 3600; // we need a default lifetime
157 }
158 $this->_cacheOptions = $array;
159 $this->_cacheObject = new Cache_Lite($this->_cacheOptions);
160 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ _workWithoutCache()

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.

361 {
362 require_once('XML/RPC2/Server.php');
363 $this->_serverObject = XML_RPC2_Server::create($this->_callTarget, $this->_options);
364 return $this->_serverObject->getResponse();
365 }
static create($callTarget, $options=array())
Factory method to select a backend and return a new XML_RPC2_Server based on the backend.
Definition: Server.php:190

References XML_RPC2_Server\create().

Referenced by getResponse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clean()

XML_RPC2_CachedServer::clean ( )

Clean all the cache.

Definition at line 387 of file CachedServer.php.

388 {
389 $this->_cacheObject->clean($this->_defaultCacheGroup, 'ingroup');
390 }

◆ create()

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.

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

References $options.

◆ getContentLength()

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.

403 {
404 if (extension_loaded('mbstring') && (ini_get('mbstring.func_overload') & 2) == 2) {
405 $length = mb_strlen($content, '8bit');
406 } else {
407 $length = strlen((binary)$content);
408 }
409
410 return $length;
411 }

Referenced by handleCall().

+ Here is the caller graph for this function:

◆ getResponse()

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.

233 {
234 if (isset($GLOBALS['HTTP_RAW_POST_DATA'])) {
235 $methodName = $this->_parseMethodName($GLOBALS['HTTP_RAW_POST_DATA']);
236 } else {
237 $methodName = null;
238 }
239 $weCache = $this->_cacheByDefault;
240 $lifetime = $this->_cacheOptions['lifetime'];
241 if ($this->_cacheDebug) {
242 if ($weCache) {
243 print "CACHE DEBUG : default values => weCache=true, lifetime=$lifetime\n";
244 } else {
245 print "CACHE DEBUG : default values => weCache=false, lifetime=$lifetime\n";
246 }
247 }
248 if ($methodName) {
249 // work on reflection API to search for @xmlrpc.caching tags into PHPDOC comments
250 list($weCache, $lifetime) = $this->_reflectionWork($methodName);
251 if ($this->_cacheDebug) {
252 if ($weCache) {
253 print "CACHE DEBUG : phpdoc comments => weCache=true, lifetime=$lifetime\n";
254 } else {
255 print "CACHE DEBUG : phpdoc comments => weCache=false, lifetime=$lifetime\n";
256 }
257 }
258 }
259 if (($weCache) and ($lifetime!=-1)) {
260 if (isset($GLOBALS['HTTP_RAW_POST_DATA'])) {
261 $cacheId = $this->_makeCacheId($GLOBALS['HTTP_RAW_POST_DATA']);
262 } else {
263 $cacheId = 'norawpostdata';
264 }
265 $this->_cacheObject = new Cache_Lite($this->_cacheOptions);
266 $this->_cacheObject->setLifetime($lifetime);
267 if ($data = $this->_cacheObject->get($cacheId, $this->_defaultCacheGroup)) {
268 // cache id hit
269 if ($this->_cacheDebug) {
270 print "CACHE DEBUG : cache is hit !\n";
271 }
272 } else {
273 // cache is not hit
274 if ($this->_cacheDebug) {
275 print "CACHE DEBUG : cache is not hit !\n";
276 }
277 $data = $this->_workWithoutCache();
278 $this->_cacheObject->save($data);
279 }
280 } else {
281 if ($this->_cacheDebug) {
282 print "CACHE DEBUG : we don't cache !\n";
283 }
284 $data = $this->_workWithoutCache();
285 }
286 return $data;
287 }
_reflectionWork($methodName)
Work on reflection API to search for @xmlrpc.caching tags into PHPDOC comments.
_makeCacheId($raw_request)
make a cache id depending on the raw xmlrpc client request but depending on "environnement" setting t...
_workWithoutCache()
Do the real stuff if no cache available.
_parseMethodName($request)
Parse the method name from the raw XMLRPC client request.
$data
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
if(! $in) print

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

Referenced by handleCall().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleCall()

XML_RPC2_CachedServer::handleCall ( )

handle XML_RPC calls

Definition at line 215 of file CachedServer.php.

216 {
217 $response = $this->getResponse();
218 $encoding = 'iso-8859-1';
219 if (isset($this->_options['encoding'])) {
220 $encoding = $this->_options['encoding'];
221 }
222 header('Content-type: text/xml; charset=' . $encoding);
223 header('Content-length: ' . $this->getContentLength($response));
224 print $response;
225 }
getContentLength($content)
Gets the content legth of a serialized XML-RPC message in bytes.
getResponse()
get the XML response of the XMLRPC server

References getContentLength(), getResponse(), and print.

+ Here is the call graph for this function:

Field Documentation

◆ $_cacheByDefault

XML_RPC2_CachedServer::$_cacheByDefault = true
private

Definition at line 65 of file CachedServer.php.

Referenced by _reflectionWork(), and getResponse().

◆ $_cacheDebug

XML_RPC2_CachedServer::$_cacheDebug = false
private

Definition at line 123 of file CachedServer.php.

◆ $_cacheObject

XML_RPC2_CachedServer::$_cacheObject = null
private

Definition at line 72 of file CachedServer.php.

◆ $_callHandler

XML_RPC2_CachedServer::$_callHandler = null
private

Definition at line 95 of file CachedServer.php.

◆ $_callTarget

XML_RPC2_CachedServer::$_callTarget = ''
private

Definition at line 102 of file CachedServer.php.

◆ $_defaultCacheGroup

XML_RPC2_CachedServer::$_defaultCacheGroup = 'xml_rpc2_server'
private

Definition at line 86 of file CachedServer.php.

◆ $_encoding

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

Definition at line 130 of file CachedServer.php.

◆ $_options

XML_RPC2_CachedServer::$_options = array()
private

Definition at line 116 of file CachedServer.php.

◆ $_prefix

XML_RPC2_CachedServer::$_prefix = ''
private

Definition at line 109 of file CachedServer.php.

◆ $_serverObject

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: