PHPackages                             wandu/restifier - 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. wandu/restifier

AbandonedArchivedLibrary[API Development](/categories/api)

wandu/restifier
===============

Restify Data to the RESTFul API Output.

v4.0.0-beta2(8y ago)02.3kMITPHPPHP &gt;=7.0

Since Feb 10Pushed 8y agoCompare

[ Source](https://github.com/Wandu/Restifier)[ Packagist](https://packagist.org/packages/wandu/restifier)[ RSS](/packages/wandu-restifier/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (2)Used By (0)

Wandu Restifier
===============

[](#wandu-restifier)

[![Latest Stable Version](https://camo.githubusercontent.com/be6663b3921e28f1513f4d7694ae2eda66ca55b87bf6877da9c0e258825bcc90/68747470733a2f2f706f7365722e707567782e6f72672f77616e64752f7265737469666965722f762f737461626c652e737667)](https://packagist.org/packages/wandu/restifier)[![Latest Unstable Version](https://camo.githubusercontent.com/55855a2bb3d15ef2972034b6066cf11bed1a7acc9c1cbb3339c140040d753c2e/68747470733a2f2f706f7365722e707567782e6f72672f77616e64752f7265737469666965722f762f756e737461626c652e737667)](https://packagist.org/packages/wandu/restifier)[![Total Downloads](https://camo.githubusercontent.com/0e08d6ad305779c3e304ce7f07ac26ec4384191cd7c91960418337a809ba8fcc/68747470733a2f2f706f7365722e707567782e6f72672f77616e64752f7265737469666965722f646f776e6c6f6164732e737667)](https://packagist.org/packages/wandu/restifier)[![License](https://camo.githubusercontent.com/27346252f2d3cb7e7c285ef3969ed9bb26bfc14bf02a4eb0ac0a55d94c4513f8/68747470733a2f2f706f7365722e707567782e6f72672f77616e64752f7265737469666965722f6c6963656e73652e737667)](https://packagist.org/packages/wandu/restifier)

Transform Data to the RESTFul API Output.

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

[](#installation)

`composer require wandu/restifier`

Documentation
-------------

[](#documentation)

**Example**

```
$restifier = new Restifier();
$restifier->addTransformer(SampleUser::class, new SampleUserTransformer());
$restifier->addTransformer(SampleCustomer::class, new SampleCustomerTransformer());

$user = new SampleUser([
    'username' => 'wan2land',
    'customer' => new SampleCustomer([
        'address' => 'seoul blabla',
        'paymentmethods' => [], // critical data
    ]),
]);

static::assertEquals([
    "username" => "wan2land",
    'customer' => [
        'address' => 'seoul blabla',
    ],
], $restifier->restify($user));
```

**Restifier**

```
class Restifier {
    public function addTransformer(string $classNameOrInterfaceName, callable $transformer);

    public function restify($resource, array $includes = [], callable $transformer = null): array|null

    public function restifyMany($resource, array $includes = [], callable $transformer = null): array
}
```

### Transformer

[](#transformer)

Transformer is callable. It is recommended to use the callable class that contain `__invoke` method.

**Example**

```
