PHPackages                             elan-ev/opencast-api - 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. elan-ev/opencast-api

ActiveLibrary[API Development](/categories/api)

elan-ev/opencast-api
====================

A comprehensive PHP library for Opencast

2.0.0(6mo ago)66.0k↓26.9%3[3 issues](https://github.com/elan-ev/opencast-php-library/issues)GPL-3.0-or-laterPHPPHP ^8.1CI passing

Since Mar 30Pushed 6mo ago4 watchersCompare

[ Source](https://github.com/elan-ev/opencast-php-library)[ Packagist](https://packagist.org/packages/elan-ev/opencast-api)[ Docs](https://docs.opencast.org/)[ RSS](/packages/elan-ev-opencast-api/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (15)Used By (0)

opencast-php-library
====================

[](#opencast-php-library)

This PHP composer package is meant to provide a unified easy-to-use Opencast RESTful API library. It has been designed to make most of commonly used REST Endpoints available to the developers of thirt-party applications mainly LMSes such as Stud.IP, Moodle and ILIAS. Please refer to the [Change Log](https://github.com/elan-ev/opencast-php-library/blob/master/CHANGELOG.md) for more info.

Note
----

[](#note)

As of version 1.2.0 the main class name has been changed from `OpenCast` to `Opencast`. Please refer to [Upgrade Log](https://github.com/elan-ev/opencast-php-library/blob/master/UPGRADING.md) for more info.

Requisitions
============

[](#requisitions)

**PHP Version 7.2.5 or above** as well as **cURL** are required. Additionaly, the [requirements](https://docs.guzzlephp.org/en/stable/overview.html#requirements) of [guzzlehttp/guzzle](https://packagist.org/packages/guzzlehttp/guzzle#7.0.0) must be fullfiled.

**Note:** Starting from version 2.x, the minimum required PHP version is **8.1**.

Installation
============

[](#installation)

`composer require elan-ev/opencast-api`

Basic Usage
===========

[](#basic-usage)

There are 2 approaches to use the Opencast REST Endpoints from this library:

1. The first one is via the generic `OpencastApi\Opencast` which contains all available Opencast endpoints (which are capable with the API version defined in the config). The advantage of using this approach is a better control over all available endpoints. **(Recommended)**

**NOTE:** When using this library against a distributed Opencast setup with admin and presentation split, you can pass another set of configuration as the second parameter when instantiating the `OpencastApi\Opencast`. Initially, the presentation node only takes care of search endpoint.

```
$config = [
      'url' => 'https://develop.opencast.org/',       // The API URL of the Opencast instance. (required)
      'username' => 'admin',                          // The API username. (required)
      'password' => 'opencast',                       // The API password. (required)
      'timeout' => 0,                                 // The API timeout. In seconds (default 0 to wait indefinitely). (optional)
      'connect_timeout' => 0,                         // The API connection timeout. In seconds (default 0 to wait indefinitely) (optional)
      'version' => null,                              // The API Version. (Default null). (optional)
      'handler' => null,                               // The callable Handler or HandlerStack. (Default null). (optional)
      'features' => null,                              // A set of additional features [e.g. lucene search]. (Default null). (optional)
      'guzzle' => null,                                // Additional Guzzle Request Options. These options can overwrite some default options (Default null). (optional)
      'jwt' => [                                      // JWT Configuration. When exists, the JWT auth is activated.
            'private_key' => '...',                   // Private Key in full text.
            'algorithm' => 'ES256',                   // Algorithm with which the public/private key has been created
            'expiration' => 3600,                     // The expiration duration of the token
      ],
];

$engageConfig = [
      'url' => 'https://develop.opencast.org/',       // The API URL of the Opencast instance. (required)
      'username' => 'admin',                          // The API username. (required)
      'password' => 'opencast',                       // The API password. (required)
      'timeout' => 0,                                 // The API timeout. In seconds (default 0 to wait indefinitely). (optional)
      'connect_timeout' => 0,                         // The API connection timeout. In seconds (default 0 to wait indefinitely) (optional)
      'version' => null,                              // The API version. (Default null). (optional)
      'handler' => null,                               // The callable Handler or HandlerStack. (Default null). (optional)
      'features' => null,                              // A set of additional features [e.g. lucene search]. (Default null). (optional)
      'guzzle' => null,                                // Additional Guzzle Request Options. These options can overwrite some default options (Default null). (optional)
      'jwt' => [                                      // JWT Configuration. When exists, the JWT auth is activated.
            'private_key' => '...',                   // Private Key in full text.
            'algorithm' => 'ES256',                   // Algorithm with which the public/private key has been created
            'expiration' => 3600,                     // The expiration duration of the token
      ],
];

use OpencastApi\Opencast;

// In case of a distributed Opencast setup
$opencastDualApi = new Opencast($config, $engageConfig);
// Or simply
$opencastApi = new Opencast($config);

// Accessing Event Endpoints to get all events
$events = [];
$eventsResponse = $opencastApi->eventsApi->getAll();
if ($eventsResponse['code'] == 200) {
      $events = $eventsResponse['body'];
}

// Accessing Series Endpoints to get all series
$series = [];
$seriesResponse = $opencastApi->seriesApi->getAll();
if ($seriesResponse['code'] == 200) {
      $series = $seriesResponse['body'];
}

// ...
```

2. The second approach is to instantiate each REST endpoint class, which are located under `OpencastApi\Rest\` namespace, when needed, but the down side of this is that it needs a `OpencastApi\Rest\OcRestClient` instance as its parameter. The advantage of this approach might be the methods' definitions in the IDE.

```
$config = [
      'url' => 'https://develop.opencast.org/',       // The API URL of the Opencast instance. (required)
      'username' => 'admin',                          // The API username. (required)
      'password' => 'opencast',                       // The API password. (required)
      'timeout' => 0,                                 // The API timeout. In seconds (default 0 to wait indefinitely). (optional)
      'connect_timeout' => 0,                         // The API connection timeout. In seconds (default 0 to wait indefinitely) (optional)
      'version' => null,                              // The API version. (Default null). (optional)
      'handler' => null,                               // The callable Handler or HandlerStack. (Default null). (optional)
      'features' => null,                              // A set of additional features [e.g. lucene search]. (Default null). (optional)
      'guzzle' => null,                                // Additional Guzzle Request Options. These options can overwrite some default options (Default null). (optional)
      'jwt' => [                                      // JWT Configuration. When exists, the JWT auth is activated.
            'private_key' => '...',                   // Private Key in full text.
            'algorithm' => 'ES256',                   // Algorithm with which the public/private key has been created
            'expiration' => 3600,                     // The expiration duration of the token
      ],
];

use OpencastApi\Rest\OcRestClient;
use OpencastApi\Rest\OcEventsApi;
use OpencastApi\Rest\OcSeriesApi;

// Get a client object.
$opencastClient = new OcRestClient($config);

// To get events.
$opencastEventsApi = new OcEventsApi($opencastClient);
$events = [];
$eventsResponse = $opencastEventsApi->getAll();
if ($eventsResponse['code'] == 200) {
      $events = $eventsResponse['body'];
}

// To get series.
$opencastSeriesApi = new OcSeriesApi($opencastClient);
$series = [];
$seriesResponse = $opencastSeriesApi->getAll();
if ($seriesResponse['body'] == 200) {
      $series = $seriesResponse['body'];
}

// ...
```

Configuration
=============

[](#configuration)

The configuration is type of `Array` and has to be defined as follows:

```
$config = [
      'url' => 'https://develop.opencast.org/',       // The API URL of the Opencast instance. (required)
      'username' => 'admin',                          // The API username. (required)
      'password' => 'opencast',                       // The API password. (required)
      'timeout' => 0,                                 // The API timeout. In seconds (default 0 to wait indefinitely). (optional)
      'connect_timeout' => 0,                         // The API connection timeout. In seconds (default 0 to wait indefinitely) (optional)
      'version' => null,                              // The API version. (Default null). (optional)
      'handler' => null,                               // The callable Handler or HandlerStack. (Default null). (optional)
      'features' => null,                              // A set of additional features [e.g. lucene search]. (Default null). (optional)
      'guzzle' => null,                                // Additional Guzzle Request Options. These options can overwrite some default options (Default null). (optional)
      'jwt' => [                                      // JWT Configuration. When exists, the JWT auth is activated.
            'private_key' => '...',                   // Private Key in full text.
            'algorithm' => 'ES256',                   // Algorithm with which the public/private key has been created
            'expiration' => 3600,                     // The expiration duration of the token
      ],
];
```

> **Update (v2.0.0):** A new configuration parameter has been introduced to enable **JWT authentication**, allowing the JWT component to issue and validate tokens. For more details, see the [JWT Authentication Mechanism](#jwt-authentication-mechanism).

> **UPDATE (v1.9.0):** a new config parameter called "guzzle" is introduced, which is intended to pass additional guzzle request options to the call. These options will take precedence over the default configs like uri, auth and timeouts, but some other options like query, fome\_params and json will be overwritten by the function if present.

> **UPDATE (v1.7.0):** the new items called `features` is added to the configuration array. As of now, it is meant to hanlde the toggle behavior to enable/disable Lucene search endpoint simply by adding `'features' => ['lucene' => true]`. Just keep in mind that this endpoint id off by default and won't work in Opencast 16 onwards. Therefore, developer must be very careful to use this feature and to toggle it!

> NOTE: the configuration for presentation (`engage` node) responsible for search has to follow the same definition as normal config. But in case any parameter is missing, the value will be taken from the main config param.

#### Extra: Dynamically loading the ingest endpoint class into Opencast instance.

[](#extra-dynamically-loading-the-ingest-endpoint-class-into-opencast-instance)

As of v1.3 it is possible to enable (Default) or disable the ingest endpoint to be loaded into `OpencastApi\Opencast` by passing a boolean value as the last argument of the class as follows:

```
use OpencastApi\Opencast;
$opencastApiWithIngest = new Opencast($config, $engageConfig);
$opencastApiWithoutIngest = new Opencast($config, $engageConfig, false);
// ...
```

JWT Authentication Mechanism
============================

[](#jwt-authentication-mechanism)

Starting from **version 2.0.0**, the Opencast PHP library introduces a **JWT-based authentication mechanism**. This feature handles issuing and verifying access tokens, creating Opencast-specific claims, and validating these claims.

For details about Opencast's JWT configuration and claim standards, see the official documentation: 👉 [Opencast Configuration for JWT-based Authentication and Authorization](https://docs.opencast.org/r/18.x/admin/#configuration/security.jwt/#configuration-for-jwt-based-authentication-and-authorization)

---

### Requirements

[](#requirements)

To support this feature, some version requirements apply:

- **PHP:** 8.1 or higher
- **Opencast:** 18.0 or higher (JWT and ACL support required)

---

### Configuration

[](#configuration-1)

To enable JWT authentication in this library, add the `jwt` configuration array to your existing setup:

```
$config = [
    ...,
    'jwt' => [                                     // JWT configuration. When present, JWT auth is enabled.
        'private_key' => '...',                    // Private key in full text.
        'algorithm'   => 'ES256',                  // Algorithm used for key generation.
        'expiration'  => 3600,                     // Token expiration time in seconds.
    ],
];
```

---

### How to Use

[](#how-to-use)

Before performing authenticated requests, you need to create an Opencast-specific claim using `OcJwtClaim`.

```
use OpencastApi\Auth\JWT\OcJwtClaim;
...

// Example: Claim with event ACLs
$ocClaim = new OcJwtClaim();
$eventAcl = [
    "{event id}" => ['read'],
];
$ocClaim->setEventAcls($eventAcl);
// Also for series.
$seriesAcl = [
    "{series id}" => ['read', 'write'],
];
$ocClaim->setSeriesAcls($seriesAcl);
// Also for playlists.
$playlistAcl = [
    "{playlist id}" => ['read', 'write'],
];
$ocClaim->setPlaylistAcls($playlistAcl);

// Example: Claim with user info and roles
$ocClaim = new OcJwtClaim();
$name = 'JWT TEST USER 1';
$username = 'jwt_test_user_1';
$email = 'jwt_test_user_1@test.test';

// User Info.
$ocClaim->setUserInfoClaims($username, $name, $email);
// Roles.
$ocClaim->setRoles(['ROLE_USER_1', 'ROLE_JWT_USER_1']);

// Creating from array is also there:
$userInfoArray = [
    'sub'   => 'jwt_test_user_2',
    'name'  => 'JWT TEST USER 2',
    'email' => 'jwt_test_user_2@test.test',
    'roles' => ['ROLE_USER_2', 'ROLE_JWT_USER_2'],
];

$ocClaim = OcJwtClaim::createFromArray($userInfoArray);
...
```

---

#### Calling Endpoints with JWT

[](#calling-endpoints-with-jwt)

You can call API endpoints using JWT simply by chaining the `withClaims()` method before the desired service:

```
use OpencastApi\Opencast;
use OpencastApi\Auth\JWT\OcJwtClaim;
...

$config = [
    ...,
    'jwt' => [
        'private_key' => '...',
        'algorithm'   => 'ES256',
        'expiration'  => 3600,
    ],
];

$api = new Opencast($config);

$userInfoArray = [
    'sub'   => 'jwt_test_user_2',
    'name'  => 'JWT TEST USER 2',
    'email' => 'jwt_test_user_2@test.test',
    'roles' => ['ROLE_USER_2', 'ROLE_JWT_USER_2'],
];

$ocClaim = OcJwtClaim::createFromArray($userInfoArray);

// Example endpoint call using JWT
$response = $api->info->withClaims($ocClaim)->getInfoMeJson();
...
```

---

#### Token Generation and Validation

[](#token-generation-and-validation)

This approach is typically used when you only need to generate or validate JWT access tokens. You first need to call `getJwtHandler()` from the Opencast class to obtain an instance of `OcJwtHandler` - the library's core JWT component - which provides access to the `validateToken()` and `issueToken()` methods.

```
use OpencastApi\Opencast;
use OpencastApi\Auth\JWT\OcJwtClaim;
...

$config = [
    ...,
    'jwt' => [
        'private_key' => '...',
        'algorithm'   => 'ES256',
        'expiration'  => 3600,
    ],
];

$api = new Opencast($config);

$eventId = '1234...';

$ocClaim = new OcJwtClaim();
$eventAcl = [
    "$eventId" => ['read'], // Allowed actions
];
$ocClaim->setEventAcls($eventAcl);

// Issue a new token
$accessToken = $api->getJwtHandler()->issueToken($ocClaim);

// Attach token to a URL or include it in the Authorization header
$staticFileUrl = '.../static/.../test.mp4' . '?jwt=' . $accessToken;

// Validate the token
$isValid = $api->getJwtHandler()->validateToken($accessToken);

// Extract and compare claims
$extractedOcClaim = $api->getJwtHandler()->getOcJwtClaimFromTokenString($accessToken);
$comparingAclAction = ['read', 'write'];
$matchedActions = $extractedOcClaim->actionsMatchFor(OcJwtClaim::OC_EVENT, $eventId, $comparingAclAction);
```

Response
========

[](#response)

The return result of each call is an `Array` containing the following information: From v1.4 the 5th response parameter 'origin' is available!

```
[
      'code' => 200,                            // The status code of the response
      'body' => '',                             // The result of the response. It can be type of string, array or objec ('' || [] || {})
      'reason' => 'OK',                         // The reason/message of response
      'location' => '',                         // The location header of the response when available,
      'origin' => [                             // The information about the origin of the request (ADDED in v1.4)
            'base' => 'https://example.com',    // Request base url address
            'path' => '/api/path',              // Request url path
            'method' => 'GET',                  // Request method
            'params' => [                       // Request parameters
                'query_params' => [],
                'form_params' => [],
                'form_multipart_params' => [],
                'json' => [],
                'body' => null,
            ]
      ]
]
```

Filters and Sorts
=================

[](#filters-and-sorts)

Filters and Sorts must be defined as associative `Array`, as follows:

```
// for example:

$filters = [
      'title' => 'The title name',
      'creator' => 'opencast admin'
];

$sorts = [
      'title' => 'DESC',
      'startDate' => 'ASC'
];
```

**NOTE:** Sometimes a filter can occur multiple times for example in [Series API `/get`](https://docs.opencast.org/develop/developer/#architecture/api/series-api/#get-apiseries), filters like `subject` and `identifier` can occur multiple times. Therefore, an `Array` should be passed as filter value like following:

```
// for example:

$filters = [
      'identifier' => [
            '{first ID}',  '{second ID}'
      ],
      'subject' => [
            '{first Subject}',  '{second Subject}'
      ]
];
```

`runWithRoles([])`
==================

[](#runwithroles)

Sometimes it is needed to perform the request with a disposable header of `X-RUN-WITH-ROLES` containing some roles (e.g. user ids) in order for Opencast to assume that those users has special access right.
It is commonly used to get data with `onlyWithWriteAccess` parameter for example to perform [`getAll`](https://github.com/elan-ev/opencast-php-library/wiki/OcSeriesApi#getallparams--) in `OcSeriesApi` and grab those series that only specified users have access to!
In order to perform such requests it is needed to call the `runWithRoles` method **before** calling the desired function in a class:
NOTE: This method **accepts** an `Array` defining the roles to check against!

```
// With Opencast generic class
use OpencastApi\Opencast;
$opencastApi = new Opencast($config);

// Role
$roles = ['ROLE_ADMIN'];
$seriesResponse = $opencastApi->seriesApi->runWithRoles($roles)->getAll(['onlyWithWriteAccess' => true]);

// Or direct class call
$opencastClient = \OpencastApi\Rest\OcRestClient($config);
$ocSeriesApi = \OpencastApi\Rest\OcSeriesApi($opencastClient);
// Role
$roles = ['ROLE_ADMIN'];
$seriesResponse = $ocSeriesApi->runWithRoles($roles)->getAll(['onlyWithWriteAccess' => true]);
```

**NOTE:** Roles can be either an `Array` including each role, or a comma separated string!

`runAsUser($user)`
==================

[](#runasuseruser)

Sometimes it is needed to perform the request with a disposable header of `X-RUN-AS-USER` containing the user id in order for Opencast to assume that this user has access right. This feature is added since v1.4. NOTE: This method **accepts** an `String` defining the user id to check against!

```
// With Opencast generic class
use OpencastApi\Opencast;
$opencastApi = new Opencast($config);

// Role
$user = 'lms-admin';
$seriesResponse = $opencastApi->seriesApi->runAsUser($user)->getAll(['onlyWithWriteAccess' => true]);

// Or direct class call
$opencastClient = \OpencastApi\Rest\OcRestClient($config);
$ocSeriesApi = \OpencastApi\Rest\OcSeriesApi($opencastClient);
// Role
$user = 'lms-admin';
$seriesResponse = $ocSeriesApi->runAsUser($user)->getAll(['onlyWithWriteAccess' => true]);
```

`noHeader()`
============

[](#noheader)

In order to perform a request call to an endpoint without any request headers/options, you can use this method **before** calling the desired function in an endpoint class: NOTE: This method **accepts** nothing (`void`).

```
// With Opencast generic class
use OpencastApi\Opencast;
$opencastApi = new Opencast($config);

$baseResponse = $opencastApi->baseApi->noHeader()->get();

// Or direct class call
$opencastClient = \OpencastApi\Rest\OcRestClient($config);
$ocBaseApi = \OpencastApi\Rest\OcBaseApi($opencastClient);
$baseResponse = $ocBaseApi->noHeader()->get();
```

`setRequestTimeout($timeout = 0)`
=================================

[](#setrequesttimeouttimeout--0)

In order to perform a request call with a different timeout value other than the one set in the configuration, you can use this method **before** calling the desired function in an endpoint class: NOTE: This method **accepts** integer defining a single use timeout in second.

```
// With Opencast generic class
use OpencastApi\Opencast;
$opencastApi = new Opencast($config);

$baseResponse = $opencastApi->baseApi->setRequestTimeout(10)->get();

// Or direct class call
$opencastClient = \OpencastApi\Rest\OcRestClient($config);
$ocBaseApi = \OpencastApi\Rest\OcBaseApi($opencastClient);
$baseResponse = $ocBaseApi->setRequestTimeout(10)->get();
```

`setRequestConnectionTimeout($connectionTimeout = 0)`
=====================================================

[](#setrequestconnectiontimeoutconnectiontimeout--0)

In order to perform a request call with a different connection timeout value other than the one set in the configuration, you can use this method **before** calling the desired function in an endpoint class: NOTE: This method **accepts** integer defining a single use connection timeout in second.

```
// With Opencast generic class
use OpencastApi\Opencast;
$opencastApi = new Opencast($config);

$baseResponse = $opencastApi->baseApi->setRequestConnectionTimeout(10)->get();

// Or direct class call
$opencastClient = \OpencastApi\Rest\OcRestClient($config);
$ocBaseApi = \OpencastApi\Rest\OcBaseApi($opencastClient);
$baseResponse = $ocBaseApi->setRequestConnectionTimeout(10)->get();
```

Available Opencast REST Service Endpoint
========================================

[](#available-opencast-rest-service-endpoint)

- `/api/*`: all known API endpoints of Opencast are available to be used in this library. [API Endpoints definitions WiKi](https://github.com/elan-ev/opencast-php-library/wiki/API-Endpoints)
- `/ingest/*`: all known Ingest endpoints are available. [Ingest Endpoint definitions WiKi](https://github.com/elan-ev/opencast-php-library/wiki/OcIngest)
- `/services/services.json`: only services.json is available. [Services Endpoint definitions WiKi](https://github.com/elan-ev/opencast-php-library/wiki/OcServices)
- `/search/{episode | lucene | series}.{json | xml}`: only episode, lucene and series in JSON or XML format are available. [Search Endpoint definitions WiKi](https://github.com/elan-ev/opencast-php-library/wiki/OcSearch)
- `/capture-admin/*`: all known Capture Admin endpoints are available. [Capture Admin Endpoint definitions WiKi](https://github.com/elan-ev/opencast-php-library/wiki/OcCaptureAdmin)
- `/admin-ng/event/delete`: only delete endpoint is available. [Admin Ng Endpoint definitions WiKi](https://github.com/elan-ev/opencast-php-library/wiki/OcEventAdminNg)
- `/recordings/*`: all known Recording endpoints are available. [Recordings Endpoint definitions WiKi](https://github.com/elan-ev/opencast-php-library/wiki/OcRecordings)
- `/series/*`: all known Series endpoints are available. [Series Endpoint definitions WiKi](https://github.com/elan-ev/opencast-php-library/wiki/OcSeries)
- `/workflow/*`: all known Workflow endpoints are available. [Workflow Endpoint definitions WiKi](https://github.com/elan-ev/opencast-php-library/wiki/OcWorkflow)
- `/sysinfo/bundles/version`: (v1.1.1) only bundle version endpoint is available. [Sysinfo Endpoint definitions WiKi](https://github.com/elan-ev/opencast-php-library/wiki/OcSysinfo)

Utility Class
=============

[](#utility-class)

Starting from version **v1.9.0**, a new utility class has been introduced to provide additional functionality, making it easier to integrate and consume this library's output within applications.

How to use
----------

[](#how-to-use-1)

To use the utility class, initialize it directly via its namespace and start calling its functions:

```
use OpencastApi\Opencast;
use OpencastApi\Util\OcUtils;
...
$config = [...];
$opencastApi = new Opencast($config);

$params = [...];
$response = $opencastApi->ocSearch->getEpisodes($params);

// Use `findValueByKey` from the Utility class to extract the mediapackage from the response,
// regardless of the response's structure.
$mediapackage = OcUtils::findValueByKey($response['body'], 'mediapackage');
...
```

Mocking Responses
=================

[](#mocking-responses)

In order to conduct proper testing, a mocking mechanism is provided.

How to use
----------

[](#how-to-use-2)

### Step 1: Responses Array

[](#step-1-responses-array)

As in the first step it is necessary to have all the responses in an array form, which has to have the following structure:

```
$responsesArray = [
      "/api/events" => [ // Request Path
            "GET": [ // METHOD
                  [
                        "body" => "", //Response body (Default "")
                        "status": 200, // Status code (Default 200)
                        "headers": [], // Response headers (Default [])
                        "version": "", // Protocol version (Default null)
                        "reason": "", // Reason phrase (when empty a default will be used based on the status code) (Default null)
                        "params": []  // The optional params to pass to the call (Default [])
                  ]
            ],
            "POST": [ // METHOD
                  [
                        "body" => "", //Response body (Default "")
                        "status": 200, // Status code (Default 200)
                        "headers": [], // Response headers (Default [])
                        "version": "", // Protocol version (Default null)
                        "reason": "", // Reason phrase (when empty a default will be used based on the status code) (Default null)
                        "params": []  // The optional params to pass to the call (Default [])
                  ],
                  [...] // Multiple response data object to have multiple calls to the same path and same method. Please see the NOTE below.
            ],
            "PUT": [
                  [...]
            ],
            "DELETE": [
                  [...]
            ]
      ],
];
```

NOTE: In order to apply multiple calls to the same path, a unique parameter called `unique_request_identifier` in `params` array must be provided, for example you want to update a series's acl twice with the same path but different acl values: (The value of the unique identifier must be something within the body of the request)

```
$responsesArray = [
      "/api/series/{series id}/acl": [
            "PUT": [ // PUT METHOD on the same path
                  [
                        "body" => "", //Response body (Default "")
                        "status": 200, // Status code (Default 200)
                        "params": [  // The optional params to pass to the call (Default [])
                              "unique_request_identifier": "acl=[]"
                        ],
                  ],
                  [
                        "body" => "[{\"allow\":true,\"role\":\"ROLE_ANONYMOUS\",\"action\":\"read\"}]", //Response body (Default "")
                        "status": 200, // Status code (Default 200)
                        "params": [  // The optional params to pass to the call (Default [])
                              "unique_request_identifier": "ROLE_ANONYMOUS"
                        ],
                  ]
            ]
      ],
];
```

### Step 2: Creating a new MockHandler instance and passing to the configuration array.

[](#step-2-creating-a-new-mockhandler-instance-and-passing-to-the-configuration-array)

In order to create a new MockHandler instance, you should use `\OpencastApi\Mock\OcMockHanlder::getHandlerStackWithPath` and pass that instance into the configuration array with handler key, like so:

```
$mockResponses = [...]; // As described above.
$mockHandler = \OpencastApi\Mock\OcMockHanlder::getHandlerStackWithPath($mockResponses);

$config = [/*the config*/];
$config['handler'] = $mockHandler;
$opencast = new \OpencastApi\Opencast($config);
```

#### Extra: Log requests uri

[](#extra-log-requests-uri)

if you want to have a list of request uri, you can pass a file path variable as the second argument into the `\OpencastApi\Mock\OcMockHanlder::getHandlerStackWithPath` to write/append every uri into that file, like so;

```
$filePath = '{A valid writeable file path}';
$mockResponses = [...]; // As described above.
$mockHandler = \OpencastApi\Mock\OcMockHanlder::getHandlerStackWithPath($mockResponses, $filePath);

$config = [/*the config*/];
$config['handler'] = $mockHandler;
$opencast = new \OpencastApi\Opencast($config);
```

Naming convention
=================

[](#naming-convention)

Classes:
--------

[](#classes)

Apart from 'Opencast' class, all other classes under `OpencastApi\Rest\` namespace start with `Oc` followed by the name and the endpoint category. For example:

- `OcEventsApi` contains 3 parts including Oc + Endpoint Name (Events) + Endpoint Category (Api)
- `OcServices` contains 2 parts including Oc + Endpoint Name/Category (Services)

Opencast class properties:
--------------------------

[](#opencast-class-properties)

The naming convention to access the endpoint subclasses from `OpencastApi\Opencast` as its properties, includes the name of the class without `Oc` in camelCase format. For example:

```
use OpencastApi\Opencast;
$config = [/*the config*/];
$opencast = new Opencast($config);

// Accessing OcEventsApi would be like: (without Oc and in camelCase format)
$ocEventsApi = $opencast->eventsApi;
```

References
==========

[](#references)

- [Main Opencast REST Service Documentation](https://develop.opencast.org/rest_docs.html)
- [Detailed Opencast REST API Endpoints Documentation](https://docs.opencast.org/develop/developer/#architecture/api)

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance56

Moderate activity, may be stable

Popularity30

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 91.7% 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.

###  Release Activity

Cadence

Every ~100 days

Recently: every ~125 days

Total

14

Last Release

203d ago

Major Versions

1.9.1 → 2.0.02025-10-28

PHP version history (2 changes)1.0.0PHP &gt;=7.2.5

2.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/547a4ff7de6fec2abb67d1fefb0d06d92256e40ada8bcc31ba7faca5bb662b93?d=identicon)[elan-ev](/maintainers/elan-ev)

---

Top Contributors

[![ferishili](https://avatars.githubusercontent.com/u/53179227?v=4)](https://github.com/ferishili "ferishili (144 commits)")[![tgloeggl](https://avatars.githubusercontent.com/u/6160?v=4)](https://github.com/tgloeggl "tgloeggl (5 commits)")[![luniki](https://avatars.githubusercontent.com/u/2993?v=4)](https://github.com/luniki "luniki (2 commits)")[![justusdieckmann](https://avatars.githubusercontent.com/u/45795270?v=4)](https://github.com/justusdieckmann "justusdieckmann (2 commits)")[![dennis531](https://avatars.githubusercontent.com/u/44410838?v=4)](https://github.com/dennis531 "dennis531 (2 commits)")[![Rillke](https://avatars.githubusercontent.com/u/2311611?v=4)](https://github.com/Rillke "Rillke (1 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

apirestfulopencast

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/elan-ev-opencast-api/health.svg)

```
[![Health](https://phpackages.com/badges/elan-ev-opencast-api/health.svg)](https://phpackages.com/packages/elan-ev-opencast-api)
```

###  Alternatives

[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.6M74](/packages/openai-php-laravel)[teepluss/api

Laravel 4 Internal Request (HMVC)

7034.0k](/packages/teepluss-api)[mvdnbrk/dhlparcel-php-api

DHL Parcel API client for PHP

3957.9k5](/packages/mvdnbrk-dhlparcel-php-api)

PHPackages © 2026

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