Skip to content

Commit

Permalink
Updating default serializer to allow for empty and custom resource keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
joshforbes committed Jan 20, 2016
1 parent 489d0ff commit 44a47f3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Serializers/DataArraySerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace NavJobs\Transmit\Serializers;

use League\Fractal\Resource\ResourceInterface;
use League\Fractal\Serializer\ArraySerializer as BaseArraySerializer;

class DataArraySerializer extends BaseArraySerializer
Expand All @@ -16,7 +17,11 @@ class DataArraySerializer extends BaseArraySerializer
*/
public function collection($resourceKey, array $data)
{
return ['data' => $data];
if ($resourceKey === false) {
return $data;
}

return $resourceKey ? [$resourceKey => $data] : ['data' => $data];
}

/**
Expand All @@ -29,7 +34,11 @@ public function collection($resourceKey, array $data)
*/
public function item($resourceKey, array $data)
{
return ['data' => $data];
if ($resourceKey === false) {
return $data;
}

return $resourceKey ? [$resourceKey => $data] : ['data' => $data];
}

/**
Expand Down

0 comments on commit 44a47f3

Please sign in to comment.