|
1
|
|
|
<?php declare (strict_types = 1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Limoncello\Flute\Contracts\Validation; |
|
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 Limoncello\Validation\Contracts\Rules\RuleInterface; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @package Limoncello\Application |
|
25
|
|
|
*/ |
|
26
|
|
|
interface JsonApiQueryRulesSerializerInterface |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* Add rules from query rules class. |
|
30
|
|
|
* |
|
31
|
|
|
* @param string $rulesClass |
|
32
|
|
|
* |
|
33
|
|
|
* @return self |
|
|
|
|
|
|
34
|
|
|
*/ |
|
35
|
|
|
public function addRulesFromClass(string $rulesClass): self; |
|
36
|
|
|
|
|
37
|
|
|
/** @noinspection PhpTooManyParametersInspection |
|
38
|
|
|
* Add rules manually. |
|
39
|
|
|
* |
|
40
|
|
|
* @param string $name |
|
41
|
|
|
* @param RuleInterface|null $identityRule |
|
42
|
|
|
* @param RuleInterface[]|null $filterRules |
|
43
|
|
|
* @param RuleInterface[]|null $fieldSetRules |
|
44
|
|
|
* @param RuleInterface|null $sortsRule |
|
45
|
|
|
* @param RuleInterface|null $includesRule |
|
46
|
|
|
* @param RuleInterface|null $pageOffsetRule |
|
47
|
|
|
* @param RuleInterface|null $pageLimitRule |
|
48
|
|
|
* |
|
49
|
|
|
* @return self |
|
50
|
|
|
*/ |
|
51
|
|
|
public function addQueryRules( |
|
52
|
|
|
string $name, |
|
53
|
|
|
?RuleInterface $identityRule, |
|
54
|
|
|
?array $filterRules, |
|
55
|
|
|
?array $fieldSetRules, |
|
56
|
|
|
?RuleInterface $sortsRule, |
|
57
|
|
|
?RuleInterface $includesRule, |
|
58
|
|
|
?RuleInterface $pageOffsetRule, |
|
59
|
|
|
?RuleInterface $pageLimitRule |
|
60
|
|
|
): JsonApiQueryRulesSerializerInterface; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Get serialized data. |
|
64
|
|
|
* |
|
65
|
|
|
* @return array |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getData(): array; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Reads validation blocks from serialized data. |
|
71
|
|
|
* |
|
72
|
|
|
* @param array $serializedData |
|
73
|
|
|
* |
|
74
|
|
|
* @return array |
|
75
|
|
|
*/ |
|
76
|
|
|
public static function readBlocks(array $serializedData): array; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Reads serialized validation rules from serialized data. |
|
80
|
|
|
* |
|
81
|
|
|
* @param string $name |
|
82
|
|
|
* @param array $serializedData |
|
83
|
|
|
* |
|
84
|
|
|
* @return bool |
|
85
|
|
|
*/ |
|
86
|
|
|
public static function hasRules(string $name, array $serializedData): bool; |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Reads serialized validation rules from serialized data. |
|
90
|
|
|
* |
|
91
|
|
|
* @param string $name |
|
92
|
|
|
* @param array $serializedData |
|
93
|
|
|
* |
|
94
|
|
|
* @return array |
|
95
|
|
|
*/ |
|
96
|
|
|
public static function readRules(string $name, array $serializedData): array; |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Reads serialized identity validation rule indexes from rules. |
|
100
|
|
|
* |
|
101
|
|
|
* @param array $serializedRules |
|
102
|
|
|
* |
|
103
|
|
|
* @return array |
|
104
|
|
|
*/ |
|
105
|
|
|
public static function readIdentityRuleIndexes(array $serializedRules): ?array; |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Reads serialized filter validation rule indexes from rules. |
|
109
|
|
|
* |
|
110
|
|
|
* @param array $serializedRules |
|
111
|
|
|
* |
|
112
|
|
|
* @return array |
|
113
|
|
|
*/ |
|
114
|
|
|
public static function readFilterRulesIndexes(array $serializedRules): ?array; |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Reads serialized field set validation rule indexes from rules. |
|
118
|
|
|
* |
|
119
|
|
|
* @param array $serializedRules |
|
120
|
|
|
* |
|
121
|
|
|
* @return array |
|
122
|
|
|
*/ |
|
123
|
|
|
public static function readFieldSetRulesIndexes(array $serializedRules): ?array; |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Reads serialized sorts validation rule indexes from rules. |
|
127
|
|
|
* |
|
128
|
|
|
* @param array $serializedRules |
|
129
|
|
|
* |
|
130
|
|
|
* @return array |
|
131
|
|
|
*/ |
|
132
|
|
|
public static function readSortsRuleIndexes(array $serializedRules): ?array; |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Reads serialized includes validation rule indexes from rules. |
|
136
|
|
|
* |
|
137
|
|
|
* @param array $serializedRules |
|
138
|
|
|
* |
|
139
|
|
|
* @return array |
|
140
|
|
|
*/ |
|
141
|
|
|
public static function readIncludesRuleIndexes(array $serializedRules): ?array; |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Reads serialized page offset validation rule indexes from rules. |
|
145
|
|
|
* |
|
146
|
|
|
* @param array $serializedRules |
|
147
|
|
|
* |
|
148
|
|
|
* @return array |
|
149
|
|
|
*/ |
|
150
|
|
|
public static function readPageOffsetRuleIndexes(array $serializedRules): ?array; |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Reads serialized page limit validation rule indexes from rules. |
|
154
|
|
|
* |
|
155
|
|
|
* @param array $serializedRules |
|
156
|
|
|
* |
|
157
|
|
|
* @return array |
|
158
|
|
|
*/ |
|
159
|
|
|
public static function readPageLimitRuleIndexes(array $serializedRules): ?array; |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* Read rule indexes (key, index pairs) from serialized rules indexes. |
|
163
|
|
|
* |
|
164
|
|
|
* @param array $ruleIndexes |
|
165
|
|
|
* |
|
166
|
|
|
* @return array |
|
167
|
|
|
*/ |
|
168
|
|
|
public static function readRuleMainIndexes(array $ruleIndexes): ?array; |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* Read first rule index from serialized rules indexes. |
|
172
|
|
|
* |
|
173
|
|
|
* @param array $ruleIndexes |
|
174
|
|
|
* |
|
175
|
|
|
* @return int |
|
176
|
|
|
*/ |
|
177
|
|
|
public static function readRuleMainIndex(array $ruleIndexes): ?int; |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Read rule start indexes (key, index pairs) from serialized rules indexes. |
|
181
|
|
|
* |
|
182
|
|
|
* @param array $ruleIndexes |
|
183
|
|
|
* |
|
184
|
|
|
* @return array |
|
185
|
|
|
*/ |
|
186
|
|
|
public static function readRuleStartIndexes(array $ruleIndexes): array; |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Read rule end indexes (key, index pairs) from serialized rules indexes. |
|
190
|
|
|
* |
|
191
|
|
|
* @param array $ruleIndexes |
|
192
|
|
|
* |
|
193
|
|
|
* @return array |
|
194
|
|
|
*/ |
|
195
|
|
|
public static function readRuleEndIndexes(array $ruleIndexes): array; |
|
196
|
|
|
} |
|
197
|
|
|
|
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.