PHP code example of flipboxdigital / relay-transform

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

    

flipboxdigital / relay-transform example snippets



$request = new Zend\Diactoros\Request();
$response = new Zend\Diactoros\Response();

$data = [
    'firstName' => 'foo',
    'lastName' => 'bar',
    'dateCreated' => new \DateTime(),
    'dateUpdated' => new \DateTime()
];

$queue = [
    [
        'class' => Flipbox\Relay\Middleware\Transform\Item::class,
        'data' => $data,
        'transformer' => function($data) {
            return [
                'name' => [
                    'first' => $data['firstName'],
                    'last' => $data['firstName']
                ],
                'date' => [
                    'created' => $data['dateCreated']->format('c'),
                    'updated' => $data['dateUpdated']->format('c')
                ]
            ]
        }
    ]
];

// Relay runner
$runner = new Runner(
    $queue,
    RelayHelper::createResolver()
);

// Relay runner
$runner = new Relay\Runner(
    $queue,
    Flipbox\Relay\Helpers\RelayHelper::createResolver()
);

// Run
$response = $runner($request, $response);