1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace W2w\Lib\Apie\Core; |
4
|
|
|
|
5
|
|
|
use Psr\Http\Message\RequestInterface; |
6
|
|
|
use W2w\Lib\Apie\Core\Models\ApiResourceFacadeResponse; |
7
|
|
|
use W2w\Lib\Apie\Core\Models\ApiResourceListFacadeResponse; |
8
|
|
|
use W2w\Lib\Apie\Core\SearchFilters\SearchFilterRequest; |
9
|
|
|
use W2w\Lib\Apie\Interfaces\ResourceSerializerInterface; |
10
|
|
|
use W2w\Lib\Apie\PluginInterfaces\ResourceLifeCycleInterface; |
11
|
|
|
|
12
|
|
|
class ApiResourceFacadeResponseFactory |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var ResourceSerializerInterface |
16
|
|
|
*/ |
17
|
|
|
private $serializer; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var ResourceLifeCycleInterface[] |
21
|
|
|
*/ |
22
|
|
|
private $resourceLifeCycles; |
23
|
|
|
|
24
|
|
|
public function __construct( |
25
|
|
|
ResourceSerializerInterface $serializer, |
26
|
|
|
iterable $resourceLifeCycles |
27
|
|
|
) { |
28
|
|
|
$this->serializer = $serializer; |
29
|
|
|
$this->resourceLifeCycles = $resourceLifeCycles; |
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function createResponseForResource($resource, ?RequestInterface $request): ApiResourceFacadeResponse |
33
|
|
|
{ |
34
|
|
|
return new ApiResourceFacadeResponse( |
35
|
|
|
$this->serializer, |
36
|
|
|
$resource, |
37
|
|
|
($request && $request->hasHeader('Accept')) ? $request->getHeader('Accept')[0] : 'application/json', |
38
|
|
|
$this->resourceLifeCycles |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function createResponseListForResource($resource, string $resourceClass, SearchFilterRequest $searchFilter, ?RequestInterface $request): ApiResourceListFacadeResponse |
43
|
|
|
{ |
44
|
|
|
return new ApiResourceListFacadeResponse( |
45
|
|
|
$this->serializer, |
46
|
|
|
$resource, |
47
|
|
|
$resourceClass, |
48
|
|
|
$searchFilter, |
49
|
|
|
($request && $request->hasHeader('Accept')) ? $request->getHeader('Accept')[0] : 'application/json', |
50
|
|
|
$this->resourceLifeCycles |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..