2017 © Pedro Peláez
 

library rka-content-type-renderer

Render an array to a JSON/XML/HTML PSR-7 Response based on a PSR-7 Request's Accept header.

image

akrabat/rka-content-type-renderer

Render an array to a JSON/XML/HTML PSR-7 Response based on a PSR-7 Request's Accept header.

  • Sunday, March 4, 2018
  • by akrabat
  • Repository
  • 4 Watchers
  • 34 Stars
  • 7,704 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 10 Forks
  • 2 Open issues
  • 18 Versions
  • 21 % Grown

The README.md

Render output based on content-type

Render an array (or HAL object) to a JSON/XML/HTML PSR-7 Response based on a PSR-7 Request's Accept header., (*1)

![Build status][Master image], (*2)

Installation

composer require akrabat/rka-content-type-renderer, (*3)

Usage

// given:
// $request instanceof Psr\Http\Message\RequestInterface
// $response instanceof Psr\Http\Message\ResponseInterface

$data = [
    'items' => [
        [
            'name' => 'Alex',
            'is_admin' => true,
        ],
        [
            'name' => 'Robin',
            'is_admin' => false,
        ],
    ],
];
$renderer = new RKA\ContentTypeRenderer\Renderer();
$response  = $renderer->render($request, $response, $data);
return $response->withStatus(200);

The constructor takes a parameter, $pretty that defaults to true. Set to false to disable pretty printing., (*4)

HalRenderer

This component also supports nocarrier/hal objects with the HalRenderer:, (*5)

$hal = new Nocarrier\Hal(
    '/foo',
    [
        'items' => [
            [
                'name' => 'Alex',
                'is_admin' => true,
            ],
            [
                'name' => 'Robin',
                'is_admin' => false,
            ],
        ],
    ]
);
$renderer = new RKA\ContentTypeRenderer\HalRenderer();
$response  = $renderer->render($request, $response, $hal);
return $response->withStatus(200);

ApiRenderer

This component also supports crell/ApiProblem objects with the ApiProblemRenderer:, (*6)

$problem = new Crell\ApiProblem("Something unexpected happened");
$renderer = new RKA\ContentTypeRenderer\ApiProblemRenderer();
$response  = $renderer->render($request, $response, $problem);
return $response->withStatus(500);

Arrays of objects

If you have an array of objects, then the renderer will still work as long as the objects implement PHP's JsonSerializable interface., (*7)

Testing

  • Code style: $ phpcs
  • Unit tests: $ phpunit
  • Code coverage: $ phpunit --coverage-html ./build

The Versions

04/03 2018

dev-master

9999999-dev http://github.com/akrabat/rka-content-type-renderer

Render an array to a JSON/XML/HTML PSR-7 Response based on a PSR-7 Request's Accept header.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

json xml psr7

04/03 2018
03/03 2018

dev-travis-update

dev-travis-update http://github.com/akrabat/rka-content-type-renderer

Render an array to a JSON/XML/HTML PSR-7 Response based on a PSR-7 Request's Accept header.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

json xml psr7

03/03 2018

dev-optional-pretty-print

dev-optional-pretty-print http://github.com/akrabat/rka-content-type-renderer

Render an array to a JSON/XML/HTML PSR-7 Response based on a PSR-7 Request's Accept header.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

json xml psr7

28/01 2017
28/01 2017
26/01 2017
24/01 2017
23/01 2017

0.6.0

0.6.0.0 http://github.com/akrabat/rka-content-type-renderer

Render an array to a JSON/XML/HTML PSR-7 Response based on a PSR-7 Request's Accept header.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

json xml psr7

13/11 2016

0.5.0

0.5.0.0 http://github.com/akrabat/rka-content-type-renderer

Render an array to a JSON/XML/HTML PSR-7 Response based on a PSR-7 Request's Accept header.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

json xml psr7

22/10 2015

0.4.0

0.4.0.0 http://github.com/akrabat/rka-content-type-renderer

Render an array to a JSON/XML/HTML PSR-7 Response based on a PSR-7 Request's Accept header.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

json xml psr7

18/10 2015

dev-willdurand-negotiation

dev-willdurand-negotiation http://github.com/akrabat/rka-content-type-renderer

Render an array to a JSON/XML/HTML PSR-7 Response based on a PSR-7 Request's Accept header.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

json xml psr7

18/10 2015

0.3.3

0.3.3.0 http://github.com/akrabat/rka-content-type-renderer

Render an array to a JSON/XML/HTML PSR-7 Response based on a PSR-7 Request's Accept header.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

json xml psr7

17/10 2015

0.3.2

0.3.2.0 http://github.com/akrabat/rka-content-type-renderer

Render an array to a JSON/XML/HTML PSR-7 Response based on a PSR-7 Request's Accept header.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

json xml psr7

17/10 2015

0.3.1

0.3.1.0 http://github.com/akrabat/rka-content-type-renderer

Render an array to a JSON/XML/HTML PSR-7 Response based on a PSR-7 Request's Accept header.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

json xml psr7

12/10 2015

0.3

0.3.0.0 http://github.com/akrabat/rka-content-type-renderer

Render an array to a JSON/XML/HTML PSR-7 Response based on a PSR-7 Request's Accept header.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

json xml psr7

12/10 2015

0.2

0.2.0.0 http://github.com/akrabat/rka-content-type-renderer

Render an array to a JSON/XML/HTML PSR-7 Response based on a PSR-7 Request's Accept header.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

json xml psr7

12/10 2015

0.1

0.1.0.0 http://github.com/akrabat/rka-content-type-renderer

Render an array to a JSON/XML/HTML PSR-7 Response based on a PSR-7 Request's Accept header.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

json xml psr7