1 | <?php namespace Limoncello\Flute\Schema; |
||
29 | class JsonSchemas implements JsonSchemasInterface |
||
30 | { |
||
31 | use ClassIsTrait; |
||
32 | |||
33 | /** |
||
34 | * @var FactoryInterface |
||
35 | */ |
||
36 | private $factory; |
||
37 | |||
38 | /** |
||
39 | * @var array |
||
40 | */ |
||
41 | private $modelToSchemaMap; |
||
42 | |||
43 | /** |
||
44 | * @var array |
||
45 | */ |
||
46 | private $typeToSchemaMap; |
||
47 | |||
48 | /** |
||
49 | * @var array |
||
50 | */ |
||
51 | private $schemaInstances = []; |
||
52 | |||
53 | /** |
||
54 | * @var ModelSchemaInfoInterface |
||
55 | */ |
||
56 | private $modelSchemas; |
||
57 | |||
58 | /** |
||
59 | * @param FactoryInterface $factory |
||
60 | * @param array $modelToSchemaMap |
||
61 | * @param array $typeToSchemaMap |
||
62 | * @param ModelSchemaInfoInterface $modelSchemas |
||
63 | */ |
||
64 | 56 | public function __construct( |
|
75 | |||
76 | /** |
||
77 | * @inheritdoc |
||
78 | */ |
||
79 | 17 | public function getSchema($resourceObject): JsonSchemaInterface |
|
80 | { |
||
81 | 17 | assert($this->hasSchema($resourceObject)); |
|
82 | |||
83 | 17 | return $this->getSchemaByModelClass($this->getResourceClass($resourceObject)); |
|
84 | } |
||
85 | |||
86 | /** |
||
87 | * @inheritdoc |
||
88 | */ |
||
89 | 17 | public function hasSchema($resourceObject): bool |
|
90 | { |
||
91 | 17 | return is_object($resourceObject) === true && |
|
92 | 17 | array_key_exists($this->getResourceClass($resourceObject), $this->modelToSchemaMap); |
|
93 | } |
||
94 | |||
95 | /** |
||
96 | * @inheritdoc |
||
97 | */ |
||
98 | 5 | public function hasRelationshipSchema(string $schemaClass, string $relationshipName): bool |
|
110 | |||
111 | /** |
||
112 | * @inheritdoc |
||
113 | */ |
||
114 | 20 | public function getRelationshipSchema(string $schemaClass, string $relationshipName): SchemaInterface |
|
125 | |||
126 | /** |
||
127 | * @inheritdoc |
||
128 | */ |
||
129 | 20 | public function getModelRelationshipSchema(string $modelClass, string $relationshipName): SchemaInterface |
|
138 | |||
139 | /** |
||
140 | * @inheritdoc |
||
141 | */ |
||
142 | 25 | public function getSchemaByResourceType(string $resourceType): SchemaInterface |
|
150 | |||
151 | /** |
||
152 | * @return FactoryInterface |
||
153 | */ |
||
154 | 28 | private function getFactory(): FactoryInterface |
|
158 | |||
159 | /** |
||
160 | * @return ModelSchemaInfoInterface |
||
161 | */ |
||
162 | 28 | private function getModelSchemas(): ModelSchemaInfoInterface |
|
166 | |||
167 | /** |
||
168 | * @param mixed $resource |
||
169 | * |
||
170 | * @return string |
||
171 | */ |
||
172 | 17 | private function getResourceClass($resource): string |
|
173 | { |
||
174 | 17 | assert( |
|
175 | 17 | is_object($resource) === true, |
|
176 | 17 | 'Unable to get a type of the resource as it is not an object.' |
|
177 | ); |
||
178 | |||
179 | 17 | return get_class($resource); |
|
180 | } |
||
181 | |||
182 | /** |
||
183 | * @inheritdoc |
||
184 | */ |
||
185 | 22 | private function getSchemaByModelClass(string $modelClass): JsonSchemaInterface |
|
193 | |||
194 | /** |
||
195 | * @param string $schemaClass |
||
196 | * |
||
197 | * @return SchemaInterface |
||
198 | */ |
||
199 | 28 | private function getSchemaByClass(string $schemaClass): JsonSchemaInterface |
|
212 | } |
||
213 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: