for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php namespace League\Fractal\Test\Stub\Transformer;
use League\Fractal\TransformerAbstract;
class JsonApiBookTransformer extends TransformerAbstract
{
protected $availableIncludes = [
'author',
'co-author',
];
public function transform(array $book)
$book['year'] = (int) $book['year'];
unset($book['_author']);
unset($book['_co_author']);
return $book;
}
public function includeAuthor(array $book)
if (!array_key_exists('_author', $book)) {
return;
if ($book['_author'] === null) {
return $this->null();
return $this->item($book['_author'], new JsonApiAuthorTransformer(), 'people');
public function includeCoAuthor(array $book)
if (!array_key_exists('_co_author', $book)) {
if ($book['_co_author'] === null) {
return $this->item($book['_co_author'], new JsonApiAuthorTransformer(), 'people');