PHPackages                             streamline/openactive-models - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. streamline/openactive-models

Abandoned → [openactive/models](/?search=openactive%2Fmodels)Library[Utility &amp; Helpers](/categories/utility)

streamline/openactive-models
============================

Fork of the openactive/models library. See https://github.com/openactive/models-php for original library

v0.13.0(4y ago)0752MITPHPPHP ^5.6 | ^7.0 | ^8.0

Since May 21Pushed 4y agoCompare

[ Source](https://github.com/nathansalter/models-php)[ Packagist](https://packagist.org/packages/streamline/openactive-models)[ RSS](/packages/streamline-openactive-models/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependencies (3)Versions (21)Used By (0)

models-php [![Latest Stable Version](https://camo.githubusercontent.com/c9554d4b75210f9f4794298a3231d337114166ebcd0cf750c1a3d9cc7b143af6/68747470733a2f2f706f7365722e707567782e6f72672f6f70656e6163746976652f6d6f64656c732f762f737461626c65)](https://packagist.org/packages/openactive/models) [![Total Downloads](https://camo.githubusercontent.com/6c2ac73b023013f0bf91d0acdb58ad165950a5a48c7c098d3d377fb4fc6da22f/68747470733a2f2f706f7365722e707567782e6f72672f6f70656e6163746976652f6d6f64656c732f646f776e6c6f616473)](https://packagist.org/packages/openactive/models)
================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#models-php--)

PHP Models for the OpenActive Opportunity and Booking Specifications

OpenActive aims to provide model files for all classes defined in its Opportunity and Booking specifications across the PHP, Ruby, and .NET languages. This repository is intended for the PHP files; see also the [Ruby](https://github.com/openactive/models-ruby/) and [.NET](https://github.com/openactive/OpenActive.NET) implementations.

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
    - [Models](#models)
        - [OpenActive](#openactive)
        - [Schema.org](#schemaorg)
    - [RPDE](#rpde)
    - [Enums](#enums)
    - [Serialization](#serialization)
        - [`serialize($obj, $prettyPrint = false)`](#serializeobj-prettyprint--false)
        - [`deserialize($data)`](#deserializedata)
- [Contributing](#contributing)

Requirements
------------

[](#requirements)

This project requires PHP &gt;=5.6. While most of the functionality should work down to PHP 5.4, some functionality (especially around parsing of offset for DateTimeZone) will not work with that version of PHP (see the [DateTimeZone PHP docs](https://www.php.net/manual/en/datetimezone.construct.php#refsect1-datetimezone.construct-changelog) for more info).

Installation
------------

[](#installation)

To install via Composer, from terminal, run:

```
composer require openactive/models
```

Usage
-----

[](#usage)

This package provides PHP models for the OpenActive specifications.

It also provide a set of models for the [schema.org](https://schema.org) specifications.

Finally it provides a set of classes to handle OpenActive's [RPDE](https://developer.openactive.io/publishing-data/data-feeds/how-a-data-feed-works) data feeds.

### Models

[](#models)

The models are included under the `\OpenActive\Models` namespace.

You can instantiate a new model, passing an associative array, where the key is the attribute name, and the value is the attribute value.

For example, from your PHP application, run:

```
// Make sure you use the right namespace for your models
use OpenActive\Models\OA\SessionSeries;
use OpenActive\Models\OA\Place;
use OpenActive\Models\OA\GeoCoordinates;
use OpenActive\Models\OA\Concept;
use OpenActive\Models\OA\Organization;
use OpenActive\Models\OA\Offer;

$sessionSeries = new SessionSeries([
    "name" => "Virtual BODYPUMP",
    "description" => "This is the virtual version of the original barbell class, which will help you get lean, toned and fit - fast",
    "startDate" => "2017-04-24T19:30:00-08:00",
    "endDate" => "2017-04-24T23:00:00-08:00",
    "location" => new Place([
        "name" => "Raynes Park High School, 46A West Barnes Lane",
        "geo" => new GeoCoordinates([
            "latitude" => 51.4034423828125,
            "longitude" => -0.2369088977575302,
        ])
    ]),
    "activity" => new Concept([
        "id" => "https://openactive.io/activity-list#5e78bcbe-36db-425a-9064-bf96d09cc351",
        "prefLabel" => "Bodypump™",
        "inScheme" => "https://openactive.io/activity-list"
    ]),
    "organizer" => new Organization([
        "name" => "Central Speedball Association",
        "url" => "http://www.speedball-world.com"
    ]),
    "offers" => [new Offer([
        "identifier" => "OX-AD",
        "name" => "Adult",
        "price" => 3.3,
        "priceCurrency" => "GBP",
        "url" => "https://profile.everyoneactive.com/booking?Site=0140&Activities=1402CBP20150217&Culture=en-GB"
    ])],
]);
```

Please note that type enforcement is in place whenever creating a new model.

For example, providing a `string` to the `target` attribute in the example above will result in an `\OpenActive\Exception\InvalidArgumentException` being thrown.

A set of getters and setters for all the attributes is provided. Type enforcement is in place for setters too.

#### OpenActive

[](#openactive)

The OpenActive models are included under the `\OpenActive\Models\OA` namespace.

To instantiate a new one, see the [models](#models) section, making sure you are using the right namespace from your model.

#### Schema.org

[](#schemaorg)

The Schema.org models are included under the `\OpenActive\Models\SchemaOrg` namespace.

To instantiate a new one, see the [models](#models) section, making sure you are using the right namespace from your model.

### RPDE

[](#rpde)

RpdeItem &amp; RpdeBody are the main classes to use when generating a page for an RPDE feed.

#### Feed items

[](#feed-items)

RpdeItem is used to create each individual item for a page. It includes a data attribute to which should be an instance of an OA Model along with metadata (id, modified, state and kind). It is left to each application developer to generate these models and metadata.

e.g. a session series collection

```
use OpenActive\Rpde\RpdeItem;

$feedItems = [
    new RpdeItem([
        "Id" => "2",
        "Modified" => 4,
        "State" => RpdeState::UPDATED,
        "Kind" => RpdeKind::SESSION_SERIES,
        "Data" => $sessionSeries2,
    ]),
    new RpdeItem([
        "Id" => "1",
        "Modified" => 5,
        "State" => RpdeState::DELETED,
        "Kind" => RpdeKind::SESSION_SERIES,
    ]),
];
```

#### Feed page

[](#feed-page)

RpdeBody is then used to wrap a collection of items and provide the licence and next entries expected from an RPDE page. To help keep pages valid and create an correct next link, use `RpdeBody::createFromNextChangeNumber` or `RpdeBody::createFromModifiedId` to create an RPDE page feed out of an array of `RpdeItem`s (the constructor has been made private).

`RpdeBody::createFromNextChangeNumber` will check that all feed items do indeed come after the `$changeNumber` argument provided. It will contruct the next link based on the modified value of the newest feed item and the provided `$feedBaseUrl` argument.

e.g.

```
use OpenActive\Rpde\RpdeBody;

$feedPage = RpdeBody::createFromNextChangeNumber(
    'https://www.example.com/rpde-feeds/session-series', # $feedBaseUrl
    0, # $changeNumber,
    $feedItems
);

$feedPage->getNext(); # 'https://www.example.com/rpde-feeds/session-series?afterTimestamp=5&afterId=2'
```

`RpdeBody::createFromModifiedId` will check that all feed items do indeed come after the `$id` and `$modified` arguments provided. It will contruct the next link based on the id and modified value of the newest feed item and the provided `$feedBaseUrl` argument.

e.g.

```
use OpenActive\Rpde\RpdeBody;

$feedPage = RpdeBody::createFromModifiedId(
    'https://www.example.com/rpde-feeds/session-series', # $feedBaseUrl
    0, # $id
    0, # $modified,
    $feedItems
);

$feedPage->getNext(); # 'https://www.example.com/rpde-feeds/session-series?afterChangeNumber=5'
```

To override the default licence:

```
$feedPage->setLicense('https://www.example.com/my-licence/v2.0');
```

#### Serializing the feed page

[](#serializing-the-feed-page)

Finally the feed page can then be serialized with `Serialize RpdeBody::serialize($feedPage)` which will also take care of serializing the each feed item's data attribute as JSON-LD.

```
$jsonFeedPage = RpdeBody::serialize($feedPage);
```

See the [OpenActive's guide to publishing data](https://developer.openactive.io/publishing-data/data-feeds) and [the RPDE specification](https://www.openactive.io/realtime-paged-data-exchange/) for more details about RPDE feeds.

### Enums

[](#enums)

Each enum is represented by a class which contains a constant for each available value.

e.g. Adding days of the week to a Schedule:

```
use OpenActive\Models\OA\Schedule;
use OpenActive\Enums\SchemaOrg\DayOfWeek;

new Schedule([
    "scheduledEventType" => "Event",
    "startTime" => "12:00:00",
    "endTime" => "14:00:00",
    "byDay" => [
        new DayOfWeek\Monday,
        new DayOfWeek\Wednesday,
        new DayOfWeek\Friday
    ],
    ...
]);
```

### Serialization

[](#serialization)

This package provides support for JSON-LD serialization/deserialization of [models](#models) and and for the `\OpenActive\Rpde\RpdeBody` object.

#### `serialize($obj, $prettyPrint = false)`

[](#serializeobj-prettyprint--false)

Returns the JSON-LD string representation of the given object `$obj`.

An additional parameter `$prettyPrint` is available to return a JSON-LD string in a human-readable format.

An example, using the `\OpenActive\Models\OA\SessionSeries` defined above:

```
use OpenActive\Models\OA\SessionSeries;

echo SessionSeries::serialize($sessionSeries, true);
```

Will output:

```
{
    "@context": [
        "https:\/\/openactive.io\/",
        "https:\/\/openactive.io\/ns-beta"
    ],
    "type": "SessionSeries",
    "name": "Virtual BODYPUMP",
    "description": "This is the virtual version of the original barbell class, which will help you get lean, toned and fit - fast.",
    "startDate": "2017-04-24T19:30:00-08:00",
    "endDate": "2017-04-24T23:00:00-08:00",
    "location": {...},
    "activity": {...},
    "organizer": {...},
    "offers": [...]
}
```

**Please note:** at the moment, only the OpenActive `@context` is rendered in the serialization output. Future versions of this package may allow to include more and/or different `@context`.

#### `deserialize($data)`

[](#deserializedata)

Returns an object from a given JSON-LD representation.

The `$data` argument can be a JSON-LD string, or an associative array, for example as a result of `json_encode($string, true)`.

For example:

```
use OpenActive\Models\OA\Action;

$jsonLd = '{"@context": ["https:\/\/openactive.io\/","https:\/\/openactive.io\/ns-beta"],"type": "Action","name": "Book","target": {"type": "EntryPoint","encodingType": "application\/vnd.openactive.v1.0+json","httpMethod": "POST","type": "EntryPoint","url": "https:\/\/example.com\/orders"}}';

$action = Action::deserialize($jsonLd);

var_dump($action);
```

Will result in:

```
object(OpenActive\Models\OA\Action)#3 (24) {
  ["name":protected]=>
  string(4) "Book"
  ["target":protected]=>
  object(OpenActive\Models\OA\EntryPoint)#2 (20) {
    ["encodingType":protected]=>
    string(36) "application/vnd.openactive.v1.0+json"
    ["httpMethod":protected]=>
    string(4) "POST"
    ["urlTemplate":protected]=>
    NULL
    ["actionApplication":protected]=>
    NULL
    ["application":protected]=>
    NULL
    ["actionPlatform":protected]=>
    NULL
    ["contentType":protected]=>
    NULL
    ["identifier":protected]=>
    NULL
    ["name":protected]=>
    NULL
    ["description":protected]=>
    NULL
    ["sameAs":protected]=>
    NULL
    ["url":protected]=>
    string(26) "https://example.com/orders"
    ["image":protected]=>
    NULL
    ["additionalType":protected]=>
    NULL
    ["subjectOf":protected]=>
    NULL
    ["mainEntityOfPage":protected]=>
    NULL
    ["potentialAction":protected]=>
    NULL
    ["disambiguatingDescription":protected]=>
    NULL
    ["alternateName":protected]=>
    NULL
    ["id":protected]=>
    NULL
  }
  ["result":protected]=>
  NULL
  ["startTime":protected]=>
  NULL
  ["actionStatus":protected]=>
  NULL
  ["agent":protected]=>
  NULL
  ["endTime":protected]=>
  NULL
  ["instrument":protected]=>
  NULL
  ["participant":protected]=>
  NULL
  ["object":protected]=>
  NULL
  ["error":protected]=>
  NULL
  ["location":protected]=>
  NULL
  ["identifier":protected]=>
  NULL
  ["description":protected]=>
  NULL
  ["sameAs":protected]=>
  NULL
  ["url":protected]=>
  NULL
  ["image":protected]=>
  NULL
  ["additionalType":protected]=>
  NULL
  ["subjectOf":protected]=>
  NULL
  ["mainEntityOfPage":protected]=>
  NULL
  ["potentialAction":protected]=>
  NULL
  ["disambiguatingDescription":protected]=>
  NULL
  ["alternateName":protected]=>
  NULL
  ["id":protected]=>
  NULL
}

```

Contributing
------------

[](#contributing)

### Installation

[](#installation-1)

**Please note:** [Composer](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-macos) is required for dependency management.

```
git clone https://github.com/openactive/models-php.git
cd models-php
composer install
```

### Running Tests

[](#running-tests)

PHPUnit 5.7 is used to run tests.

To run the whole suite:

```
./vendor/bin/phpunit
```

If you want to run the whole suite in verbose mode:

```
./vendor/bin/phpunit --verbose
```

You can also run a section of the suite by specifying the class's relative path on which you want to perform tests:

```
./vendor/bin/phpunit --verbose tests/Unit/RpdeTest.php
```

For additional information on the commands available for PHPUnit, consult [their documentation](https://phpunit.de/manual/5.7/en/installation.html)

### Updating models

[](#updating-models)

A guide is provided in [UPDATING.md](UPDATING.md)

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 79% 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 ~71 days

Recently: every ~101 days

Total

7

Last Release

1757d ago

PHP version history (2 changes)0.1.0PHP &gt;=7.0

v0.12.0PHP ^5.6 | ^7.0 | ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/998690?v=4)[Nathan Salter](/maintainers/nathansalter)[@nathansalter](https://github.com/nathansalter)

---

Top Contributors

[![thtg88](https://avatars.githubusercontent.com/u/16927402?v=4)](https://github.com/thtg88 "thtg88 (271 commits)")[![ylt](https://avatars.githubusercontent.com/u/705668?v=4)](https://github.com/ylt "ylt (37 commits)")[![henryaddison](https://avatars.githubusercontent.com/u/49613?v=4)](https://github.com/henryaddison "henryaddison (24 commits)")[![thill-odi](https://avatars.githubusercontent.com/u/49978820?v=4)](https://github.com/thill-odi "thill-odi (6 commits)")[![nathansalter](https://avatars.githubusercontent.com/u/998690?v=4)](https://github.com/nathansalter "nathansalter (4 commits)")[![nickevansuk](https://avatars.githubusercontent.com/u/2616208?v=4)](https://github.com/nickevansuk "nickevansuk (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/streamline-openactive-models/health.svg)

```
[![Health](https://phpackages.com/badges/streamline-openactive-models/health.svg)](https://phpackages.com/packages/streamline-openactive-models)
```

PHPackages © 2026

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