[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/webservice/xmlrpc/ -> lib.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  
  18  /**
  19   * Moodle XML-RPC library
  20   *
  21   * @package    webservice_xmlrpc
  22   * @copyright  2009 Jerome Mouneyrac
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  require_once 'Zend/XmlRpc/Client.php';
  27  
  28  /**
  29   * Moodle XML-RPC client
  30   *
  31   * It has been implemented for unit testing purpose (all protocols have similar client)
  32   *
  33   * @package    webservice_xmlrpc
  34   * @copyright  2010 Jerome Mouneyrac
  35   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class webservice_xmlrpc_client extends Zend_XmlRpc_Client {
  38  
  39      /** @var string server url e.g. https://yyyyy.com/server.php */
  40      private $serverurl;
  41  
  42      /**
  43       * Constructor
  44       *
  45       * @param string $serverurl a Moodle URL
  46       * @param string $token the token used to do the web service call
  47       */
  48      public function __construct($serverurl, $token) {
  49          $this->serverurl = $serverurl;
  50          $serverurl = $serverurl . '?wstoken=' . $token;
  51          parent::__construct($serverurl);
  52      }
  53  
  54      /**
  55       * Set the token used to do the XML-RPC call
  56       *
  57       * @param string $token the token used to do the web service call
  58       */
  59      public function set_token($token) {
  60          $this->_serverAddress = $this->serverurl . '?wstoken=' . $token;
  61      }
  62  
  63      /**
  64       * Execute client WS request with token authentication
  65       *
  66       * @param string $functionname the function name
  67       * @param array $params the parameters of the function
  68       * @return mixed
  69       */
  70      public function call($functionname, $params=array()) {
  71          global $DB, $CFG;
  72  
  73          //zend expects 0 based array with numeric indexes
  74          $params = array_values($params);
  75  
  76          //traditional Zend soap client call (integrating the token into the URL)
  77          $result = parent::call($functionname, $params);
  78  
  79          return $result;
  80      }
  81  
  82  }


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