2017 © Pedro Peláez
 

library restifier

Restify Data to the RESTFul API Output.

image

wandu/restifier

Restify Data to the RESTFul API Output.

  • Tuesday, February 13, 2018
  • by wan2land
  • Repository
  • 0 Watchers
  • 0 Stars
  • 24 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 4 % Grown

The README.md

Wandu Restifier

Latest Stable Version Latest Unstable Version Total Downloads License, (*1)

Transform Data to the RESTFul API Output., (*2)

Installation

composer require wandu/restifier, (*3)

Documentation

Example, (*4)

$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, (*5)

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 is callable. It is recommended to use the callable class that contain __invoke method., (*6)

Example, (*7)

<?php
namespace Wandu\Restifier\Sample;

use Wandu\Restifier\Contracts\Restifiable;

class SampleUserTransformer
{
    public function __invoke(SampleUser $user, Restifiable $restifier, array $includes = [])
    {
        return [
            'username' => $user->username,
            'customer' => $restifier->restify($user->customer),
        ];
    }

    public function customer(SampleUser $user, Restifiable $restifier, array $includes = [])
    {
        return [
            'customer' => $restifier->restify($user->customer, $includes),
        ];
    }

    public function profile(SampleUser $user, Restifiable $restifier, array $includes = [])
    {
        return [
            'profile' => $user->profile,
        ];
    }
}

The Versions

13/02 2018

dev-master

9999999-dev

Restify Data to the RESTFul API Output.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

wandu restifier

10/02 2018

v4.0.0-beta2

4.0.0.0-beta2

Restify Data to the RESTFul API Output.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

wandu restifier