Skip to content

Commit

Permalink
Merge pull request #234 from quetzyg/fix/json-api-serializer-visibility
Browse files Browse the repository at this point in the history
[RFC] Extending JSON API Serializer
  • Loading branch information
willishq committed Oct 7, 2015
2 parents cd877af + 07875f4 commit 3caeefb
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/Serializer/JsonApiSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use InvalidArgumentException;
use League\Fractal\Resource\ResourceInterface;
use League\Fractal\Resource\ResourceAbstract;

class JsonApiSerializer extends ArraySerializer
{
Expand Down Expand Up @@ -188,7 +187,7 @@ public function filterIncludes($includedData, $data)
*
* @return bool
*/
private function filterRootObject($object)
protected function filterRootObject($object)
{
return !$this->isRootObject($object);
}
Expand All @@ -198,7 +197,7 @@ private function filterRootObject($object)
*
* @param array $objects
*/
private function setRootObjects(array $objects = [])
protected function setRootObjects(array $objects = [])
{
$this->rootObjects = array_map(function($object) {
return "{$object['type']}:{$object['id']}";
Expand All @@ -212,28 +211,28 @@ private function setRootObjects(array $objects = [])
*
* @return bool
*/
private function isRootObject($object)
protected function isRootObject($object)
{
$objectKey = "{$object['type']}:{$object['id']}";
return in_array($objectKey, $this->rootObjects);
}

private function isCollection($data)
protected function isCollection($data)
{
return array_key_exists('data', $data) &&
array_key_exists(0, $data['data']);
}

private function isNull($data)
protected function isNull($data)
{
return array_key_exists('data', $data) && $data['data'] === null;
}

private function isEmpty($data) {
protected function isEmpty($data) {
return array_key_exists('data', $data) && $data['data'] === [];
}

private function fillRelationships($data, $relationships)
protected function fillRelationships($data, $relationships)
{
if ($this->isCollection($data)) {
foreach ($relationships as $key => $relationship) {
Expand All @@ -260,7 +259,7 @@ private function fillRelationships($data, $relationships)
return $data;
}

private function parseRelationships($includedData)
protected function parseRelationships($includedData)
{
$relationships = [];

Expand Down Expand Up @@ -305,7 +304,7 @@ private function parseRelationships($includedData)
return $relationships;
}

private function getIdFromData(array $data)
protected function getIdFromData(array $data)
{
if (!array_key_exists('id', $data)) {
throw new InvalidArgumentException(
Expand All @@ -323,7 +322,7 @@ private function getIdFromData(array $data)
*
* @return array
*/
private function pullOutNestedIncludedData(ResourceInterface $resource, array $data)
protected function pullOutNestedIncludedData(ResourceInterface $resource, array $data)
{
$includedData = [];
$linkedIds = [];
Expand Down Expand Up @@ -353,7 +352,7 @@ private function pullOutNestedIncludedData(ResourceInterface $resource, array $d
*
* @return bool
*/
private function shouldIncludeLinks()
protected function shouldIncludeLinks()
{
return $this->baseUrl !== null;
}
Expand Down

0 comments on commit 3caeefb

Please sign in to comment.