PHPackages                             unige/moodlewsclient - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. unige/moodlewsclient

ActiveLibrary[API Development](/categories/api)

unige/moodlewsclient
====================

Client for Moodle web services

16PHP

Since Oct 15Pushed 6y ago1 watchersCompare

[ Source](https://github.com/UniGe/MoodleWSClient)[ Packagist](https://packagist.org/packages/unige/moodlewsclient)[ RSS](/packages/unige-moodlewsclient/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

A "magic" Moodle web services client
====================================

[](#a-magic-moodle-web-services-client)

The class MoodleWSClient is a stub to a remote Moodle server. The server must be configured to expose web services using REST protocol. See Moodle documentation for this topic. You can invoke Moodle web services functions as methods of the objec, e.g.:

```
require_once 'vendor/autoload.php';

$token = ...;  // user token, see Administration Block -> Plugins -> Web Services -> Manage tokens

$moodle = new \UniGe\MoodleWSClient('https://yourmoodle/', $token);

$site_info = $moodle->core_webservice_get_site_info();
echo "Your are connected to {$site_info->sitename}\n";

$courses = $moodle->core_course_get_courses();
foreach ($courses as $course) {
    echo $course->idnumber . " " . $course->fullname . "n";
}

```

Usage
-----

[](#usage)

Install it using composer, searching for unige/moodlewsclient.

To instantiate a client stub:

```
$moodle = new \UniGe\MoodleWSClient($moodle_url);

```

The class implements \\Psr\\Log\\Logger, so you can setup any PSR-3-compatible logger.

If you have a security token, you can pass it to the constructor:

```
$moodle = new \UniGe\MoodleWSClient($moodle_url, $token);

```

or

```
$moodle = new \UniGe\MoodleWSClient($moodle_url);
$moodle->setToken($token);

```

otherwise, you can obtain one from Moodle:

```
$moodle = new \UniGe\MoodleWSClient($moodle_url);
$token = $moodle->newToken($username, $password, $service);
$moodle->setToken($token);

```

If your network requires a proxy, you can set it before invoking methods:

```
$moodle->setupProxy($host, $port, $user = NULL, $pass = NULL)

```

Functions and arguments
-----------------------

[](#functions-and-arguments)

Using PHP magic method \_\_call(), a MoodleWSClient exposes remote API as local methods: e.g. a Moodle web service function core\_fun() are invoked as $moodle-&gt;core\_fun().

However, this client is not aware of the functions effectively exposed by the server because plugins can add own functions and Moodle service definition can limit the core functions available to users. Thus this class accept any function name and raise an Exception if the server cannot understand it.

As a Moodle administrator, you can have a list of functions available on your server from Administration Block -&gt; Plugins -&gt; Web Services -&gt; API Documentation

Another issue is that Moodle web services requires arguments by name, and this is emulated in PHP using associative array. Sometimes arguments required by a function is a little not-intuitive from the documentation. The MoodleWSClient class automatically serialize objects to the required format, so you a more fluent style can be use. E.g., to create a course:

```
$course = new stdClass();
$course->fullname = $info->fullname;

$course->shortname = $info->shortname;
$course->categoryid = $category->id;
$course->idnumber = $info->idnumber;
$course->visible = 0;
$course->summary = "{$captions['codins']} {$info->codice_ins}";
// ... other course field

$moodle->core_course_create_courses(['courses' => [$course]]);

```

Please that web service connection setup has a significative overhead; you can speedup operation passing multiple arguments to functions every times it is possible. Fortunately, Moodle functions usually operate on arrays of elements, for instance core\_course\_create\_courses() wants an array of courses to create in one shot.

File upload
-----------

[](#file-upload)

Even if there is a web service function to upload files, it has poor performances. Moodle offers an alternative efficient way to upload files using HTTP POST. The MoodleWSClient class implements it in the method upload().

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 88.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/b831f6051a4f8a7954a5b2c43bce005faa66aba9c0350538bfafb7f51b713a18?d=identicon)[mfprimo](/maintainers/mfprimo)

---

Top Contributors

[![mfprimo](https://avatars.githubusercontent.com/u/1607497?v=4)](https://github.com/mfprimo "mfprimo (8 commits)")[![awandrea](https://avatars.githubusercontent.com/u/23695115?v=4)](https://github.com/awandrea "awandrea (1 commits)")

### Embed Badge

![Health badge](/badges/unige-moodlewsclient/health.svg)

```
[![Health](https://phpackages.com/badges/unige-moodlewsclient/health.svg)](https://phpackages.com/packages/unige-moodlewsclient)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M478](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M271](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
