Last active
March 16, 2018 13:30
-
-
Save lkmadushan/a29c8274fe3614928b1d to your computer and use it in GitHub Desktop.
Remove data key from "thephpleague/fractal" serialize output.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Serializers; | |
use League\Fractal\Serializer\ArraySerializer; | |
class JsonSerializer extends ArraySerializer | |
{ | |
/** | |
* Serialize a collection | |
* | |
* @param string $resourceKey | |
* @param array $data | |
* @return array | |
**/ | |
public function collection($resourceKey, array $data) | |
{ | |
return ($resourceKey && $resourceKey !== 'data') ? array($resourceKey => $data) : $data; | |
} | |
/** | |
* Serialize an item | |
* | |
* @param string $resourceKey | |
* @param array $data | |
* @return array | |
**/ | |
public function item($resourceKey, array $data) | |
{ | |
return ($resourceKey && $resourceKey !== 'data') ? array($resourceKey => $data) : $data; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment