mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-76055 libraries: Autoload phpxmlrpc and verify it works
Also, we can now safely remove Autoloader.php, because Moodle PSR-4 autoloader has taken control, so document and test it too.
This commit is contained in:
parent
c958bd7305
commit
a0d916bc86
4 changed files with 60 additions and 36 deletions
|
@ -108,6 +108,7 @@ class core_component {
|
||||||
'ZipStream' => 'lib/zipstream/src/',
|
'ZipStream' => 'lib/zipstream/src/',
|
||||||
'MyCLabs\\Enum' => 'lib/php-enum/src',
|
'MyCLabs\\Enum' => 'lib/php-enum/src',
|
||||||
'Psr\\Http\\Message' => 'lib/http-message/src',
|
'Psr\\Http\\Message' => 'lib/http-message/src',
|
||||||
|
'PhpXmlRpc' => 'lib/phpxmlrpc',
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace PhpXmlRpc;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* In the unlikely event that you are not using Composer to manage class autoloading, here's an autoloader for this lib.
|
|
||||||
* For usage, see any file in the demo/client directory
|
|
||||||
*/
|
|
||||||
class Autoloader
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Registers PhpXmlRpc\Autoloader as an SPL autoloader.
|
|
||||||
*
|
|
||||||
* @param bool $prepend Whether to prepend the autoloader or not.
|
|
||||||
*/
|
|
||||||
public static function register($prepend = false)
|
|
||||||
{
|
|
||||||
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles autoloading of classes.
|
|
||||||
*
|
|
||||||
* @param string $class A class name.
|
|
||||||
*/
|
|
||||||
public static function autoload($class)
|
|
||||||
{
|
|
||||||
if (0 !== strpos($class, 'PhpXmlRpc\\')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_file($file = __DIR__ . str_replace(array('PhpXmlRpc\\', '\\'), '/', $class).'.php')) {
|
|
||||||
require $file;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -11,6 +11,8 @@ To update:
|
||||||
- Download or checkout it.
|
- Download or checkout it.
|
||||||
- Delete the contents on the lib/phpxmlrpc directory (but this file) completely.
|
- Delete the contents on the lib/phpxmlrpc directory (but this file) completely.
|
||||||
- Copy the /src directory contents of the library to lib/phpxmlrpc.
|
- Copy the /src directory contents of the library to lib/phpxmlrpc.
|
||||||
|
- Remove the following files:
|
||||||
|
- Autoloader.php
|
||||||
- Edit this file and update the release and commit details below.
|
- Edit this file and update the release and commit details below.
|
||||||
- Edit lib/thirdpartylibs.xml and update the information details too.
|
- Edit lib/thirdpartylibs.xml and update the information details too.
|
||||||
|
|
||||||
|
|
57
lib/tests/phpxmlrpc_test.php
Normal file
57
lib/tests/phpxmlrpc_test.php
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle 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 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle 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.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
namespace core;
|
||||||
|
|
||||||
|
use PhpXmlRpc\Client;
|
||||||
|
use PhpXmlRpc\Request;
|
||||||
|
use PhpXmlRpc\Response;
|
||||||
|
use PhpXmlRpc\Server;
|
||||||
|
use PhpXmlRpc\Value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* phpxmlrpc library unit tests.
|
||||||
|
*
|
||||||
|
* @package core
|
||||||
|
* @category test
|
||||||
|
* @copyright 2022 onwards Eloy Lafuente (stronk7) {@link https://stronk7.com}
|
||||||
|
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class phpxmlrpc_test extends \basic_testcase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure PhpXmlRpc availability.
|
||||||
|
*
|
||||||
|
* This may seem silly, sure it is. But it's a good way to verify
|
||||||
|
* that the Moodle PSR-4 autoloader is working ok.
|
||||||
|
*
|
||||||
|
* @coversNothing
|
||||||
|
*/
|
||||||
|
public function test_phpxmlrpc_availability() {
|
||||||
|
// All these classes need to be at hand.
|
||||||
|
$this->assertInstanceOf(\PhpXmlRpc\Client::class, new Client('https://example.com'));
|
||||||
|
$this->assertInstanceOf(\PhpXmlRpc\Request::class, new Request(''));
|
||||||
|
$this->assertInstanceOf(\PhpXmlRpc\Response::class, new Response(''));
|
||||||
|
$this->assertInstanceOf(\PhpXmlRpc\Server::class, new Server());
|
||||||
|
$this->assertInstanceOf(\PhpXmlRpc\Value::class, new Value());
|
||||||
|
|
||||||
|
// Worth checking that we have removed this.
|
||||||
|
$this->assertFileDoesNotExist(__DIR__ . '/../phpxmlrpc/Autoloader.php');
|
||||||
|
|
||||||
|
// We cannnot live without our beloved readme.
|
||||||
|
$this->assertFileExists(__DIR__ . '/../phpxmlrpc/readme_moodle.txt');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue