ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Server.php
Go to the documentation of this file.
1<?php
2
3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
4
5// LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{
6
40// }}}
41
42// dependencies {{{
43require_once 'XML/RPC2/Exception.php';
44require_once 'XML/RPC2/Backend.php';
45// }}}
46
47
97abstract class XML_RPC2_Server
98{
99
100 // {{{ properties
101
109 protected $callHandler = null;
110
116 protected $prefix = '';
117
125 protected $encoding = 'iso-8859-1';
126
132 protected $autoDocument = true;
133
140
149 protected $signatureChecking = true;
150
151 // }}}
152 // {{{ constructor
153
160 protected function __construct($callHandler, $options = array())
161 {
162 $this->callHandler = $callHandler;
163 if ((isset($options['prefix'])) && (is_string($options['prefix']))) {
164 $this->prefix = $options['prefix'];
165 }
166 if ((isset($options['encoding'])) && (is_string($options['encoding']))) {
167 $this->encoding = $options['encoding'];
168 }
169 if ((isset($options['autoDocument'])) && (is_bool($options['autoDocument']))) {
170 $this->autoDocument = $options['autoDocument'];
171 }
172 if ((isset($options['autoDocumentExternalLinks'])) && (is_bool($options['autoDocumentExternalLinks']))) {
173 $this->autoDocumentExternalLinks = $options['autoDocumentExternalLinks'];
174 }
175 if ((isset($options['signatureChecking'])) && (is_bool($options['signatureChecking']))) {
176 $this->signatureChecking = $options['signatureChecking'];
177 }
178 }
179
180 // }}}
181 // {{{ create()
182
190 public static function create($callTarget, $options = array())
191 {
192 if (isset($options['backend'])) {
194 }
195 if (isset($options['prefix'])) {
196 $prefix = $options['prefix'];
197 } else {
198 $prefix = '';
199 }
201 // Find callHandler class
202 if (!isset($options['callHandler'])) {
203 if (is_object($callTarget)) { // Delegate calls to instance methods
204 require_once 'XML/RPC2/Server/CallHandler/Instance.php';
205 $callHandler = new XML_RPC2_Server_CallHandler_Instance($callTarget, $prefix);
206 } else { // Delegate calls to static class methods
207 require_once 'XML/RPC2/Server/CallHandler/Class.php';
208 $callHandler = new XML_RPC2_Server_CallHandler_Class($callTarget, $prefix);
209 }
210 } else {
211 $callHandler = $options['callHandler'];
212 }
213 return new $backend($callHandler, $options);
214 }
215
216 // }}}
217 // {{{ handleCall()
218
223 public abstract function handleCall();
224
225 // }}}
226 // {{{ errorToException()
227
236 public static function errorToException($errno, $errstr, $errfile, $errline)
237 {
238 switch ($errno) {
239 case E_WARNING:
240 case E_NOTICE:
241 case E_USER_WARNING:
242 case E_USER_NOTICE:
243 case E_STRICT:
244 // Silence warnings
245 // TODO Logging should occur here
246 break;
247 default:
248 throw new Exception('Classic error reported "' . $errstr . '" on ' . $errfile . ':' . $errline);
249 }
250 }
251
252 // }}}
253 // {{{ autoDocument()
254 /* autoDocument {{{ */
260 public function autoDocument()
261 /* }}} */
262 {
263 print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
264 print "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n";
265 print " <head>\n";
266 print " <meta http-equiv=\"Content-Type\" content=\"text/HTML; charset=" . $this->encoding . "\" />\n";
267 print " <title>Available XMLRPC methods for this server</title>\n";
268 print " <style type=\"text/css\">\n";
269 print " li,p { font-size: 10pt; font-family: Arial,Helvetia,sans-serif; }\n";
270 print " a:link { background-color: white; color: blue; text-decoration: underline; font-weight: bold; }\n";
271 print " a:visited { background-color: white; color: blue; text-decoration: underline; font-weight: bold; }\n";
272 print " table { border-collapse:collapse; width: 100% }\n";
273 print " table,td { padding: 5px; border: 1px solid black; }\n";
274 print " div.bloc { border: 1px dashed gray; padding: 10px; margin-bottom: 20px; }\n";
275 print " div.description { border: 1px solid black; padding: 10px; }\n";
276 print " span.type { background-color: white; color: gray; font-weight: normal; }\n";
277 print " span.paratype { background-color: white; color: gray; font-weight: normal; }\n";
278 print " span.name { background-color: white; color: #660000; }\n";
279 print " span.paraname { background-color: white; color: #336600; }\n";
280 print " img { border: 0px; }\n";
281 print " li { font-size: 12pt; }\n";
282 print " </style>\n";
283 print " </head>\n";
284 print " <body>\n";
285 print " <h1>Available XMLRPC methods for this server</h1>\n";
286 print " <h2><a name=\"index\">Index</a></h2>\n";
287 print " <ul>\n";
288 foreach ($this->callHandler->getMethods() as $method) {
289 $name = $method->getName();
290 $id = md5($name);
291 $signature = $method->getHTMLSignature();
292 print " <li><a href=\"#$id\">$name()</a></li>\n";
293 }
294 print " </ul>\n";
295 print " <h2>Details</h2>\n";
296 foreach ($this->callHandler->getMethods() as $method) {
297 print " <div class=\"bloc\">\n";
298 $method->autoDocument();
299 print " <p>(return to <a href=\"#index\">index</a>)</p>\n";
300 print " </div>\n";
301 }
302 if (!($this->autoDocumentExternalLinks)) {
303 print ' <p><a href="http://pear.php.net/packages/XML_RPC2"><img src="http://pear.php.net/gifs/pear-power.png" alt="Powered by PEAR/XML_RPC2" height="31" width="88" /></a> &nbsp; &nbsp; &nbsp; <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a> &nbsp; &nbsp; &nbsp; <a href="http://jigsaw.w3.org/css-validator/"><img style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" /></a></p>' . "\n";
304 }
305 print " </body>\n";
306 print "</html>\n";
307 }
308 // }}}
309 // {{{ getContentLength()
310
318 protected function getContentLength($content)
319 {
320 if (extension_loaded('mbstring') && (ini_get('mbstring.func_overload') & 2) == 2) {
321 $length = mb_strlen($content, '8bit');
322 } else {
323 $length = strlen((binary)$content);
324 }
325
326 return $length;
327 }
328
329 // }}}
330}
331
332?>
static getServerClassname()
Include the relevant php files for the server class, and return the backend server class name.
Definition: Backend.php:157
static setBackend($backend)
Backend setter.
Definition: Backend.php:98
handleCall()
Receive the XML-RPC request, decode the HTTP payload, delegate execution to the call handler,...
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
$autoDocumentExternalLinks
Definition: Server.php:139
static errorToException($errno, $errstr, $errfile, $errline)
Transform an error into an exception.
Definition: Server.php:236
__construct($callHandler, $options=array())
Create a new XML-RPC Server.
Definition: Server.php:160
getContentLength($content)
Gets the content legth of a serialized XML-RPC message in bytes.
Definition: Server.php:318
if(! $in) print
if(!is_array($argv)) $options