1 | <?php declare(strict_types=1); |
||
12 | class Alias |
||
13 | { |
||
14 | /** |
||
15 | * An array of aliases that will be checked when the resource is being populated. For example, |
||
16 | * |
||
17 | * 'CLASS_NAME' => ['FOO_BAR' => 'fooBar'] |
||
18 | * |
||
19 | * will extract FOO_BAR from the response, and save it as 'fooBar' in the resource. |
||
20 | * |
||
21 | * 'CLASS_NAME' => ['FOO_BAR' => ['fooBar', \DateTimeImmutable::class]] |
||
22 | * |
||
23 | * will extract FOO_BAR from the response, and save it as 'fooBar' with type \DateTimeImmutable in the resource. |
||
24 | * |
||
25 | * 'CLASS_NAME' => ['FOO_BAR' => ['fooBar', \DateTimeImmutable::class, true]] |
||
26 | * |
||
27 | * do the same as above plus indicates that target property is a list |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $aliases = []; |
||
32 | |||
33 | /** |
||
34 | * @param ResourceInterface $object |
||
35 | * @param string $key |
||
36 | * @param mixed $value |
||
37 | * |
||
38 | * @return void |
||
39 | */ |
||
40 | public function setObjectProperty(ResourceInterface $object, $key, $value) |
||
51 | |||
52 | /** |
||
53 | * Adds a new alias for class property |
||
54 | * |
||
55 | * @param string $resourceClass |
||
56 | * @param string $alias |
||
57 | * @param string $property |
||
58 | * @param string|null $class |
||
59 | * @param bool $isList |
||
60 | * |
||
61 | * @return $this |
||
62 | */ |
||
63 | public function add($resourceClass, $alias, $property, $class = null, $isList = false) |
||
74 | |||
75 | /** |
||
76 | * Removes an alias(es) for a class |
||
77 | * |
||
78 | * @param string $resourceClass |
||
79 | * @param string|null $alias |
||
80 | * |
||
81 | * @return $this |
||
82 | */ |
||
83 | public function remove($resourceClass, $alias = null) |
||
97 | |||
98 | /** |
||
99 | * Returns |
||
100 | * |
||
101 | * @param string $resourceClass |
||
102 | * |
||
103 | * @return array |
||
104 | */ |
||
105 | public function getAliases($resourceClass) |
||
113 | |||
114 | /** |
||
115 | * Checks whether aliases added for a class or not |
||
116 | * |
||
117 | * @param string $resourceClass |
||
118 | * |
||
119 | * @return bool |
||
120 | */ |
||
121 | public function hasAliases($resourceClass) |
||
125 | |||
126 | /** |
||
127 | * @param ResourceInterface $object |
||
128 | * @param mixed $value |
||
129 | * @param string|false $class |
||
130 | * @param bool $isList |
||
131 | * |
||
132 | * @return mixed |
||
133 | */ |
||
134 | protected function normalizePropertyValue(ResourceInterface $object, $value, $class, $isList) |
||
150 | |||
151 | /** |
||
152 | * @param mixed $object |
||
153 | * |
||
154 | * @return string |
||
155 | */ |
||
156 | private function ensureClassName($object) |
||
160 | } |
||
161 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: