|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the reva2/jsonapi. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Sergey Revenko <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
namespace Reva2\JsonApi\Http; |
|
13
|
|
|
|
|
14
|
|
|
use Neomerx\JsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface; |
|
15
|
|
|
use Neomerx\JsonApi\Contracts\Schema\ContainerInterface; |
|
16
|
|
|
use Neomerx\JsonApi\Http\Responses; |
|
17
|
|
|
use Reva2\JsonApi\Contracts\Services\EnvironmentInterface; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* JSON API response factory |
|
22
|
|
|
* |
|
23
|
|
|
* @package Reva2\JsonApi\Http |
|
24
|
|
|
* @author Sergey Revenko <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class ResponseFactory extends Responses |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var ContainerInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $schemas; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var EnvironmentInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $environment; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var EncodingParametersInterface |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $params; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Constructor |
|
45
|
|
|
* |
|
46
|
|
|
* @param ContainerInterface $schemas |
|
47
|
|
|
* @param EnvironmentInterface $environment |
|
48
|
|
|
* @param EncodingParametersInterface|null $params |
|
49
|
|
|
*/ |
|
50
|
2 |
|
public function __construct( |
|
51
|
|
|
ContainerInterface $schemas, |
|
52
|
|
|
EnvironmentInterface $environment, |
|
53
|
|
|
EncodingParametersInterface $params = null |
|
54
|
|
|
) { |
|
55
|
2 |
|
$this->schemas = $schemas; |
|
56
|
2 |
|
$this->environment = $environment; |
|
57
|
2 |
|
$this->params = $params; |
|
58
|
2 |
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @inheritdoc |
|
62
|
|
|
*/ |
|
63
|
2 |
|
protected function createResponse($content, $statusCode, array $headers) |
|
64
|
|
|
{ |
|
65
|
2 |
|
return new Response($content, $statusCode, $headers); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @inheritdoc |
|
70
|
|
|
*/ |
|
71
|
1 |
|
protected function getEncoder() |
|
72
|
|
|
{ |
|
73
|
1 |
|
return $this->environment->getEncoder(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @inheritdoc |
|
78
|
|
|
*/ |
|
79
|
|
|
protected function getUrlPrefix() |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->environment->getUrlPrefix(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @inheritdoc |
|
86
|
|
|
*/ |
|
87
|
1 |
|
protected function getEncodingParameters() |
|
88
|
|
|
{ |
|
89
|
1 |
|
return $this->params; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @inheritdoc |
|
94
|
|
|
*/ |
|
95
|
|
|
protected function getSchemaContainer() |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->schemas; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @inheritdoc |
|
102
|
|
|
*/ |
|
103
|
2 |
|
protected function getSupportedExtensions() |
|
104
|
|
|
{ |
|
105
|
2 |
|
return null; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @inheritdoc |
|
110
|
|
|
*/ |
|
111
|
2 |
|
protected function getMediaType() |
|
112
|
|
|
{ |
|
113
|
2 |
|
return $this->environment->getEncoderMediaType(); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|