Fractal module for the Lumen PHP framework.
Switch branches/tags
Clone or download
hugovk Remove Gitter badge
We're closing the room. In the future, please ask questions in issues here.
Latest commit f2e70af Mar 16, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Add project files Mar 5, 2016
config Add project files Mar 5, 2016
src Add more tests Nov 21, 2016
tests Apply fixes from StyleCI Nov 29, 2017
.gitignore Update gitignore Apr 8, 2016
.scrutinizer.yml Add .scrutinizer.yml Nov 21, 2016
.styleci.yml Create .styleci.yml Jun 3, 2016
.travis.yml Turn off email notifications entirely Nov 29, 2017
LICENSE Initial commit Mar 5, 2016
README.md Remove Gitter badge Mar 16, 2018
codeception.yml Add code coverage using coveralls Apr 14, 2016
composer.json Add more tests Nov 21, 2016
composer.lock Add more tests Nov 21, 2016

README.md

Lumen Fractal

Build Status Coverage Status Code Climate Scrutinizer Code Quality StyleCI Latest Stable Version Total Downloads License

Fractal module for the Lumen PHP framework.

Requirements

Setup

Installation

Run the following command to install the package through Composer:

composer require nordsoftware/lumen-fractal

Configuration

Copy the configuration template in config/fractal.php to your application's config directory and modify according to your needs. For more information see the Configuration Files section in the Lumen documentation.

Available configuration options:

  • default_serializer - Default serializer to use for serialization, defaults to null

Bootstrap

Add the following lines to bootstrap/app.php:

$app->register('Nord\Lumen\Fractal\FractalServiceProvider');

Optionally you can also use Nord\Lumen\Fractal\FractalMiddleware to parse includes automatically from the request.

$app->middleware([
	.....
	'Nord\Lumen\Fractal\Middleware\FractalMiddleware',
]);

Usage

You can now use Nord\Lumen\Fractal\FractalService to access Fractal anywhere in your application.

Here is a few examples on how you can serialize data if you are using Eloquent:

public function getBook(FractalService $fractal, $id) {
  // load the book model ...

  return response()->json($fractal->item($book, new BookTransformer)->toArray());
}
public function listBooks(FractalService $fractal) {
  // load the book collection ...

  return response()->json($fractal->collection($books, new BookTransformer)->toArray());
}

Contributing

Please read the guidelines.

Running tests

Clone the project and install its dependencies by running:

composer install

Run the following command to run the test suite:

vendor/bin/codecept run unit

License

MIT, see LICENSE.