1
|
|
|
<?php namespace Neomerx\JsonApi\Encoder\Serialize; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2015-2017 [email protected] |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
use \Iterator; |
20
|
|
|
use \Neomerx\JsonApi\Exceptions\ErrorCollection; |
21
|
|
|
use \Neomerx\JsonApi\Contracts\Document\ErrorInterface; |
22
|
|
|
use \Neomerx\JsonApi\Contracts\Schema\ContainerInterface as CI; |
23
|
|
|
use \Neomerx\JsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @method CI getContainer() |
27
|
|
|
* @method array encodeDataToArray(CI $container, $data, EncodingParametersInterface $parameters = null) |
28
|
|
|
* @method array encodeIdentifiersToArray($data, EncodingParametersInterface $parameters = null) |
29
|
|
|
* @method array encodeErrorToArray(ErrorInterface $error) |
30
|
|
|
* @method array encodeErrorsToArray($errors) |
31
|
|
|
* @method array encodeMetaToArray($meta) |
32
|
|
|
* |
33
|
|
|
* @package Neomerx\JsonApi |
34
|
|
|
*/ |
35
|
|
|
trait ArraySerializerTrait |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* @param object|array|Iterator|null $data |
39
|
|
|
* @param EncodingParametersInterface|null $parameters |
40
|
|
|
* |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
1 |
|
public function serializeData($data, EncodingParametersInterface $parameters = null) |
44
|
|
|
{ |
45
|
1 |
|
return $this->encodeDataToArray($this->getContainer(), $data, $parameters); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param object|array|Iterator|null $data |
50
|
|
|
* @param EncodingParametersInterface|null $parameters |
51
|
|
|
* |
52
|
|
|
* @return array |
53
|
|
|
*/ |
54
|
1 |
|
public function serializeIdentifiers($data, EncodingParametersInterface $parameters = null) |
55
|
|
|
{ |
56
|
1 |
|
return $this->encodeIdentifiersToArray($data, $parameters); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param ErrorInterface $error |
61
|
|
|
* |
62
|
|
|
* @return array |
63
|
|
|
*/ |
64
|
1 |
|
public function serializeError(ErrorInterface $error) |
65
|
|
|
{ |
66
|
1 |
|
return $this->encodeErrorToArray($error); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param ErrorInterface[]|ErrorCollection $errors |
71
|
|
|
* |
72
|
|
|
* @return array |
73
|
|
|
*/ |
74
|
1 |
|
public function serializeErrors($errors) |
75
|
|
|
{ |
76
|
1 |
|
return $this->encodeErrorsToArray($errors); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param array|object $meta |
81
|
|
|
* |
82
|
|
|
* @return array |
83
|
|
|
*/ |
84
|
1 |
|
public function serializeMeta($meta) |
85
|
|
|
{ |
86
|
1 |
|
return $this->encodeMetaToArray($meta); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.
We recommend to add an additional type check (or disallow null for the parameter):