mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
web serviceMDL-12886 refactor servers into object + add Zend_soap and Zend_xmlrpc server
This commit is contained in:
parent
625b51d4e0
commit
06e7fadc43
79 changed files with 10475 additions and 211 deletions
77
webservice/xmlrpc/lib.php
Normal file
77
webservice/xmlrpc/lib.php
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/**
|
||||
* Moodle - Modular Object-Oriented Dynamic Learning Environment
|
||||
* http://moodle.com
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details:
|
||||
*
|
||||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* @category Moodle
|
||||
* @package webservice
|
||||
* @copyright Copyright (c) 1999 onwards Martin Dougiamas http://dougiamas.com
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL License
|
||||
*/
|
||||
|
||||
/*
|
||||
* XML-RPC server class
|
||||
*/
|
||||
|
||||
require_once('../lib.php');
|
||||
|
||||
final class xmlrpc_server extends webservice_server {
|
||||
|
||||
public function __construct() {
|
||||
|
||||
$this->set_protocolname("XML-RPC");
|
||||
}
|
||||
|
||||
public function run() {
|
||||
include "Zend/Loader.php";
|
||||
Zend_Loader::registerAutoload();
|
||||
|
||||
Zend_XmlRpc_Server_Fault::attachFaultException('moodle_exception');
|
||||
|
||||
// retrieve the token from the url
|
||||
// if the token doesn't exist, set a class containing only get_token()
|
||||
$token = optional_param('token',null,PARAM_ALPHANUM);
|
||||
if (empty($token)) {
|
||||
$server = new Zend_XmlRpc_Server();
|
||||
$server->setClass("ws_authentication", "authentication");
|
||||
echo $server->handle();
|
||||
} else { // if token exist, do the authentication here
|
||||
/// TODO: following function will need to be modified
|
||||
$user = webservice_lib::mock_check_token($token);
|
||||
if (empty($user)) {
|
||||
throw new moodle_exception('wrongidentification');
|
||||
} else {
|
||||
/// TODO: probably change this
|
||||
global $USER;
|
||||
$USER = $user;
|
||||
}
|
||||
|
||||
//retrieve the api name
|
||||
$classpath = optional_param(classpath,null,PARAM_ALPHA);
|
||||
require_once(dirname(__FILE__) . '/../../'.$classpath.'/external.php');
|
||||
|
||||
/// run the server
|
||||
$server = new Zend_XmlRpc_Server();
|
||||
$server->setClass($classpath."_external", $classpath);
|
||||
echo $server->handle();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
53
webservice/xmlrpc/testclient/zend_xmlrpc_client.php
Normal file
53
webservice/xmlrpc/testclient/zend_xmlrpc_client.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
/**
|
||||
* Moodle - Modular Object-Oriented Dynamic Learning Environment
|
||||
* http://moodle.com
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details:
|
||||
*
|
||||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* @category Moodle
|
||||
* @package webservice
|
||||
* @copyright Copyright (c) 1999 onwards Martin Dougiamas http://dougiamas.com
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL License
|
||||
*/
|
||||
|
||||
/*
|
||||
* Zend XMLRPC sclient
|
||||
*/
|
||||
require_once('../../../config.php');
|
||||
|
||||
include "Zend/Loader.php";
|
||||
Zend_Loader::registerAutoload();
|
||||
|
||||
|
||||
//1. authentication
|
||||
$client = new Zend_XmlRpc_Client($CFG->wwwroot."/webservice/xmlrpc/zend_xmlrpc_server.php");
|
||||
$token = $client->call('authentication.tmp_get_token', array(array('username' => "wsuser", 'password' => "wspassword")));
|
||||
var_dump($token);
|
||||
|
||||
//2. test functions
|
||||
$client = new Zend_XmlRpc_Client($CFG->wwwroot."/webservice/xmlrpc/zend_xmlrpc_server.php?classpath=user&token=".$token);
|
||||
var_dump($users = $client->call('user.tmp_get_users', array(array('search' => "admin"))));
|
||||
print "<br/><br/>\n";
|
||||
var_dump($users = $client->call('user.tmp_create_user', array(array('username' => "mockuser66",'firstname' => "firstname6",'lastname' => "lastname6",'email' => "mockuser6@mockuser6.com",'password' => "password6"))));
|
||||
print "<br/><br/>\n";
|
||||
var_dump($users = $client->call('user.tmp_update_user', array(array('username' => "mockuser66",'mnethostid' => 1,'newusername' => "mockuser6b",'firstname' => "firstname6b"))));
|
||||
print "<br/><br/>\n";
|
||||
var_dump($users = $client->call('user.tmp_delete_user', array(array('username' => "mockuser6b",'mnethostid' => 1))));
|
||||
print "<br/><br/>\n";
|
||||
var_dump($users = $client->call('user.tmp_do_multiple_user_searches', array(array(array('search' => "jerome"),array('search' => "admin")))));
|
||||
print "<br/><br/>\n";
|
||||
|
||||
?>
|
46
webservice/xmlrpc/zend_xmlrpc_server.php
Normal file
46
webservice/xmlrpc/zend_xmlrpc_server.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
/**
|
||||
* Moodle - Modular Object-Oriented Dynamic Learning Environment
|
||||
* http://moodle.com
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details:
|
||||
*
|
||||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* @category Moodle
|
||||
* @package webservice
|
||||
* @copyright Copyright (c) 1999 onwards Martin Dougiamas http://dougiamas.com
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL License
|
||||
*/
|
||||
/**
|
||||
* Main script - XML-RPC server
|
||||
*
|
||||
* @author Jerome Mouneyrac <jerome@moodle.com>
|
||||
* @version 1.0
|
||||
* @package webservices
|
||||
*/
|
||||
|
||||
/*
|
||||
* Zend XML-RPC server
|
||||
*/
|
||||
require_once(dirname(__FILE__) . '/../../config.php');
|
||||
require_once('lib.php');
|
||||
|
||||
if (empty($CFG->enablewebservices)) {
|
||||
die;
|
||||
}
|
||||
|
||||
$server = new xmlrpc_server();
|
||||
$server->run();
|
||||
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue