Skip to content

Instantly share code, notes, and snippets.

@mbfisher
Last active August 29, 2015 14:02
Show Gist options
  • Save mbfisher/c766693937e6f0ba6af0 to your computer and use it in GitHub Desktop.
Save mbfisher/c766693937e6f0ba6af0 to your computer and use it in GitHub Desktop.
<?php
require 'vendor/autoload.php';
class Transformer extends League\Fractal\TransformerAbstract
{
protected $availableIncludes = ['child'];
protected $defaultIncludes = ['child'];
public function transform($data)
{
return $data;
}
public function includeChild($data)
{
return $this->item($data['child'], function ($child) {
return $child;
});
}
}
$item = [
'foo' => 'bar',
'child' => []
];
$manager = (new League\Fractal\Manager)->setSerializer(new League\Fractal\Serializer\ArraySerializer);
$resource = new League\Fractal\Resource\Item($item, new Transformer);
$scope = $manager->createData($resource);
echo $scope->toJson();
/**
Output:
{"foo":"bar","child":[]}
Desired:
{"foo":"bar","child":{}}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment