PHP code example of wandu / restifier

1. Go to this page and download the library: Download wandu/restifier library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wandu / restifier example snippets


$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));

class Restifier {
    public function addTransformer(string $classNameOrInterfaceName, callable $transformer);
    
    public function restify($resource, array $


namespace Wandu\Restifier\Sample;

use Wandu\Restifier\Contracts\Restifiable;

class SampleUserTransformer
{
    public function __invoke(SampleUser $user, Restifiable $restifier, array $r, Restifiable $restifier, array $rn [
            'profile' => $user->profile,
        ];
    }
}