PHPackages                             fourmation/rest-remote-object - 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. fourmation/rest-remote-object

ActiveLibrary[API Development](/categories/api)

fourmation/rest-remote-object
=============================

This library provide a REST adapter for the Remote Object pattern implemented by the ProxyManager project.

1.0.1(12y ago)175.6k2[2 issues](https://github.com/fourmation/RestRemoteObject/issues)1PHP

Since Jan 10Pushed 10y ago4 watchersCompare

[ Source](https://github.com/fourmation/RestRemoteObject)[ Packagist](https://packagist.org/packages/fourmation/rest-remote-object)[ RSS](/packages/fourmation-rest-remote-object/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (11)Versions (5)Used By (1)

Rest Remote Object
==================

[](#rest-remote-object)

This library provide a REST adapter for the [Remote Object pattern](https://github.com/Ocramius/ProxyManager#remote-object) implemented by the [ProxyManager](https://github.com/Ocramius/ProxyManager) project. A REST client is also provided to facilitate the REST interaction.

[![Build Status](https://camo.githubusercontent.com/ab7e66008edab5b0ab950a89e7beb8c2de818efcb36ec63c2513fbab866bd425/68747470733a2f2f6170692e7472617669732d63692e6f72672f666f75726d6174696f6e2f5265737452656d6f74654f626a6563742e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/fourmation/RestRemoteObject)[![Coverage Status](https://camo.githubusercontent.com/f5941e1e2fe537c39303bea9b9c720d5ef990ec947e1a2d6694caf0f42b8b9b9/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f666f75726d6174696f6e2f5265737452656d6f74654f626a6563742f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/fourmation/RestRemoteObject)[![Latest Stable Version](https://camo.githubusercontent.com/1aa28c08d069398df0bf95761c15e11c0b956da51093a0d58830e9d9bffedbfe/68747470733a2f2f706f7365722e707567782e6f72672f666f75726d6174696f6e2f726573742d72656d6f74652d6f626a6563742f762f737461626c652e706e67)](https://packagist.org/packages/fourmation/rest-remote-object)[![Latest Unstable Version](https://camo.githubusercontent.com/44cd0eab892ac502f9af12d4925e3aae1629457e1638f98f0a0107dbff25d17b/68747470733a2f2f706f7365722e707567782e6f72672f666f75726d6174696f6e2f726573742d72656d6f74652d6f626a6563742f762f756e737461626c652e706e67)](https://packagist.org/packages/fourmation/rest-remote-object)

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

[](#installation)

```
php composer.phar require "fourmation/rest-remote-object:1.0.*"
```

Rest remote objects examples
----------------------------

[](#rest-remote-objects-examples)

Some examples are provided in the `examples/` directory : JIRA, ZenDesk, Xero, eWay, FlightStats and AgileZen ! Now, you can transform all REST API in remote objects !

Rest Adapter usages
-------------------

[](#rest-adapter-usages)

A remote object proxy is an object that is located on a different system, but is used as if it was available locally.

To use the REST remote object, add two tags to yours services interfaces : @rest\\http to define the HTTP method to use and @uri to define the resource URI :

```
interface UserServiceInterface
{
    /**
     * @rest\http GET
     * @rest\uri /users/%id
     * @param int $id
     * @return \Models\User
     */
    public function get($id);
}
```

That's all ! You are ready to use your REST API now :

```
use ProxyManager\Factory\RemoteObjectFactory;
use RestRemoteObject\Adapter\Rest as RestAdapter;
use RestRemoteObject\Client\Rest as RestClient;
use RestRemoteObject\Client\Rest\Format\Format;
use RestRemoteObject\Client\Rest\Format\HeaderFormatStrategy;

$client = new RestClient('http://my-company.com/rest');
$client->setFormatStrategy(new HeaderFormatStrategy(new Format(Format::JSON)));

$factory = RemoteObjectFactory(
    new RestAdapter(
        $client
    )
);

// proxy is your remote implementation
$proxy = $factory->createProxy('UserServiceInterface');

$user = $proxy->get(1); // The result is automatically converted to a `\Models\User` class.

var_dump($user->getName()); // 'Vincent'
```

Rest versioning
---------------

[](#rest-versioning)

This project offer three way for the versioning :

- versioning included in a header (recommended)
- versioning included in URL
- versioning included in URL parameter

```
use ProxyManager\Factory\RemoteObjectFactory;
use RestRemoteObject\Adapter\Rest as RestAdapter;
use RestRemoteObject\Client\Rest as RestClient;
use RestRemoteObject\Client\Rest\Format\Format;
use RestRemoteObject\Client\Rest\Format\HeaderFormatStrategy;
use RestRemoteObject\Client\Rest\Versioning\HeaderVersioningStrategy;

$versioning = new HeaderVersioningStrategy('3.0');

$client = new RestClient('http://my-company.com/rest');
$client->setFormatStrategy(new HeaderFormatStrategy(new Format(Format::JSON)));
$client->setVersioningStrategy($versioning);

$factory = new RemoteObjectFactory(
    new RestAdapter(
        $client
    )
);

// proxy is your remote implementation
$proxy = $factory->createProxy('UserServiceInterface');

$user = $proxy->get(1); // A header "Rest-Version: v3" will be added

var_dump($user->getName()); // 'Vincent'
```

Rest authentication
-------------------

[](#rest-authentication)

Three authentication strategy are available :

- Query authentication (recommended)
- HTTP authentication
- simple token

You can easily use an authentication with your REST client :

```
use ProxyManager\Factory\RemoteObjectFactory;
use RestRemoteObject\Adapter\Rest as RestAdapter;
use RestRemoteObject\Client\Rest as RestClient;
use RestRemoteObject\Client\Rest\Authentication\QueryAuthenticationStrategy;
use RestRemoteObject\Client\Rest\Format\Format;
use RestRemoteObject\Client\Rest\Format\HeaderFormatStrategy;

$queryAuth = new QueryAuthenticationStrategy();
$queryAuth->setPublicKey('12345689');
$queryAuth->setPrivateKey('qwerty');

$client = new RestClient('http://my-company.com/rest');
$client->setFormatStrategy(new HeaderFormatStrategy(new Format(Format::JSON)));
$client->setAuthenticationStrategy($queryAuth);

$factory = new RemoteObjectFactory(
    new RestAdapter(
        $client
    )
);

// proxy is your remote implementation
$proxy = $factory->createProxy('UserServiceInterface');

$user = $proxy->get(1); // Your request will be `http://my-company.com/rest/users/1?public_key=12345689&signature=aaa665b46e1060c6b7e5a6b5c891c37312149ece`

var_dump($user->getName()); // 'Vincent'
```

Feature
-------

[](#feature)

To apply feature on your API request, just implement the FeatureInterface and use the `addFeature` method. Example with the timestamp feature :

```
use ProxyManager\Factory\RemoteObjectFactory;
use RestRemoteObject\Adapter\Rest as RestAdapter;
use RestRemoteObject\Client\Rest as RestClient;
use RestRemoteObject\Client\Rest\Feature\Timestamp;
use RestRemoteObject\Client\Rest\Format\Format;
use RestRemoteObject\Client\Rest\Format\HeaderFormatStrategy;

$queryAuth = new QueryAuthenticationStrategy();
$queryAuth->setPublicKey('12345689');
$queryAuth->setPrivateKey('qwerty');

$client = new RestClient('http://my-company.com/rest');
$client->setFormatStrategy(new HeaderFormatStrategy(new Format(Format::JSON)));
$client->addFeature(new TimestampFeature());

$factory = new RemoteObjectFactory(
    new RestAdapter(
        $client
    )
);

// proxy is your remote implementation
$proxy = $factory->createProxy('UserServiceInterface');

$user = $proxy->get(1); // Your request will be `http://my-company.com/rest/locations/1?t=1383881696`

var_dump($user->getName()); // 'Vincent'
```

Custom response parser
----------------------

[](#custom-response-parser)

Two response parser are provided : XML and JSON. The parser is selected automatically based on the response format. You can write your own parser, just implements the `RestRemoteObject\Client\Rest\ResponseHandler\Parser\ParserInterface` interface :

```
interface ParserInterface
{
    /**
     * Parse response content
     *
     * @param $content
     * @return array
     */
    public function parse($content);
}
```

Use your parser like this :

```
use ProxyManager\Factory\RemoteObjectFactory;
use RestRemoteObject\Adapter\Rest as RestAdapter;
use RestRemoteObject\Client\Rest as RestClient;
use RestRemoteObject\Client\Rest\Format\Format;
use RestRemoteObject\Client\Rest\Format\HeaderFormatStrategy;

$client = new RestClient('http://my-company.com/rest');
$client->setFormatStrategy(new HeaderFormatStrategy(new Format(Format::JSON)));

$responseHandler = $client->getResponseHandler();
$responseHandler->getResponseParser(new MyParser()); // create your own logic here

$factory = new RemoteObjectFactory(
    new RestAdapter(
        $client
    )
);

// proxy is your remote implementation
$proxy = $factory->createProxy('UserServiceInterface');

$user = $proxy->get(1);

var_dump($user->getName()); // 'Vincent'
```

Custom response builder
-----------------------

[](#custom-response-builder)

Two standards builder are provided : DefaultBuilder and GhostObjectBuilder.

The DefaultBuilder transform data (provide by the response parser) to an object. By default, the `ClassMethods` hydrator will use, so if you have defined your getter/setter, the object will be built easily.

The second builder is the GhostObjectBuilder which provide a proxy object (by setter/getter such as the DefaultBuilder) instead the real object, and allow remote call from uninitialized properties :

```
use ProxyManager\Factory\RemoteObjectFactory;
use RestRemoteObject\Adapter\Rest as RestAdapter;
use RestRemoteObject\Client\Rest as RestClient;
use RestRemoteObject\Client\Rest\Format\Format;
use RestRemoteObject\Client\Rest\Format\HeaderFormatStrategy;

$client = new RestClient('http://my-company.com/rest');
$client->setFormatStrategy(new HeaderFormatStrategy(new Format(Format::JSON)));

$responseHandler = $client->getResponseHandler();
$responseHandler->setResponseBuilder(new GhostObjectBuilder($this->restClient));

$factory = new RemoteObjectFactory(
    new RestAdapter(
        $client
    )
);

// proxy is your remote implementation
$proxy = $factory->createProxy('UserServiceInterface');

$user = $proxy->get(1);

var_dump($user->getName()); // 'Vincent' -- local data
var_dump($user->getLocations()); // will call remote method !
```

To have remote call, just define your annotations in your model :

```
class User
{
    public function getId()
    {
        return $this->id;
    }

    /**
     * @rest\http GET
     * @rest\uri /locations?user=:getId
     * @rest\mapping setLocations
     * @return \RestRemoteObjectTestAsset\Models\Location[]
     */
    public function getLocations()
    {
        return $this->locations;
    }

    public function setLocations(array $locations)
    {
        $this->locations = $locations;
    }
}
```

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity66

Established project with proven stability

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

Total

4

Last Release

4387d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/205595da798aefe4f9a1f9a6e65555c051f7af291d50cc5acf9284f3a1f1365c?d=identicon)[blanchonvincent](/maintainers/blanchonvincent)

---

Top Contributors

[![blanchonvincent](https://avatars.githubusercontent.com/u/1580512?v=4)](https://github.com/blanchonvincent "blanchonvincent (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/fourmation-rest-remote-object/health.svg)

```
[![Health](https://phpackages.com/badges/fourmation-rest-remote-object/health.svg)](https://phpackages.com/packages/fourmation-rest-remote-object)
```

###  Alternatives

[evandotpro/edp-github

Github API integration module for Zend Framework 2

242.2k](/packages/evandotpro-edp-github)[audeio/spotify-web-api

PHP library for the Spotify Web API

671.1k](/packages/audeio-spotify-web-api)[jacobsteringa/odoo-client

A PHP Client for Odoo

1324.1k](/packages/jacobsteringa-odoo-client)[zfr/zfr-prerender

Integration with prerender.io service

218.1k](/packages/zfr-zfr-prerender)[components-web-app/api-components-bundle

Creates a flexible API for a website's structure, reusable components and common functionality.

323.0k](/packages/components-web-app-api-components-bundle)

PHPackages © 2026

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