1 | <?php |
||
16 | abstract class AbstractResource extends Operator implements ResourceInterface |
||
17 | { |
||
18 | const DEFAULT_MARKER_KEY = 'id'; |
||
19 | |||
20 | /** |
||
21 | * The JSON key that indicates how the API nests singular resources. For example, when |
||
22 | * performing a GET, it could respond with ``{"server": {"id": "12345"}}``. In this case, |
||
23 | * "server" is the resource key, since the essential state of the server is nested inside. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $resourceKey; |
||
28 | |||
29 | /** |
||
30 | * The key that indicates how the API nests resource collections. For example, when |
||
31 | * performing a GET, it could respond with ``{"servers": [{}, {}]}``. In this case, "servers" |
||
32 | * is the resources key, since the array of servers is nested inside. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $resourcesKey; |
||
37 | |||
38 | /** |
||
39 | * Indicates which attribute of the current resource should be used for pagination markers. |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $markerKey; |
||
44 | |||
45 | /** |
||
46 | * An array of aliases that will be checked when the resource is being populated. For example, |
||
47 | * |
||
48 | * 'FOO_BAR' => 'fooBar' |
||
49 | * |
||
50 | * will extract FOO_BAR from the response, and save it as 'fooBar' in the resource. |
||
51 | * |
||
52 | * @var array |
||
53 | */ |
||
54 | protected $aliases = []; |
||
55 | |||
56 | /** |
||
57 | * Populates the current resource from a response object. |
||
58 | * |
||
59 | * @param ResponseInterface $response |
||
60 | * |
||
61 | * @return $this|ResourceInterface |
||
62 | */ |
||
63 | 66 | public function populateFromResponse(ResponseInterface $response) |
|
74 | |||
75 | /** |
||
76 | * Populates the current resource from a data array. |
||
77 | * |
||
78 | * @param array $array |
||
79 | * |
||
80 | * @return mixed|void |
||
81 | */ |
||
82 | 116 | public function populateFromArray(array $array) |
|
98 | |||
99 | 111 | private function parseDocBlockValue($type, $val) |
|
115 | |||
116 | 107 | private function isNotNativeType($type) |
|
122 | |||
123 | 12 | private function normalizeModelClass($class) |
|
132 | |||
133 | 114 | private function extractTypeFromDocBlock(\ReflectionClass $reflClass, $propertyName) |
|
145 | |||
146 | /** |
||
147 | * Internal method which retrieves the values of provided keys. |
||
148 | * |
||
149 | * @param array $keys |
||
150 | * |
||
151 | * @return array |
||
152 | */ |
||
153 | 52 | protected function getAttrs(array $keys) |
|
165 | |||
166 | /** |
||
167 | * @param array $definition |
||
168 | * |
||
169 | * @return mixed |
||
170 | */ |
||
171 | 47 | public function executeWithState(array $definition) |
|
175 | |||
176 | /** |
||
177 | * {@inheritDoc} |
||
178 | */ |
||
179 | 28 | public function enumerate(array $def, array $userVals = [], callable $mapFn = null) |
|
226 | } |
||
227 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.