PHPackages                             mrbig/ocpi-protocol - 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. mrbig/ocpi-protocol

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mrbig/ocpi-protocol
===================

Library to handle OCPI. Compatible with PSRs. Uses JsonSchema to validate payloads.

2.2.1-p7(3w ago)2104[1 PRs](https://github.com/mrbig/ocpi-protocol/pulls)MITPHPPHP ^7.4|^8

Since Jul 30Pushed 3w ago1 watchersCompare

[ Source](https://github.com/mrbig/ocpi-protocol)[ Packagist](https://packagist.org/packages/mrbig/ocpi-protocol)[ RSS](/packages/mrbig-ocpi-protocol/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (33)Versions (54)Used By (0)

OCPI Protocol
=============

[](#ocpi-protocol)

Library to handle OCPI. Compatible with PSRs.

DISCLAIMER
----------

[](#disclaimer)

This fork is of chargemap/ocpi-protocol upgraded to OCPI V2.2.1.

This is by no means feature complete, and maybe never will. Currently the most common modules for eMSP and CPO servers are both available, and many of the client classes.

If you miss some classes then please feel free to add them or contact me.

Functionality
-------------

[](#functionality)

Library provides OCPI request/response classes for eMSP interfaces, models, factories and errors. Listing requests/responses are also supported for GET routes. The responses need a corresponding request to be constructed. It is required to ensure the presence and validity of **offset** and **limit** request headers and **X-Total-Count**, **X-Limit** and **Link** response headers. So it is quite easy to construct valid listing response or get the next request.

eMSP interface
--------------

[](#emsp-interface)

### Respond to CPO

[](#respond-to-cpo)

```
use Chargemap\OCPI\Versions\V2_1_1\Server\Emsp\Sessions\Put\OcpiEmspSessionPutRequest;
use Chargemap\OCPI\Versions\V2_1_1\Server\Emsp\Sessions\Put\OcpiEmspSessionPutResponse;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

/** @var RequestInterface $httpRequest */
$sessionPutRequest = new OcpiEmspSessionPutRequest($httpRequest, 'NL', 'TNM', '101');
$session = $sessionPutRequest->getSession();

// Some code...

$sessionPutResponse = new OcpiEmspSessionPutResponse($session);
/** @var ResponseInterface $response */
$response = $sessionPutResponse->getResponseInterface();
```

Each request and response class correspond to an eMSP interface route. Request classes must be instantiated by providing PSR-7 compatible request (got from CPO). Internally, it extracts the authorization token from headers, and validates the body (if necessary) against json schema. Then, it constructs corresponding model class using the factories. The model is accessible via a getter.

Response classes must be instantiated with a model instance, even if it's not used (e.g. in Post/Put/Patch responses). It can be converted to PSR-7 compatible response instance using *getResponseInterface* method.

#### Use of listing request/response

[](#use-of-listing-requestresponse)

```
use Chargemap\OCPI\Versions\V2_1_1\Server\Emsp\Tokens\Get\OcpiEmspTokenGetRequest;
use Chargemap\OCPI\Versions\V2_1_1\Server\Emsp\Tokens\Get\OcpiEmspTokenGetResponse;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

/** @var RequestInterface $httpRequest */
$tokenGetRequest = new OcpiEmspTokenGetRequest($httpRequest);
$tokens = [];
$tokenCount = 0;

//Fetch tokens from database...

$tokenGetResponse = new OcpiEmspTokenGetResponse($tokenGetRequest, $tokenCount, count($tokens));
foreach ($tokens as $token) {
    $tokenGetResponse->addToken($token);
}
// X-Total-Count, X-Limit and Link headers are already set in $response
/** @var ResponseInterface $response */
$response = $tokenGetResponse->getResponseInterface();
```

### Request the CPO

[](#request-the-cpo)

This part provides an API SDK to request the CPO. To use it, you need to instantiate the OcpiClient with OcpiConfiguration and needed endpoints. Then you can perform the requests like that:

```
use Chargemap\OCPI\Versions\V2_1_1\Client\Locations\GetListing\GetLocationsListingRequest;
use Chargemap\OCPI\Versions\V2_1_1\Common\Models\Location;
use Chargemap\OCPI\Common\Client\OcpiClient;
use Chargemap\OCPI\Common\Client\OcpiConfiguration;
use Chargemap\OCPI\Common\Client\OcpiEndpoint;
use Chargemap\OCPI\Common\Client\OcpiVersion;
use Chargemap\OCPI\Common\Models\BaseModuleId;

$ocpiClient = new OcpiClient(
            (new OcpiConfiguration($supervisorAuthString))
                ->withEndpoint(new OcpiEndpoint(
                    OcpiVersion::V2_1_1(),
                    BaseModuleId::LOCATIONS(),
                    new Uri('ocpi/cpo2.0/locations'))
                )
        );
$getLocationListingRequest = (new GetLocationsListingRequest())
                                ->withOffset(0)
                                ->withLimit(100)
                                ->withDateFrom($dateFrom)
                                ->withDateTo($dateTo);
$locationResponse = $ocpiClient->V2_1_1()->locations()->getListing($getLocationListingRequest);
/** @var Location[] $locations */
$locations = $locationResponse->getLocations();
//Some code...
```

#### Listing request/response

[](#listing-requestresponse)

```
use Chargemap\OCPI\Versions\V2_1_1\Client\Locations\GetListing\GetLocationsListingRequest;
use Chargemap\OCPI\Common\Client\OcpiClient;
use Chargemap\OCPI\Common\Client\OcpiConfiguration;
use Chargemap\OCPI\Common\Client\OcpiEndpoint;
use Chargemap\OCPI\Common\Client\OcpiVersion;
use Chargemap\OCPI\Common\Models\BaseModuleId;

$ocpiClient = new OcpiClient(
            (new OcpiConfiguration($supervisorAuth))
                ->withEndpoint(new OcpiEndpoint(
                    OcpiVersion::V2_1_1(),
                    BaseModuleId::LOCATIONS(),
                    new Uri('ocpi/cpo2.0/locations'))
                )
        );
$getLocationListingRequest = (new GetLocationsListingRequest())
                                ->withOffset(0)
                                ->withLimit(100)
                                ->withDateFrom($dateFrom)
                                ->withDateTo($dateTo);
do {
    $locationResponse = $this->ocpiClient->V2_1_1()->locations()->getListing($getLocationListingRequest);

    //Some code...

    //Next request will update its limit and offset values
    $getLocationListingRequest = $locationResponse->getNextRequest();
} while ($getLocationListingRequest !== null);
```

### Common

[](#common)

#### Errors

[](#errors)

Each error class corresponds to an OCPI error code. It can be converted to the PSR-7 response instance just like any response class. It ensures correct HTTP error code as well as OCPI status code.

```
use Chargemap\OCPI\Common\Server\Errors\OcpiGenericClientError;
use Psr\Http\Message\ResponseInterface;

$error = new OcpiGenericClientError('Client error');
//Correct payload and HTTP error code is already set
/** @var ResponseInterface $response */
$response = $error->getResponseInterface();
```

Errors are supposed to be thrown and caught by a middleware/listener and then transformed to the response.

#### Models

[](#models)

Models fetched from request's/response's json body correspond to the OCPI objects. The exception to the rule is Partial\[Class\] classes, that are used in PATCH routes. They have the same but nullable properties as their corresponding \[Class\].

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance95

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~45 days

Total

48

Last Release

24d ago

Major Versions

0.6.1 → v2.2.1.x-dev2025-09-07

PHP version history (2 changes)0.2.1PHP ^7.4

v2.2.1.x-devPHP ^7.4|^8

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/102836?v=4)[Nagy Attila Gábor](/maintainers/mrbig)[@mrbig](https://github.com/mrbig)

---

Top Contributors

[![mrbig](https://avatars.githubusercontent.com/u/102836?v=4)](https://github.com/mrbig "mrbig (204 commits)")[![ChargemapMikhail](https://avatars.githubusercontent.com/u/86592557?v=4)](https://github.com/ChargemapMikhail "ChargemapMikhail (117 commits)")[![ChargemapThomasS](https://avatars.githubusercontent.com/u/86591705?v=4)](https://github.com/ChargemapThomasS "ChargemapThomasS (103 commits)")[![mathieu-muller](https://avatars.githubusercontent.com/u/86592602?v=4)](https://github.com/mathieu-muller "mathieu-muller (94 commits)")[![chargePanelAndreas](https://avatars.githubusercontent.com/u/90181009?v=4)](https://github.com/chargePanelAndreas "chargePanelAndreas (57 commits)")[![chiarito](https://avatars.githubusercontent.com/u/115145370?v=4)](https://github.com/chiarito "chiarito (12 commits)")[![hebabil](https://avatars.githubusercontent.com/u/4658575?v=4)](https://github.com/hebabil "hebabil (4 commits)")[![ChargemapFranck](https://avatars.githubusercontent.com/u/51370562?v=4)](https://github.com/ChargemapFranck "ChargemapFranck (3 commits)")[![ChargemapHakan](https://avatars.githubusercontent.com/u/51368616?v=4)](https://github.com/ChargemapHakan "ChargemapHakan (2 commits)")[![mad-briller](https://avatars.githubusercontent.com/u/28307684?v=4)](https://github.com/mad-briller "mad-briller (1 commits)")[![nieriksson](https://avatars.githubusercontent.com/u/91887329?v=4)](https://github.com/nieriksson "nieriksson (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mrbig-ocpi-protocol/health.svg)

```
[![Health](https://phpackages.com/badges/mrbig-ocpi-protocol/health.svg)](https://phpackages.com/packages/mrbig-ocpi-protocol)
```

###  Alternatives

[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35789.4k2](/packages/telnyx-telnyx-php)[cakephp/cakephp

The CakePHP framework

8.9k19.5M1.8k](/packages/cakephp-cakephp)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M737](/packages/sylius-sylius)[mcp/sdk

Model Context Protocol SDK for Client and Server applications in PHP

1.5k1.5M88](/packages/mcp-sdk)

PHPackages © 2026

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