PHP code example of quibble / transformer

1. Go to this page and download the library: Download quibble/transformer 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/ */

    

quibble / transformer example snippets




use Quibble\Transformer\Transformer;

$transformer = new Transformer;

$results = $statement->fetchAll();
$results = $transformer->collection($results, function () {});

$result = $statement->fetch();
$result = $transformer->resource($result, function () {});




$result = $transformer->resource($result, function (int $id, bool $active) {});




use Carbon\Carbon;

$result = $transformer->resource($result, function (Carbon $datecreated) {});




$result = $transformer->resource($result, function () : stdClass {});
$result typeof stdClass; // true




use Carbon\Carbon;

interface MySchema
{
    public function foo(int $id, Carbon $datecreated) : MyAwesomeModel;
    // A return type of array is actually the default.
    public function bar(int $id, bool $valid) : array;
}

$fooResult = $transformer->resource($fooResult, [MySchema::class, 'foo']);
$barResult = $transformer->resource($barResult, [MySchema::class, 'bar']);