flipboxdigital/relay-transform

Transform Middleware for Relay

1.0.0 2017-06-06 04:04 UTC

This package is auto-updated.

Last update: 2024-10-09 14:21:43 UTC


README

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

This package provides a Transform Middleware leveraging Transform and Stash.

Installation

To install, use composer:

composer require flipboxdigital/relay-transform

Testing

$ ./vendor/bin/phpunit

Usage

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

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.