|
1
|
|
|
<?php declare (strict_types = 1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Limoncello\Flute\Contracts\Api; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Copyright 2015-2019 [email protected] |
|
7
|
|
|
* |
|
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
9
|
|
|
* you may not use this file except in compliance with the License. |
|
10
|
|
|
* You may obtain a copy of the License at |
|
11
|
|
|
* |
|
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
13
|
|
|
* |
|
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
17
|
|
|
* See the License for the specific language governing permissions and |
|
18
|
|
|
* limitations under the License. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
use Closure; |
|
22
|
|
|
use Doctrine\DBAL\Query\QueryBuilder; |
|
23
|
|
|
use Limoncello\Flute\Contracts\Models\PaginatedDataInterface; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @package Limoncello\Flute |
|
27
|
|
|
*/ |
|
28
|
|
|
interface CrudInterface |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @return self |
|
|
|
|
|
|
32
|
|
|
*/ |
|
33
|
|
|
public function combineWithAnd(): self; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @return self |
|
|
|
|
|
|
37
|
|
|
*/ |
|
38
|
|
|
public function combineWithOr(): self; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param iterable $filterParameters |
|
42
|
|
|
* |
|
43
|
|
|
* @return self |
|
|
|
|
|
|
44
|
|
|
*/ |
|
45
|
|
|
public function withFilters(iterable $filterParameters): self; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param string $index |
|
49
|
|
|
* |
|
50
|
|
|
* @return self |
|
|
|
|
|
|
51
|
|
|
*/ |
|
52
|
|
|
public function withIndexFilter(string $index): self; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param array $indexes |
|
56
|
|
|
* |
|
57
|
|
|
* @return self |
|
|
|
|
|
|
58
|
|
|
*/ |
|
59
|
|
|
public function withIndexesFilter(array $indexes): self; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param iterable $sortingParameters |
|
63
|
|
|
* |
|
64
|
|
|
* @return self |
|
|
|
|
|
|
65
|
|
|
*/ |
|
66
|
|
|
public function withSorts(iterable $sortingParameters): self; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param iterable $includePaths |
|
70
|
|
|
* |
|
71
|
|
|
* @return self |
|
|
|
|
|
|
72
|
|
|
*/ |
|
73
|
|
|
public function withIncludes(iterable $includePaths): self; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param int $offset |
|
77
|
|
|
* @param int $limit |
|
78
|
|
|
* |
|
79
|
|
|
* @return self |
|
|
|
|
|
|
80
|
|
|
*/ |
|
81
|
|
|
public function withPaging(int $offset, int $limit): self; |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @return self |
|
|
|
|
|
|
85
|
|
|
*/ |
|
86
|
|
|
public function withoutPaging(): self; |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param string $name |
|
90
|
|
|
* @param iterable $filters |
|
91
|
|
|
* |
|
92
|
|
|
* @return CrudInterface |
|
|
|
|
|
|
93
|
|
|
*/ |
|
94
|
|
|
public function withRelationshipFilters(string $name, iterable $filters): self; |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @param string $name |
|
98
|
|
|
* @param iterable $sorts |
|
99
|
|
|
* |
|
100
|
|
|
* @return CrudInterface |
|
|
|
|
|
|
101
|
|
|
*/ |
|
102
|
|
|
public function withRelationshipSorts(string $name, iterable $sorts): self; |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @param iterable|null $columns |
|
106
|
|
|
* |
|
107
|
|
|
* @return QueryBuilder |
|
108
|
|
|
*/ |
|
109
|
|
|
public function createIndexBuilder(iterable $columns = null): QueryBuilder; |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @return QueryBuilder |
|
113
|
|
|
*/ |
|
114
|
|
|
public function createDeleteBuilder(): QueryBuilder; |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @param QueryBuilder $builder |
|
118
|
|
|
* @param string $modelClass |
|
119
|
|
|
* |
|
120
|
|
|
* @return PaginatedDataInterface |
|
121
|
|
|
*/ |
|
122
|
|
|
public function fetchResources(QueryBuilder $builder, string $modelClass): PaginatedDataInterface; |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @param QueryBuilder|null $builder |
|
|
|
|
|
|
126
|
|
|
* @param string|null $modelClass |
|
127
|
|
|
* |
|
128
|
|
|
* @return mixed|null |
|
129
|
|
|
*/ |
|
130
|
|
|
public function fetchResource(QueryBuilder $builder, string $modelClass); |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @param QueryBuilder $builder |
|
134
|
|
|
* @param string $modelClass |
|
135
|
|
|
* |
|
136
|
|
|
* @return array|null |
|
137
|
|
|
*/ |
|
138
|
|
|
public function fetchRow(QueryBuilder $builder, string $modelClass): ?array; |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @param QueryBuilder $builder |
|
142
|
|
|
* @param string $modelClass |
|
143
|
|
|
* @param string $columnName |
|
144
|
|
|
* |
|
145
|
|
|
* @return iterable |
|
146
|
|
|
*/ |
|
147
|
|
|
public function fetchColumn(QueryBuilder $builder, string $modelClass, string $columnName): iterable; |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @return PaginatedDataInterface |
|
151
|
|
|
*/ |
|
152
|
|
|
public function index(): PaginatedDataInterface; |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @return array |
|
156
|
|
|
*/ |
|
157
|
|
|
public function indexIdentities(): array; |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @param string $index |
|
161
|
|
|
* |
|
162
|
|
|
* @return mixed|null |
|
163
|
|
|
*/ |
|
164
|
|
|
public function read(string $index); |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @return int|null |
|
168
|
|
|
*/ |
|
169
|
|
|
public function count(): ?int; |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @return int |
|
173
|
|
|
*/ |
|
174
|
|
|
public function delete(): int; |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @param string $index |
|
178
|
|
|
* |
|
179
|
|
|
* @return bool |
|
180
|
|
|
*/ |
|
181
|
|
|
public function remove(string $index): bool; |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* @param null|string $index |
|
185
|
|
|
* @param array $attributes |
|
186
|
|
|
* @param array $toMany |
|
187
|
|
|
* |
|
188
|
|
|
* @return string |
|
189
|
|
|
*/ |
|
190
|
|
|
public function create(?string $index, array $attributes, array $toMany): string; |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* @param string $index |
|
194
|
|
|
* @param array $attributes |
|
195
|
|
|
* @param array $toMany |
|
196
|
|
|
* |
|
197
|
|
|
* @return int |
|
198
|
|
|
*/ |
|
199
|
|
|
public function update(string $index, array $attributes, array $toMany): int; |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* @param string $name |
|
203
|
|
|
* @param iterable|null $relationshipFilters |
|
204
|
|
|
* @param iterable|null $relationshipSorts |
|
205
|
|
|
* |
|
206
|
|
|
* @return PaginatedDataInterface|mixed|null |
|
207
|
|
|
*/ |
|
208
|
|
|
public function indexRelationship( |
|
209
|
|
|
string $name, |
|
210
|
|
|
iterable $relationshipFilters = null, |
|
211
|
|
|
iterable $relationshipSorts = null |
|
212
|
|
|
); |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* @param string $name |
|
216
|
|
|
* @param iterable|null $relationshipFilters |
|
217
|
|
|
* @param iterable|null $relationshipSorts |
|
218
|
|
|
* |
|
219
|
|
|
* @return array |
|
220
|
|
|
*/ |
|
221
|
|
|
public function indexRelationshipIdentities( |
|
222
|
|
|
string $name, |
|
223
|
|
|
iterable $relationshipFilters = null, |
|
224
|
|
|
iterable $relationshipSorts = null |
|
225
|
|
|
): array; |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* @param string $index |
|
229
|
|
|
* @param string $name |
|
230
|
|
|
* @param iterable|null $relationshipFilters |
|
231
|
|
|
* @param iterable|null $relationshipSorts |
|
232
|
|
|
* |
|
233
|
|
|
* @return PaginatedDataInterface|mixed|null |
|
234
|
|
|
*/ |
|
235
|
|
|
public function readRelationship( |
|
236
|
|
|
string $index, |
|
237
|
|
|
string $name, |
|
238
|
|
|
iterable $relationshipFilters = null, |
|
239
|
|
|
iterable $relationshipSorts = null |
|
240
|
|
|
); |
|
241
|
|
|
|
|
242
|
|
|
/** |
|
243
|
|
|
* @param string $parentId |
|
244
|
|
|
* @param string $name |
|
245
|
|
|
* @param string $childId |
|
246
|
|
|
* |
|
247
|
|
|
* @return bool |
|
248
|
|
|
*/ |
|
249
|
|
|
public function hasInRelationship(string $parentId, string $name, string $childId): bool; |
|
250
|
|
|
|
|
251
|
|
|
/** |
|
252
|
|
|
* @param string $parentId |
|
253
|
|
|
* @param string $name |
|
254
|
|
|
* @param iterable $childIds |
|
255
|
|
|
* |
|
256
|
|
|
* @return int |
|
257
|
|
|
*/ |
|
258
|
|
|
public function createInBelongsToManyRelationship(string $parentId, string $name, iterable $childIds): int; |
|
259
|
|
|
|
|
260
|
|
|
/** |
|
261
|
|
|
* @param string $parentId |
|
262
|
|
|
* @param string $name |
|
263
|
|
|
* @param iterable $childIds |
|
264
|
|
|
* |
|
265
|
|
|
* @return int |
|
266
|
|
|
*/ |
|
267
|
|
|
public function removeInBelongsToManyRelationship(string $parentId, string $name, iterable $childIds): int; |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* @param Closure $closure |
|
271
|
|
|
*/ |
|
272
|
|
|
public function inTransaction(Closure $closure): void; |
|
273
|
|
|
} |
|
274
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.