-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathhelper.php
More file actions
executable file
·308 lines (289 loc) · 10.3 KB
/
helper.php
File metadata and controls
executable file
·308 lines (289 loc) · 10.3 KB
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<?php
use Contentstack\Support\Utility;
use Contentstack\Error\ErrorMessages;
if(!function_exists('contentstackGetFunctionName')) {
/*
* To get the Query method name
* @return string|function-name
* */
function contentstackGetFunctionName() {
$stack = debug_backtrace();
if(count($stack) > 2) {
return $stack[3]['function'];
}
return $stack[0]['function'];
}
}
if(!function_exists('contentstackCreateError')) {
/*
* Create exception object based on messages
* @param
* string|msg - Exception message to be delivered
* @return Exception
* */
function contentstackCreateError($msg = '') {
if(!Utility::isEmpty($msg)) return new Exception($msg);
}
}
if (!function_exists('contentstackSearch')) {
/*
* search
* search
* @param
* $operator - query operator
* $query - Query object
* $value - value to be search
* @return $query
* */
function contentstackSearch($operator = '', $query = array(), $value = '') {
if(!(!Utility::isEmpty($value) && is_string($value)))
throw contentstackCreateError(ErrorMessages::formatMessage(ErrorMessages::INVALID_STRING_INPUT, contentstackGetFunctionName()));
$query[$operator] = $value;
return $query;
}
}
if (!function_exists('contentstackReferences')) {
/*
* contentstackReferences
* contentstackReferences
* @param
* $query - Query object
* $values - array of fields to be included in the result set
* @return $query
* */
function contentstackReferences($operator = '', $query = array(), $value = array()) {
if(!is_array($value))
throw contentstackCreateError(ErrorMessages::INVALID_INCLUDE_REFERENCES);
$query[$operator] = $value;
return $query;
}
}
if (!function_exists('contentstackProjection')) {
/*
* projection
* projection
* @param
* $query - Query object
* $values - array of fields to be included in the result set
* @return $query
* */
function contentstackProjection($operator = '', $query = array(), $level = 'BASE', $value = array()) {
if(is_array($level)) {
$value = $level;
$level = 'BASE';
}
if(!(!Utility::isEmpty($level) && is_string($level) && is_array($value))) throw contentstackCreateError(ErrorMessages::INVALID_INPUT_TYPE);
if(!Utility::isKeySet($query, $operator)) $query[$operator] = array();
if(!Utility::isKeySet($query[$operator], $level)) $query[$operator][$level] = array();
$query[$operator][$level] = array_merge($query[$operator][$level], $value);
return $query;
}
}
if (!function_exists('contentstackRegexp')) {
/*
* contentstackRegexp
* contentstackRegexp
* @param
* $operator - query operator
* $query - Query object
* $key - key of the query
* $value - value to be set against key
* $options - options for the regular expression
* @return $query
* */
function contentstackRegexp($operator = '', $query = array(), $values = array()) {
if(count($values) === 2 || count($values) === 3) {
if(Utility::isEmpty($values[0]) && Utility::isEmpty($values[1]) && is_string($values[0]) && is_string($values[1]))
throw contentstackCreateError(ErrorMessages::INVALID_REGEX_KEY_VALUE);
if(isset($values[2]) && !(is_string($values[2]) && strlen($values[2]) > 0)) {
throw contentstackCreateError(ErrorMessages::INVALID_REGEX_OPTIONS);
}
$query[$values[0]] = array($operator => $values[1]);
if(isset($values[2]))
$query[$values[0]]['$options'] = $values[2];
return $query;
} else {
throw contentstackCreateError(ErrorMessages::INVALID_REGEX_ARGS);
}
}
}
if (!function_exists('contentstackTags')) {
/*
* contentstackTags
* contentstackTags
* @param
* $operator - query operator
* $query - Query object
* $value - array of tags
* @return $query
* */
function contentstackTags($operator = '', $query = array(), $value = '') {
if(!(is_array($value) && count($value) > 0))
throw contentstackCreateError(ErrorMessages::INVALID_TAGS_INPUT);
$query[$operator] = $value;
return $query;
}
}
if (!function_exists('contentstackComparision')) {
/*
* comparision
* comparision
* @param
* $operator - query operator
* $query - Query object
* $key - key of the query
* $value - value to be set against key
* @return $query
* */
function contentstackComparision($operator = '', $query = array(), $key = '', $value = '') {
if(!(!Utility::isEmpty($key) && is_string($key) && !Utility::isEmpty($value)))
throw contentstackCreateError(ErrorMessages::formatMessage(ErrorMessages::INVALID_KEY_VALUE, contentstackGetFunctionName()));
$query[$key] = array($operator => $value);
return $query;
}
}
if (!function_exists('contentstackLogical')) {
/*
* logical
* logical operations
* @param
* $operator - query operator
* $query - Query object
* $value - array of Query object or json query
* @return $query
* @ignore
* */
function contentstackLogical($operator = '', $query = array(), $value = array()) {
if(!(is_array($value) && count($value) > 0))
throw contentstackCreateError(ErrorMessages::formatMessage(ErrorMessages::INVALID_QUERY_INPUT, contentstackGetFunctionName()));
foreach($value as $key => $_qry) {
if(!Utility::isKeySet($query, $operator)) $query[$operator] = array();
if($_qry instanceof \Contentstack\Stack\BaseQuery)
array_push($query[$operator], $_qry->subQuery);
else if(is_array($_qry))
array_push($query[$operator], $_qry);
else {
unset($query[$operator]);
throw contentstackCreateError(ErrorMessages::INVALID_QUERY_OBJECTS);
}
}
return $query;
}
}
if (!function_exists('contentstackContains')) {
/*
* contains
* contains
* @param
* $operator - query operator
* $query - Query object
* $key - key of the query
* $value - array of value to be set against key
* @return $query
* */
function contentstackContains($operator = '', $query = array(), $key = '', $value = array()) {
if (!(!Utility::isEmpty($key) && is_string($key) && is_array($value)))
throw contentstackCreateError(ErrorMessages::formatMessage(ErrorMessages::INVALID_KEY_ARRAY_VALUE, contentstackGetFunctionName()));
$query[$key] = array($operator => $value);
return $query;
}
}
if (!function_exists('contentstackPagination')) {
/*
* pagination
* Creates the skip and limit parameters
* @param
* $operator - key of the query
* $query - Query object
* $value - value to be set against key
* @return $query
* */
function contentstackPagination($operator = '', $query = array(), $value = '') {
if (!(!Utility::isEmpty($value) && is_numeric($value)))
throw contentstackCreateError(ErrorMessages::formatMessage(ErrorMessages::INVALID_NUMERIC_INPUT, contentstackGetFunctionName()));
$query[$operator] = $value;
return $query;
}
}
if (!function_exists('contentstackLanguage')) {
/*
* language
* Set the locale on the Query
* @param
* $operator - key of the query
* $query - Query object
* $value - value to be set against key
* @return $query
* */
function contentstackLanguage($operator = '', $query = array(), $value = '') {
if (!(!Utility::isEmpty($value) && is_string($value)))
throw contentstackCreateError(ErrorMessages::formatMessage(ErrorMessages::INVALID_STRING_INPUT, contentstackGetFunctionName()));
$query[$operator] = $value;
return $query;
}
}
if (!function_exists('contentstackSorting')) {
/*
* sort
* sort the field based on the query
* @param
* $operator - key of the query
* $query - Query object
* $field_uid - field_uid which is to be use for sorting
* @return $query
* */
function contentstackSorting($operator = '', $query = array(), $key = '') {
if (!(!Utility::isEmpty($key) && is_string($key)))
throw contentstackCreateError(ErrorMessages::formatMessage(ErrorMessages::INVALID_FIELD_INPUT, contentstackGetFunctionName()));
$query[$operator] = $key;
return $query;
}
}
if (!function_exists('contentstackAddBoolean')) {
/*
* addBoolean
* Set the boolean parameter on the Query
* @param
* $operator - key of the query
* $query - Query object
* $value - value to be set against key
* @return $query
* */
function contentstackAddBoolean($operator = '', $query = array()) {
$query[$operator] = 'true';
return $query;
}
}
if (!function_exists('contentstackAddParam')) {
/*
* AddParam
* Set the locale on the Query
* @param
* $operator - key of the query
* $query - Query object
* $value - value to be set against key
* @return $query
* */
function contentstackAddParam($key = '', $query = array(), $value = '') {
$query[$key] = $value;
return $query;
}
}
if (!function_exists('contentstackExistence')) {
/*
* existence
* Set the boolean parameter on the Query
* @param
* $operator - $operator of the query
* $query - Query object
* $key - field_uid against which query to be checked
* $value - value to be set against key
* @return $query
* */
function contentstackExistence($operator = '', $query = array(), $key = '', $value = false) {
if (!(!Utility::isEmpty($key) && is_string($key)))
throw contentstackCreateError(ErrorMessages::formatMessage(ErrorMessages::INVALID_FIELD_UID, contentstackGetFunctionName()));
$query[$key] = array($operator => $value);
return $query;
}
}