-
Notifications
You must be signed in to change notification settings - Fork 66
/
EncoderInterface.php
226 lines (204 loc) · 5.59 KB
/
EncoderInterface.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
<?php declare(strict_types=1);
namespace Neomerx\JsonApi\Contracts\Encoder;
/**
* Copyright 2015-2020 [email protected]
*
* 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\Schema\ErrorInterface;
use Neomerx\JsonApi\Contracts\Schema\LinkInterface;
use Neomerx\JsonApi\Contracts\Schema\LinkWithAliasesInterface;
/**
* @package Neomerx\JsonApi
*/
interface EncoderInterface
{
/** JSON API version implemented by the encoder */
const JSON_API_VERSION = '1.1';
/**
* This prefix will be used for URL links while encoding.
*
* @param string $prefix
*
* @return self
*/
public function withUrlPrefix(string $prefix): self;
/**
* Include specified paths to the output. Paths should be separated with a dot symbol.
*
* Format
* [
* 'relationship1',
* 'relationship1.sub-relationship2',
* ]
*
* @param iterable $paths
*
* @return self
*/
public function withIncludedPaths(iterable $paths): self;
/**
* Limit fields in the output result.
*
* Format
* [
* 'type1' => ['attribute1', 'attribute2', 'relationship1', ...]
* 'type2' => [] // no fields in output, only type and id.
*
* // 'type3' is not on the list so all its attributes and relationships will be in output.
* ]
*
* @param array $fieldSets
*
* @return self
*/
public function withFieldSets(array $fieldSets): self;
/**
* Set JSON encode options.
*
* @link http://php.net/manual/en/function.json-encode.php
*
* @param int $options
*
* @return self
*/
public function withEncodeOptions(int $options): self;
/**
* Set JSON encode depth.
*
* @link http://php.net/manual/en/function.json-encode.php
*
* @param int $depth
*
* @return self
*/
public function withEncodeDepth(int $depth): self;
/**
* Add links that will be encoded with data. Links must be in `$name => $link, ...` format.
*
* @param array $links
*
* @see LinkInterface
*
* @return self
*/
public function withLinks(array $links): self;
/**
* Add profile links that will be encoded with data. Links must be in `$link1, $link2, ...` format.
*
* @param iterable $links
*
* @see LinkWithAliasesInterface
*
* @return self
*/
public function withProfile(iterable $links): self;
/**
* Add meta information that will be encoded with data. If 'null' meta will not appear in a document.
*
* @param mixed|null $meta
*
* @return self
*/
public function withMeta($meta): self;
/**
* If called JSON API version information will be added to a document.
*
* @param string $version
*
* @return self
*
* @see http://jsonapi.org/format/#document-jsonapi-object
*/
public function withJsonApiVersion(string $version): self;
/**
* If called JSON API version meta will be added to a document.
*
* @param mixed $meta
*
* @return self
*
* @see http://jsonapi.org/format/#document-jsonapi-object
*/
public function withJsonApiMeta($meta): self;
/**
* Add 'self' Link to top-level document's 'links' section for relationship specified.
*
* @param object $resource
* @param string $relationshipName
*
* @see http://jsonapi.org/format/#fetching-relationships
*
* @return self
*/
public function withRelationshipSelfLink($resource, string $relationshipName): self;
/**
* Add 'related' Link to top-level document's 'links' section for relationship specified.
*
* @param object $resource
* @param string $relationshipName
*
* @see http://jsonapi.org/format/#fetching-relationships
*
* @return self
*/
public function withRelationshipRelatedLink($resource, string $relationshipName): self;
/**
* Reset encoder settings to defaults.
*
* @return self
*/
public function reset(): self;
/**
* Encode input as JSON API string.
*
* @param object|iterable|null $data Data to encode.
*
* @return string
*/
public function encodeData($data): string;
/**
* Encode input as JSON API string with a list of resource identifiers.
*
* @param object|iterable|null $data Data to encode.
*
* @return string
*/
public function encodeIdentifiers($data): string;
/**
* Encode error as JSON API string.
*
* @param ErrorInterface $error
*
* @return string
*/
public function encodeError(ErrorInterface $error): string;
/**
* Encode errors as JSON API string.
*
* @see ErrorInterface
*
* @param iterable $errors
*
* @return string
*/
public function encodeErrors(iterable $errors): string;
/**
* Encode input meta as JSON API string.
*
* @param mixed $meta Meta information.
*
* @return string
*/
public function encodeMeta($meta): string;
}