/
FactoryInterface.php
274 lines (253 loc) · 8.43 KB
/
FactoryInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<?php declare(strict_types=1);
namespace Neomerx\JsonApi\Contracts\Factories;
/**
* Copyright 2015-2020 info@neomerx.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use Neomerx\JsonApi\Contracts\Encoder\EncoderInterface;
use Neomerx\JsonApi\Contracts\Http\Headers\AcceptMediaTypeInterface;
use Neomerx\JsonApi\Contracts\Http\Headers\MediaTypeInterface;
use Neomerx\JsonApi\Contracts\Parser\EditableContextInterface;
use Neomerx\JsonApi\Contracts\Parser\IdentifierInterface as ParserIdentifierInterface;
use Neomerx\JsonApi\Contracts\Parser\ParserInterface;
use Neomerx\JsonApi\Contracts\Parser\RelationshipDataInterface;
use Neomerx\JsonApi\Contracts\Parser\RelationshipInterface;
use Neomerx\JsonApi\Contracts\Parser\ResourceInterface;
use Neomerx\JsonApi\Contracts\Representation\DocumentWriterInterface;
use Neomerx\JsonApi\Contracts\Representation\ErrorWriterInterface;
use Neomerx\JsonApi\Contracts\Representation\FieldSetFilterInterface;
use Neomerx\JsonApi\Contracts\Schema\IdentifierInterface as SchemaIdentifierInterface;
use Neomerx\JsonApi\Contracts\Schema\LinkInterface;
use Neomerx\JsonApi\Contracts\Schema\PositionInterface;
use Neomerx\JsonApi\Contracts\Schema\SchemaContainerInterface;
/**
* @package Neomerx\JsonApi
*/
interface FactoryInterface
{
/**
* Create encoder.
*
* @param SchemaContainerInterface $container
*
* @return EncoderInterface
*/
public function createEncoder(SchemaContainerInterface $container): EncoderInterface;
/**
* Create Schema container.
*
* @param iterable $schemas
*
* @return SchemaContainerInterface
*/
public function createSchemaContainer(iterable $schemas): SchemaContainerInterface;
/**
* Create resources parser.
*
* @param SchemaContainerInterface $container
* @param EditableContextInterface $context
*
* @return ParserInterface
*/
public function createParser(
SchemaContainerInterface $container,
EditableContextInterface $context
): ParserInterface;
/**
* Create position for a parsed result.
*
* @param int $level
* @param string $path
* @param null|string $parentType
* @param null|string $parentRelationship
*
* @return PositionInterface
*/
public function createPosition(
int $level,
string $path,
?string $parentType,
?string $parentRelationship
): PositionInterface;
/**
* Create JSON API document writer.
*
* @return DocumentWriterInterface
*/
public function createDocumentWriter(): DocumentWriterInterface;
/**
* Create JSON API error writer.
*
* @return ErrorWriterInterface
*/
public function createErrorWriter(): ErrorWriterInterface;
/**
* Create filter for attributes and relationships.
*
* @param array $fieldSets
*
* @return FieldSetFilterInterface
*/
public function createFieldSetFilter(array $fieldSets): FieldSetFilterInterface;
/**
* Create parsed resource over raw resource data.
*
* @param EditableContextInterface $context
* @param PositionInterface $position
* @param SchemaContainerInterface $container
* @param mixed $data
*
* @return ResourceInterface
*/
public function createParsedResource(
EditableContextInterface $context,
PositionInterface $position,
SchemaContainerInterface $container,
$data
): ResourceInterface;
/**
* Create parsed identifier over raw resource identifier.
*
* @param PositionInterface $position
* @param SchemaIdentifierInterface $identifier
*
* @return ParserIdentifierInterface
*/
public function createParsedIdentifier(
PositionInterface $position,
SchemaIdentifierInterface $identifier
): ParserIdentifierInterface;
/**
* Create link.
*
* @param bool $isSubUrl If value is either full URL or sub-URL.
* @param string $value Either full URL or sub-URL.
* @param bool $hasMeta If links has meta information.
* @param null $meta Value for meta.
*
* @return LinkInterface
*/
public function createLink(bool $isSubUrl, string $value, bool $hasMeta, $meta = null): LinkInterface;
/**
* Create parsed relationship.
*
* @param PositionInterface $position
* @param bool $hasData
* @param RelationshipDataInterface|null $data
* @param bool $hasLinks
* @param iterable|null $links
* @param bool $hasMeta
* @param mixed $meta
*
* @return RelationshipInterface
*/
public function createRelationship(
PositionInterface $position,
bool $hasData,
?RelationshipDataInterface $data,
bool $hasLinks,
?iterable $links,
bool $hasMeta,
$meta
): RelationshipInterface;
/**
* Create relationship that represents resource.
*
* @param SchemaContainerInterface $schemaContainer
* @param EditableContextInterface $context
* @param PositionInterface $position
* @param mixed $resource
*
* @return RelationshipDataInterface
*/
public function createRelationshipDataIsResource(
SchemaContainerInterface $schemaContainer,
EditableContextInterface $context,
PositionInterface $position,
$resource
): RelationshipDataInterface;
/**
* Create relationship that represents identifier.
*
* @param SchemaContainerInterface $schemaContainer
* @param EditableContextInterface $context
* @param PositionInterface $position
* @param SchemaIdentifierInterface $identifier
*
* @return RelationshipDataInterface
*/
public function createRelationshipDataIsIdentifier(
SchemaContainerInterface $schemaContainer,
EditableContextInterface $context,
PositionInterface $position,
SchemaIdentifierInterface $identifier
): RelationshipDataInterface;
/**
* Create relationship that represents collection.
*
* @param SchemaContainerInterface $schemaContainer
* @param EditableContextInterface $context
* @param PositionInterface $position
* @param iterable $resources
*
* @return RelationshipDataInterface
*/
public function createRelationshipDataIsCollection(
SchemaContainerInterface $schemaContainer,
EditableContextInterface $context,
PositionInterface $position,
iterable $resources
): RelationshipDataInterface;
/**
* Create relationship that represents `null`.
*
* @return RelationshipDataInterface
*/
public function createRelationshipDataIsNull(): RelationshipDataInterface;
/**
* Create media type.
*
* @param string $type
* @param string $subType
* @param array<string,string>|null $parameters
*
* @return MediaTypeInterface
*/
public function createMediaType(string $type, string $subType, array $parameters = null): MediaTypeInterface;
/**
* Create media type for Accept HTTP header.
*
* @param int $position
* @param string $type
* @param string $subType
* @param array<string,string>|null $parameters
* @param float $quality
*
* @return AcceptMediaTypeInterface
*/
public function createAcceptMediaType(
int $position,
string $type,
string $subType,
array $parameters = null,
float $quality = 1.0
): AcceptMediaTypeInterface;
/**
* @param array $fieldSets
* @param array $includePaths
*
* @return EditableContextInterface
*/
public function createParserContext(array $fieldSets, array $includePaths): EditableContextInterface;
}