embergrep/fractal-ember

A set of serializers for building Ember ready APIs using Fractal

0.1.0 2015-09-24 14:49 UTC

This package is not auto-updated.

Last update: 2024-03-16 12:44:00 UTC


README

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

This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.

Install

Via Composer

$ composer require embergrep/fractal-ember

Usage

use Acme\Model\Book;
use Acme\Transformer\BookTransformer;
use League\Fractal\Manager;
use League\Fractal\Resource\Item;
use Embergrep\Serializers\EmberSerializer;

$manager = new Manager();
$manager->setSerializer(new EmberSerializer());

// Some sort of ORM call
$book = Book::find(1);

// Make a resource out of the data and
$resource = new Item($book, new BookTransformer(), 'book');

// Run all transformers
$manager->createData($resource)->toArray();

// Outputs:
// [
//     'book' => [
//         'id' => 'Foo',
//         'title' => 'Foo',
//         'year' => 1991,
//     ],
//     'authors' => [
//         [
//             'id' => 'Baz',
//             'name' => 'Walter',
//     ],
// ];

Testing

$ phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

License

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