|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Anetwork\Respond; |
|
4
|
|
|
|
|
5
|
|
|
class Messages extends Main |
|
6
|
|
|
{ |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Request succeeded and contains json result |
|
10
|
|
|
* @param array $data |
|
11
|
|
|
* @author Shima Payro <[email protected]> |
|
12
|
|
|
* @since May 2, 2016 9:50:51 AM |
|
13
|
|
|
* @uses |
|
14
|
|
|
* @see |
|
15
|
|
|
*/ |
|
16
|
|
|
public function succeed( $data ) { |
|
17
|
|
|
|
|
18
|
|
|
return $this->setStatusCode( 200 ) |
|
19
|
|
|
->setStatusText( 'success' ) |
|
20
|
|
|
->respondWithResult( $data ); |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Delete action is succeed |
|
26
|
|
|
* @author Shima Payro <[email protected]> |
|
27
|
|
|
* @param String $message |
|
28
|
|
|
* @since May 2, 2016 9:52:05 AM |
|
29
|
|
|
* @uses |
|
30
|
|
|
* @see |
|
31
|
|
|
*/ |
|
32
|
|
|
public function deleteSucceeded( $message = 'The requested parameter is deleted successfully!' ) { |
|
33
|
|
|
|
|
34
|
|
|
return $this->setStatusCode( 200 ) |
|
35
|
|
|
->setStatusText( 'success' ) |
|
36
|
|
|
->respondWithMessage( $message ); |
|
37
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Update action is succeed |
|
42
|
|
|
* @author Shima Payro <[email protected]> |
|
43
|
|
|
* @param String $message |
|
44
|
|
|
* @since May 2, 2016 9:52:52 AM |
|
45
|
|
|
* @uses |
|
46
|
|
|
* @see |
|
47
|
|
|
*/ |
|
48
|
|
|
public function updateSucceeded( $message = 'The requested parameter is updated successfully!' ) { |
|
49
|
|
|
|
|
50
|
|
|
return $this->setStatusCode( 200 ) |
|
51
|
|
|
->setStatusText( 'success' ) |
|
52
|
|
|
->respondWithMessage( $message ); |
|
53
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Insert action is succeed |
|
58
|
|
|
* @author Shima Payro <[email protected]> |
|
59
|
|
|
* @param String $message |
|
60
|
|
|
* @since May 2, 2016 9:53:26 AM |
|
61
|
|
|
* @uses |
|
62
|
|
|
* @see |
|
63
|
|
|
*/ |
|
64
|
|
|
public function insertSucceeded( $message = 'The requested parameter is Added successfully!' ) { |
|
65
|
|
|
|
|
66
|
|
|
return $this->setStatusCode( 200 ) |
|
67
|
|
|
->setStatusText( 'success' ) |
|
68
|
|
|
->respondWithMessage( $message ); |
|
69
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Delete action is faild |
|
74
|
|
|
* @author Shima Payro <[email protected]> |
|
75
|
|
|
* @param String $message |
|
|
|
|
|
|
76
|
|
|
* @since May 2, 2016 9:53:53 AM |
|
77
|
|
|
* @uses |
|
78
|
|
|
* @see |
|
79
|
|
|
*/ |
|
80
|
|
|
public function deleteFaild() { |
|
81
|
|
|
|
|
82
|
|
|
return $this->setStatusCode( 447 ) |
|
83
|
|
|
->setStatusText( 'fail' ) |
|
84
|
|
|
->setErrorCode( 5447 ) |
|
85
|
|
|
->respondWithMessage(); |
|
86
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Update action is succeed |
|
91
|
|
|
* @author Shima Payro <[email protected]> |
|
92
|
|
|
* @param String $message |
|
|
|
|
|
|
93
|
|
|
* @since May 2, 2016 9:54:09 AM |
|
94
|
|
|
* @uses |
|
95
|
|
|
* @see |
|
96
|
|
|
*/ |
|
97
|
|
|
public function updateFaild() { |
|
98
|
|
|
|
|
99
|
|
|
return $this->setStatusCode( 449 ) |
|
100
|
|
|
->setStatusText( 'fail' ) |
|
101
|
|
|
->setErrorCode( 5449 ) |
|
102
|
|
|
->respondWithMessage(); |
|
103
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Insert action is faild |
|
108
|
|
|
* @author Shima Payro <[email protected]> |
|
109
|
|
|
* @param String $message |
|
|
|
|
|
|
110
|
|
|
* @since May 2, 2016 9:54:27 AM |
|
111
|
|
|
* @uses |
|
112
|
|
|
* @see |
|
113
|
|
|
*/ |
|
114
|
|
|
public function insertFaild() { |
|
115
|
|
|
|
|
116
|
|
|
return $this->setStatusCode( 448 ) |
|
117
|
|
|
->setStatusText( 'fail' ) |
|
118
|
|
|
->setErrorCode( 5448 ) |
|
119
|
|
|
->respondWithMessage(); |
|
120
|
|
|
|
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Database connection is refused |
|
125
|
|
|
* @author Shima Payro <[email protected]> |
|
126
|
|
|
* @param String $message |
|
|
|
|
|
|
127
|
|
|
* @since May 2, 2016 9:54:45 AM |
|
128
|
|
|
* @uses |
|
129
|
|
|
* @see |
|
130
|
|
|
*/ |
|
131
|
|
|
public function connectionRefused() { |
|
132
|
|
|
|
|
133
|
|
|
return $this->setStatusCode( 445 ) |
|
134
|
|
|
->setStatusText( 'fail' ) |
|
135
|
|
|
->setErrorCode( 5445 ) |
|
136
|
|
|
->respondWithMessage(); |
|
137
|
|
|
|
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* page requested is not found |
|
142
|
|
|
* @author Shima Payro <[email protected]> |
|
143
|
|
|
* @param String $message |
|
|
|
|
|
|
144
|
|
|
* @since May 2, 2016 9:55:20 AM |
|
145
|
|
|
* @uses |
|
146
|
|
|
* @see |
|
147
|
|
|
*/ |
|
148
|
|
|
public function notFound() { |
|
149
|
|
|
|
|
150
|
|
|
return $this->setStatusCode( 404 ) |
|
151
|
|
|
->setStatusText( 'fail' ) |
|
152
|
|
|
->setErrorCode( 5404 ) |
|
153
|
|
|
->respondWithMessage(); |
|
154
|
|
|
|
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Wrong parameters are entered |
|
159
|
|
|
* @author Shima Payro <[email protected]> |
|
160
|
|
|
* @param String $message |
|
|
|
|
|
|
161
|
|
|
* @since May 2, 2016 9:55:20 AM |
|
162
|
|
|
* @uses |
|
163
|
|
|
* @see |
|
164
|
|
|
*/ |
|
165
|
|
|
public function wrongParameters() { |
|
166
|
|
|
|
|
167
|
|
|
return $this->setStatusCode( 406 ) |
|
168
|
|
|
->setStatusText( 'fail' ) |
|
169
|
|
|
->setErrorCode( 5406 ) |
|
170
|
|
|
->respondWithMessage(); |
|
171
|
|
|
|
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* Method is not allowed |
|
176
|
|
|
* @author Shima Payro <[email protected]> |
|
177
|
|
|
* @param String $message |
|
|
|
|
|
|
178
|
|
|
* @since May 2, 2016 9:55:20 AM |
|
179
|
|
|
* @uses |
|
180
|
|
|
* @see |
|
181
|
|
|
*/ |
|
182
|
|
|
public function methodNotAllowed() { |
|
183
|
|
|
|
|
184
|
|
|
return $this->setStatusCode( 405 ) |
|
185
|
|
|
->setStatusText( 'fail' ) |
|
186
|
|
|
->setErrorCode( 5405 ) |
|
187
|
|
|
->respondWithMessage(); |
|
188
|
|
|
|
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* There ara validation errors |
|
193
|
|
|
* @author Shima Payro <[email protected]> |
|
194
|
|
|
* @param Array $data |
|
195
|
|
|
* @since May 2, 2016 9:55:20 AM |
|
196
|
|
|
* @uses |
|
197
|
|
|
* @see |
|
198
|
|
|
*/ |
|
199
|
|
|
public function validationErrors( $data ) { |
|
200
|
|
|
|
|
201
|
|
|
return $this->setStatusCode( 420 ) |
|
202
|
|
|
->setStatusText( 'fail' ) |
|
203
|
|
|
->setErrorCode( 5420 ) |
|
204
|
|
|
->respondWithResult( $data ); |
|
|
|
|
|
|
205
|
|
|
|
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* The request field is not found |
|
210
|
|
|
* @author Shima Payro <[email protected]> |
|
211
|
|
|
* @param String $message |
|
|
|
|
|
|
212
|
|
|
* @since May 2, 2016 9:55:20 AM |
|
213
|
|
|
* @uses |
|
214
|
|
|
* @see |
|
215
|
|
|
*/ |
|
216
|
|
|
public function requestFieldNotFound() { |
|
217
|
|
|
|
|
218
|
|
|
return $this->setStatusCode( 446 ) |
|
219
|
|
|
->setStatusText( 'fail' ) |
|
220
|
|
|
->setErrorCode( 1001 ) |
|
221
|
|
|
->respondWithMessage(); |
|
222
|
|
|
|
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* The request field is doublicated |
|
227
|
|
|
* @author Mehdi Hosseini <[email protected]> |
|
228
|
|
|
* @since August 24, 2016 |
|
229
|
|
|
* @return json |
|
230
|
|
|
*/ |
|
231
|
|
|
public function requestFieldDuplicated() { |
|
232
|
|
|
|
|
233
|
|
|
return $this->setStatusCode( 400 ) |
|
234
|
|
|
->setStatusText( 'fail' ) |
|
235
|
|
|
->SetErrorCode(1004) |
|
236
|
|
|
->respondWithMessage(); |
|
237
|
|
|
|
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* Custom error message according to error config file |
|
242
|
|
|
* @author Mehdi Hosseini <[email protected]> |
|
243
|
|
|
* @since August 24, 2016 |
|
244
|
|
|
* @param $code integer |
|
245
|
|
|
* @return json |
|
246
|
|
|
*/ |
|
247
|
|
|
public function error( $code ) { |
|
248
|
|
|
|
|
249
|
|
|
return $this->SetStatusCode( 400 ) |
|
250
|
|
|
->setStatusText( 'fail' ) |
|
251
|
|
|
->setErrorCode( $code ) |
|
252
|
|
|
->respondWithMessage(); |
|
253
|
|
|
|
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
|
|
257
|
|
|
} |
|
258
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: