1 | <?php namespace Neomerx\JsonApi\Factories; |
||
70 | class Factory implements FactoryInterface |
||
71 | { |
||
72 | /** |
||
73 | * @var LoggerInterface |
||
74 | */ |
||
75 | protected $logger; |
||
76 | |||
77 | /** |
||
78 | * Constructor. |
||
79 | */ |
||
80 | 173 | public function __construct() |
|
84 | |||
85 | /** |
||
86 | * @inheritdoc |
||
87 | */ |
||
88 | 2 | public function setLogger(LoggerInterface $logger) |
|
92 | |||
93 | /** |
||
94 | * @inheritdoc |
||
95 | */ |
||
96 | 64 | public function createEncoder(ContainerInterface $container, EncoderOptions $encoderOptions = null) |
|
104 | |||
105 | /** |
||
106 | * @inheritdoc |
||
107 | */ |
||
108 | 92 | public function createDocument() |
|
116 | |||
117 | /** |
||
118 | * @inheritdoc |
||
119 | */ |
||
120 | 3 | public function createError( |
|
132 | /** |
||
133 | * @inheritdoc |
||
134 | */ |
||
135 | 54 | public function createReply($replyType, StackReadOnlyInterface $stack) |
|
139 | |||
140 | /** |
||
141 | * @inheritdoc |
||
142 | */ |
||
143 | 21 | public function createEmptyReply( |
|
149 | |||
150 | /** |
||
151 | * @inheritdoc |
||
152 | */ |
||
153 | 60 | public function createParser(ContainerInterface $container, ParserManagerInterface $manager) |
|
161 | |||
162 | /** |
||
163 | * @inheritdoc |
||
164 | */ |
||
165 | 58 | public function createManager(ParametersAnalyzerInterface $parameterAnalyzer) |
|
173 | |||
174 | /** |
||
175 | * @inheritdoc |
||
176 | */ |
||
177 | 63 | public function createFrame(StackFrameReadOnlyInterface $previous = null) |
|
181 | |||
182 | /** |
||
183 | * @inheritdoc |
||
184 | */ |
||
185 | 64 | public function createStack() |
|
189 | |||
190 | /** |
||
191 | * @inheritdoc |
||
192 | */ |
||
193 | 58 | public function createReplyInterpreter(DocumentInterface $document, ParametersAnalyzerInterface $parameterAnalyzer) |
|
201 | |||
202 | /** |
||
203 | * @inheritdoc |
||
204 | */ |
||
205 | 61 | public function createParametersAnalyzer(EncodingParametersInterface $parameters, ContainerInterface $container) |
|
213 | |||
214 | /** |
||
215 | * @inheritdoc |
||
216 | */ |
||
217 | 1 | public function createMediaType($type, $subType, $parameters = null) |
|
221 | |||
222 | /** |
||
223 | * @inheritdoc |
||
224 | */ |
||
225 | 60 | public function createQueryParameters( |
|
242 | |||
243 | /** |
||
244 | * @inheritdoc |
||
245 | */ |
||
246 | 10 | public function createHeaderParameters($method, AcceptHeaderInterface $accept, HeaderInterface $contentType) |
|
250 | |||
251 | /** |
||
252 | * @inheritdoc |
||
253 | */ |
||
254 | 23 | public function createQueryParametersParser() |
|
262 | |||
263 | /** |
||
264 | * @inheritdoc |
||
265 | */ |
||
266 | 12 | public function createHeaderParametersParser() |
|
274 | |||
275 | /** |
||
276 | * @inheritdoc |
||
277 | */ |
||
278 | 14 | public function createSortParam($sortField, $isAscending) |
|
282 | |||
283 | /** |
||
284 | * @inheritdoc |
||
285 | */ |
||
286 | 1 | public function createSupportedExtensions($extensions = MediaTypeInterface::NO_EXT) |
|
290 | |||
291 | /** |
||
292 | * @inheritdoc |
||
293 | */ |
||
294 | 2 | public function createAcceptMediaType( |
|
304 | |||
305 | /** |
||
306 | * @inheritdoc |
||
307 | */ |
||
308 | 2 | public function createAcceptHeader($unsortedMediaTypes) |
|
312 | |||
313 | /** |
||
314 | * @inheritdoc |
||
315 | */ |
||
316 | 6 | public function createHeadersChecker(CodecMatcherInterface $codecMatcher) |
|
320 | |||
321 | /** |
||
322 | * @inheritdoc |
||
323 | */ |
||
324 | 12 | public function createQueryChecker( |
|
341 | |||
342 | /** |
||
343 | * @inheritdoc |
||
344 | */ |
||
345 | 77 | public function createContainer(array $providers = []) |
|
353 | |||
354 | /** |
||
355 | * @inheritdoc |
||
356 | */ |
||
357 | 75 | public function createResourceObject( |
|
365 | |||
366 | /** |
||
367 | * @inheritdoc |
||
368 | */ |
||
369 | 75 | public function createRelationshipObject($name, $data, $links, $meta, $isShowData, $isRoot) |
|
373 | |||
374 | /** |
||
375 | * @inheritdoc |
||
376 | */ |
||
377 | 52 | public function createLink($subHref, $meta = null, $treatAsHref = false) |
|
381 | |||
382 | /** |
||
383 | * @inheritdoc |
||
384 | */ |
||
385 | 2 | public function createResourceIdentifierSchemaAdapter(SchemaProviderInterface $schema) |
|
389 | |||
390 | /** |
||
391 | * @inheritdoc |
||
392 | */ |
||
393 | 2 | public function createResourceIdentifierContainerAdapter(ContainerInterface $container) |
|
397 | |||
398 | /** |
||
399 | * @inheritdoc |
||
400 | */ |
||
401 | 1 | public function createIdentitySchema(ContainerInterface $container, $classType, Closure $identityClosure) |
|
405 | |||
406 | /** |
||
407 | * @inheritdoc |
||
408 | */ |
||
409 | 18 | public function createCodecMatcher() |
|
413 | } |
||
414 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: