PHPackages                             ivan-novakov/php-perun-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. [HTTP &amp; Networking](/categories/http)
4. /
5. ivan-novakov/php-perun-api

AbandonedArchivedLibrary[HTTP &amp; Networking](/categories/http)

ivan-novakov/php-perun-api
==========================

A PHP client library to consume Perun REST API

0.1.3(12y ago)3254[1 issues](https://github.com/ivan-novakov/php-perun-api/issues)BSD-3-ClausePHPPHP &gt;=5.3.3

Since Dec 9Pushed 12y ago1 watchersCompare

[ Source](https://github.com/ivan-novakov/php-perun-api)[ Packagist](https://packagist.org/packages/ivan-novakov/php-perun-api)[ Docs](https://github.com/ivan-novakov/php-perun-api)[ RSS](/packages/ivan-novakov-php-perun-api/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)Dependencies (5)Versions (5)Used By (0)

PHP Perun API
=============

[](#php-perun-api)

[![Dependency Status](https://camo.githubusercontent.com/097120a8137ba521f6a8301a9ab00f1d8d07f4f8cb6e4a71187fbc55668b07d8/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3532396130313361363332626163626362393030303030322f62616467652e706e67)](https://www.versioneye.com/user/projects/529a013a632bacbcb9000002)

A client library written in PHP to consume [Perun](http://perun.metacentrum.cz/web/index.shtml) REST API.

[Perun](http://perun.metacentrum.cz/web/index.shtml) is a content management system that handles user identities, groups, resources and services. It is currently developed by [CESNET](http://www.ces.net/), [CERIT-SC](http://www.cerit-sc.cz/en/) together with students from [Masaryk University in Brno](http://www.muni.cz/).

Intro
-----

[](#intro)

This software is being developed as a part of the Shongo Project initiated by [CESNET, a. l. e.](http://www.ces.net/).

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

[](#requirements)

- PHP &gt;= 5.3.3
- cURL PHP extension

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

[](#installation)

### With Composer

[](#with-composer)

To install the library through [composer](http://getcomposer.org/), add the following requirement to your `composer.json` file:

```
"require": {
    "ivan-novakov/php-perun-api": "~0.1"
}

```

And run `composer install/update`.

### Without composer

[](#without-composer)

Just clone the repository and make sure, that your autoloader is properly set to search for the `InoPerunApi` namespace in the project's `src` directory.

Usage
-----

[](#usage)

Perun client configuration consists of several basic sections. The `client` section is used for general configuration such as the `url` of the Perun API instance. The `http_client` section configures the standard HTTP client object from Zend Framework 2. The `authenticator` section configures the client authentication of the HTTP requests.

```
    $clientConfig = array(

        'client' => array(
            'url' => 'https://api.example.org/rest'
        ),

        'http_client' => array(
            'adapter' => 'Zend\Http\Client\Adapter\Curl',
            'useragent' => 'Perun Client',
            'curloptions' => array(
                CURLOPT_SSL_VERIFYPEER => true,
                CURLOPT_SSL_VERIFYHOST => 2,
                CURLOPT_CAINFO => '/etc/ssl/certs/ca-bundle.pem'
            )
        ),

        'authenticator' => array(
            'class' => 'InoPerunApi\Client\Authenticator\ClientCertificate',
            'options' => array(
                'key_file' => '/tmp/key.pem',
                'crt_file' => '/tmp/crt.pem',
                'key_pass' => 'secret'
            )
        )
    );
```

Once the we have the configuration, we can initialize the client:

```
    use InoPerunApi\Client\ClientFactory;

    $clientConfig = array(...);

    $clientFactory = new ClientFactory();
    $client = $clientFactory->createClient($config);
```

After that, we can send requests to the remote API. For each Perun entity, there is a dedicated "manager" object, which can handle calls specific to the corresponding entity. For example, to get the user by its ID, we need to call the `getUserById` method of the `usersManager`. Any method arguments we need to pass should be included in the third argument of the `sendRequest` call:

```
    try {
        $perunResponse = $client->sendRequest('usersManager', 'getUserById', array(
            'id' => 1234
        ));
    } catch (\Exception $e) {
        // handle exception
    }
```

If there are problems while connecting to the remote API or if the response cannot be parsed properly, an exception will be thrown. Otherwise, we still need to check, if the request was successful:

```
    if ($perunResponse->isError()) {
        printf("Perun error [%s]: %s (%s)\n", $perunResponse->getErrorId(),
            $perunResponse->getErrorType(), $perunResponse->getErrorMessage());
    }
```

If there is no error, we can access the response through the `Payload` object:

```
    $payload = $perunResponse->getPayload();
    printf("User: %s %s\n", $payload->getParam('firstName'), $payload->getParam('lastName));
```

Advanced usage (experimental)
-----------------------------

[](#advanced-usage-experimental)

The library may be used in a more intuitive way, which tries to "hide" the fact, that we are calling a remote API. The library tries to "mimic" the remote manager and entity objects:

```
    $usersManager = new GenericManager($client);
    $usersManager->setManagerName('usersManager');

    $user = $usersManager->getUserById(array(
        'user' => 1234
    ));

    printf("User: %s %s\n", $user->getFirstName(), $user->getLastName());
```

We instantiate a "manager" object and pass a client object instance to its constructor. When we call a method on this object, it is caught by the magic `__call()` method and a client request is constructed and dispatched. If the call was succesful, the `User` entity is populated with data and returned.

License
-------

[](#license)

- [BSD 3 Clause](http://debug.cz/license/bsd-3-clause)

Links
-----

[](#links)

- [The Perun Project](http://perun.metacentrum.cz/web/index.shtml)
- [CESNET](http://www.ces.net/)

Author
------

[](#author)

- [Ivan Novakov](http://novakov.cz/)

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~40 days

Total

4

Last Release

4466d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1208505?v=4)[Ivan Novakov](/maintainers/ivan-novakov)[@ivan-novakov](https://github.com/ivan-novakov)

---

Top Contributors

[![ivan-novakov](https://avatars.githubusercontent.com/u/1208505?v=4)](https://github.com/ivan-novakov "ivan-novakov (88 commits)")

---

Tags

phpapirestperun

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ivan-novakov-php-perun-api/health.svg)

```
[![Health](https://phpackages.com/badges/ivan-novakov-php-perun-api/health.svg)](https://phpackages.com/packages/ivan-novakov-php-perun-api)
```

PHPackages © 2026

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