[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/lib/zend/Zend/XmlRpc/Server/ -> System.php (source)

   1  <?php
   2  /**
   3   * Zend Framework
   4   *
   5   * LICENSE
   6   *
   7   * This source file is subject to the new BSD license that is bundled
   8   * with this package in the file LICENSE.txt.
   9   * It is also available through the world-wide-web at this URL:
  10   * http://framework.zend.com/license/new-bsd
  11   * If you did not receive a copy of the license and are unable to
  12   * obtain it through the world-wide-web, please send an email
  13   * to [email protected] so we can send you a copy immediately.
  14   *
  15   * @category   Zend
  16   * @package    Zend_XmlRpc
  17   * @subpackage Server
  18   * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19   * @license    http://framework.zend.com/license/new-bsd     New BSD License
  20   * @version    $Id$
  21   */
  22  
  23  /**
  24   * XML-RPC system.* methods
  25   *
  26   * @category   Zend
  27   * @package    Zend_XmlRpc
  28   * @subpackage Server
  29   * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  30   * @license    http://framework.zend.com/license/new-bsd     New BSD License
  31   */
  32  class Zend_XmlRpc_Server_System
  33  {
  34      /**
  35       * @var Zend_XmlRpc_Server
  36       */
  37      protected $_server;
  38  
  39      /**
  40       * Constructor
  41       *
  42       * @param  Zend_XmlRpc_Server $server
  43       * @return void
  44       */
  45      public function __construct(Zend_XmlRpc_Server $server)
  46      {
  47          $this->_server = $server;
  48      }
  49  
  50      /**
  51       * List all available XMLRPC methods
  52       *
  53       * Returns an array of methods.
  54       *
  55       * @return array
  56       */
  57      public function listMethods()
  58      {
  59          $table = $this->_server->getDispatchTable()->getMethods();
  60          return array_keys($table);
  61      }
  62  
  63      /**
  64       * Display help message for an XMLRPC method
  65       *
  66       * @param string $method
  67       * @return string
  68       */
  69      public function methodHelp($method)
  70      {
  71          $table = $this->_server->getDispatchTable();
  72          if (!$table->hasMethod($method)) {
  73              require_once 'Zend/XmlRpc/Server/Exception.php';
  74              throw new Zend_XmlRpc_Server_Exception('Method "' . $method . '" does not exist', 640);
  75          }
  76  
  77          return $table->getMethod($method)->getMethodHelp();
  78      }
  79  
  80      /**
  81       * Return a method signature
  82       *
  83       * @param string $method
  84       * @return array
  85       */
  86      public function methodSignature($method)
  87      {
  88          $table = $this->_server->getDispatchTable();
  89          if (!$table->hasMethod($method)) {
  90              require_once 'Zend/XmlRpc/Server/Exception.php';
  91              throw new Zend_XmlRpc_Server_Exception('Method "' . $method . '" does not exist', 640);
  92          }
  93          $method = $table->getMethod($method)->toArray();
  94          return $method['prototypes'];
  95      }
  96  
  97      /**
  98       * Multicall - boxcar feature of XML-RPC for calling multiple methods
  99       * in a single request.
 100       *
 101       * Expects a an array of structs representing method calls, each element
 102       * having the keys:
 103       * - methodName
 104       * - params
 105       *
 106       * Returns an array of responses, one for each method called, with the value
 107       * returned by the method. If an error occurs for a given method, returns a
 108       * struct with a fault response.
 109       *
 110       * @see http://www.xmlrpc.com/discuss/msgReader$1208
 111       * @param  array $methods
 112       * @return array
 113       */
 114      public function multicall($methods)
 115      {
 116          $responses = array();
 117          foreach ($methods as $method) {
 118              $fault = false;
 119              if (!is_array($method)) {
 120                  $fault = $this->_server->fault('system.multicall expects each method to be a struct', 601);
 121              } elseif (!isset($method['methodName'])) {
 122                  $fault = $this->_server->fault('Missing methodName: ' . var_export($methods, 1), 602);
 123              } elseif (!isset($method['params'])) {
 124                  $fault = $this->_server->fault('Missing params', 603);
 125              } elseif (!is_array($method['params'])) {
 126                  $fault = $this->_server->fault('Params must be an array', 604);
 127              } else {
 128                  if ('system.multicall' == $method['methodName']) {
 129                      // don't allow recursive calls to multicall
 130                      $fault = $this->_server->fault('Recursive system.multicall forbidden', 605);
 131                  }
 132              }
 133  
 134              if (!$fault) {
 135                  try {
 136                      $request = new Zend_XmlRpc_Request();
 137                      $request->setMethod($method['methodName']);
 138                      $request->setParams($method['params']);
 139                      $response = $this->_server->handle($request);
 140                      if ($response instanceof Zend_XmlRpc_Fault
 141                          || $response->isFault()
 142                      ) {
 143                          $fault = $response;
 144                      } else {
 145                          $responses[] = $response->getReturnValue();
 146                      }
 147                  } catch (Exception $e) {
 148                      $fault = $this->_server->fault($e);
 149                  }
 150              }
 151  
 152              if ($fault) {
 153                  $responses[] = array(
 154                      'faultCode'   => $fault->getCode(),
 155                      'faultString' => $fault->getMessage()
 156                  );
 157              }
 158          }
 159  
 160          return $responses;
 161      }
 162  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1