Skip to content
This repository was archived by the owner on Jun 19, 2022. It is now read-only.

Commit 939ce69

Browse files
committed
update serializer
1 parent d2fef84 commit 939ce69

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/Fractal/CustomDataArraySerializer.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,36 @@
44

55
use League\Fractal\Serializer\DataArraySerializer;
66

7-
/**
8-
* To remove "data" on item and null resource.
9-
*/
107
class CustomDataArraySerializer extends DataArraySerializer
118
{
129
/**
13-
* Serialize an item.
14-
*
15-
* @param string $resourceKey
16-
* @param array $data
17-
*
18-
* @return array
10+
* @inheritdoc
11+
*/
12+
public function collection($resourceKey, array $data)
13+
{
14+
if($resourceKey)
15+
{
16+
return [$resourceKey => $data];
17+
}
18+
19+
return $data;
20+
}
21+
22+
/**
23+
* @inheritdoc
1924
*/
2025
public function item($resourceKey, array $data)
2126
{
27+
if($resourceKey)
28+
{
29+
return [$resourceKey => $data];
30+
}
31+
2232
return $data;
2333
}
2434

2535
/**
26-
* Serialize null resource.
27-
*
28-
* @return array
36+
* @inheritdoc
2937
*/
3038
public function null()
3139
{

0 commit comments

Comments
 (0)