@@ -133,7 +133,6 @@ discard block |
||
133 | 133 | /** |
134 | 134 | * Database connection is refused |
135 | 135 | * @author Shima Payro <[email protected]> |
136 | - * @param String $message |
|
137 | 136 | * @since May 2, 2016 9:54:45 AM |
138 | 137 | * @uses |
139 | 138 | * @see |
@@ -150,7 +149,6 @@ discard block |
||
150 | 149 | /** |
151 | 150 | * page requested is not found |
152 | 151 | * @author Shima Payro <[email protected]> |
153 | - * @param String $message |
|
154 | 152 | * @since May 2, 2016 9:55:20 AM |
155 | 153 | * @uses |
156 | 154 | * @see |
@@ -167,7 +165,6 @@ discard block |
||
167 | 165 | /** |
168 | 166 | * Wrong parameters are entered |
169 | 167 | * @author Shima Payro <[email protected]> |
170 | - * @param String $message |
|
171 | 168 | * @since May 2, 2016 9:55:20 AM |
172 | 169 | * @uses |
173 | 170 | * @see |
@@ -184,7 +181,6 @@ discard block |
||
184 | 181 | /** |
185 | 182 | * Method is not allowed |
186 | 183 | * @author Shima Payro <[email protected]> |
187 | - * @param String $message |
|
188 | 184 | * @since May 2, 2016 9:55:20 AM |
189 | 185 | * @uses |
190 | 186 | * @see |
@@ -218,7 +214,6 @@ discard block |
||
218 | 214 | /** |
219 | 215 | * The request field is not found |
220 | 216 | * @author Shima Payro <[email protected]> |
221 | - * @param String $message |
|
222 | 217 | * @since May 2, 2016 9:55:20 AM |
223 | 218 | * @uses |
224 | 219 | * @see |
@@ -6,262 +6,262 @@ |
||
6 | 6 | { |
7 | 7 | |
8 | 8 | |
9 | - /** |
|
10 | - * Request succeeded and contains json result |
|
11 | - * @param array $data |
|
12 | - * @author Shima Payro <[email protected]> |
|
13 | - * @since May 2, 2016 9:50:51 AM |
|
14 | - * @uses |
|
15 | - * @see |
|
16 | - */ |
|
17 | - public function succeed( $data ) { |
|
18 | - |
|
19 | - return $this->setStatusCode( 200 ) |
|
20 | - ->setStatusText( 'success' ) |
|
21 | - ->respondWithResult( $data ); |
|
22 | - |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * Delete action is succeed |
|
27 | - * @author Shima Payro <[email protected]> |
|
28 | - * @param String $message |
|
29 | - * @since May 2, 2016 9:52:05 AM |
|
30 | - * @uses |
|
31 | - * @see |
|
32 | - */ |
|
33 | - public function deleteSucceeded( $message ) { |
|
34 | - |
|
35 | - if ( empty( $message ) ) |
|
36 | - $message = $this->config[ 'success' ][ 'delete' ]; |
|
37 | - |
|
38 | - return $this->setStatusCode( 200 ) |
|
39 | - ->setStatusText( 'success' ) |
|
40 | - ->respondWithMessage( $message ); |
|
41 | - |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * Update action is succeed |
|
46 | - * @author Shima Payro <[email protected]> |
|
47 | - * @param String $message |
|
48 | - * @since May 2, 2016 9:52:52 AM |
|
49 | - * @uses |
|
50 | - * @see |
|
51 | - */ |
|
52 | - public function updateSucceeded( $message ) { |
|
53 | - |
|
54 | - if ( empty( $message ) ) |
|
55 | - $message = $this->config[ 'success' ][ 'update' ]; |
|
56 | - |
|
57 | - return $this->setStatusCode( 200 ) |
|
58 | - ->setStatusText( 'success' ) |
|
59 | - ->respondWithMessage( $message ); |
|
60 | - |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Insert action is succeed |
|
65 | - * @author Shima Payro <[email protected]> |
|
66 | - * @param String $message |
|
67 | - * @since May 2, 2016 9:53:26 AM |
|
68 | - * @uses |
|
69 | - * @see |
|
70 | - */ |
|
71 | - public function insertSucceeded( $message ) { |
|
72 | - |
|
73 | - if ( empty( $message ) ) |
|
74 | - $message = $this->config[ 'success' ][ 'insert' ]; |
|
75 | - |
|
76 | - return $this->setStatusCode( 200 ) |
|
77 | - ->setStatusText( 'success' ) |
|
78 | - ->respondWithMessage( $message ); |
|
79 | - |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Delete action is faild |
|
84 | - * @author Shima Payro <[email protected]> |
|
85 | - * @param String $message |
|
86 | - * @since May 2, 2016 9:53:53 AM |
|
87 | - * @uses |
|
88 | - * @see |
|
89 | - */ |
|
90 | - public function deleteFaild( $message ) { |
|
91 | - |
|
92 | - return $this->setStatusCode( 447 ) |
|
93 | - ->setStatusText( 'fail' ) |
|
94 | - ->setErrorCode( 5447 ) |
|
95 | - ->respondWithMessage( $message ); |
|
96 | - |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Update action is succeed |
|
101 | - * @author Shima Payro <[email protected]> |
|
102 | - * @param String $message |
|
103 | - * @since May 2, 2016 9:54:09 AM |
|
104 | - * @uses |
|
105 | - * @see |
|
106 | - */ |
|
107 | - public function updateFaild( $message ) { |
|
108 | - |
|
109 | - return $this->setStatusCode( 449 ) |
|
110 | - ->setStatusText( 'fail' ) |
|
111 | - ->setErrorCode( 5449 ) |
|
112 | - ->respondWithMessage( $message ); |
|
113 | - |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Insert action is faild |
|
118 | - * @author Shima Payro <[email protected]> |
|
119 | - * @param String $message |
|
120 | - * @since May 2, 2016 9:54:27 AM |
|
121 | - * @uses |
|
122 | - * @see |
|
123 | - */ |
|
124 | - public function insertFaild( $message ) { |
|
125 | - |
|
126 | - return $this->setStatusCode( 448 ) |
|
127 | - ->setStatusText( 'fail' ) |
|
128 | - ->setErrorCode( 5448 ) |
|
129 | - ->respondWithMessage( $message ); |
|
130 | - |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Database connection is refused |
|
135 | - * @author Shima Payro <[email protected]> |
|
136 | - * @param String $message |
|
137 | - * @since May 2, 2016 9:54:45 AM |
|
138 | - * @uses |
|
139 | - * @see |
|
140 | - */ |
|
141 | - public function connectionRefused() { |
|
142 | - |
|
143 | - return $this->setStatusCode( 445 ) |
|
144 | - ->setStatusText( 'fail' ) |
|
145 | - ->setErrorCode( 5445 ) |
|
146 | - ->respondWithMessage(); |
|
147 | - |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * page requested is not found |
|
152 | - * @author Shima Payro <[email protected]> |
|
153 | - * @param String $message |
|
154 | - * @since May 2, 2016 9:55:20 AM |
|
155 | - * @uses |
|
156 | - * @see |
|
157 | - */ |
|
158 | - public function notFound() { |
|
159 | - |
|
160 | - return $this->setStatusCode( 404 ) |
|
161 | - ->setStatusText( 'fail' ) |
|
162 | - ->setErrorCode( 5404 ) |
|
163 | - ->respondWithMessage(); |
|
164 | - |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Wrong parameters are entered |
|
169 | - * @author Shima Payro <[email protected]> |
|
170 | - * @param String $message |
|
171 | - * @since May 2, 2016 9:55:20 AM |
|
172 | - * @uses |
|
173 | - * @see |
|
174 | - */ |
|
175 | - public function wrongParameters() { |
|
176 | - |
|
177 | - return $this->setStatusCode( 406 ) |
|
178 | - ->setStatusText( 'fail' ) |
|
179 | - ->setErrorCode( 5406 ) |
|
180 | - ->respondWithMessage(); |
|
181 | - |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Method is not allowed |
|
186 | - * @author Shima Payro <[email protected]> |
|
187 | - * @param String $message |
|
188 | - * @since May 2, 2016 9:55:20 AM |
|
189 | - * @uses |
|
190 | - * @see |
|
191 | - */ |
|
192 | - public function methodNotAllowed() { |
|
193 | - |
|
194 | - return $this->setStatusCode( 405 ) |
|
195 | - ->setStatusText( 'fail' ) |
|
196 | - ->setErrorCode( 5405 ) |
|
197 | - ->respondWithMessage(); |
|
198 | - |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * There ara validation errors |
|
203 | - * @author Shima Payro <[email protected]> |
|
204 | - * @param Array $data |
|
205 | - * @since May 2, 2016 9:55:20 AM |
|
206 | - * @uses |
|
207 | - * @see |
|
208 | - */ |
|
209 | - public function validationErrors( $data ) { |
|
210 | - |
|
211 | - return $this->setStatusCode( 420 ) |
|
212 | - ->setStatusText( 'fail' ) |
|
213 | - ->setErrorCode( 5420 ) |
|
214 | - ->respondWithResult( $data ); |
|
215 | - |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * The request field is not found |
|
220 | - * @author Shima Payro <[email protected]> |
|
221 | - * @param String $message |
|
222 | - * @since May 2, 2016 9:55:20 AM |
|
223 | - * @uses |
|
224 | - * @see |
|
225 | - */ |
|
226 | - public function requestFieldNotFound() { |
|
227 | - |
|
228 | - return $this->setStatusCode( 446 ) |
|
229 | - ->setStatusText( 'fail' ) |
|
230 | - ->setErrorCode( 1001 ) |
|
231 | - ->respondWithMessage(); |
|
232 | - |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * The request field is doublicated |
|
237 | - * @author Mehdi Hosseini <[email protected]> |
|
238 | - * @since August 24, 2016 |
|
239 | - * @return json |
|
240 | - */ |
|
241 | - public function requestFieldDuplicated() { |
|
242 | - |
|
243 | - return $this->setStatusCode( 400 ) |
|
244 | - ->setStatusText( 'fail' ) |
|
245 | - ->SetErrorCode(1004) |
|
246 | - ->respondWithMessage(); |
|
247 | - |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Custom error message according to error config file |
|
252 | - * @author Mehdi Hosseini <[email protected]> |
|
253 | - * @since August 24, 2016 |
|
254 | - * @param $code integer |
|
255 | - * @return json |
|
256 | - */ |
|
257 | - public function error( $code ) { |
|
258 | - |
|
259 | - return $this->SetStatusCode( 400 ) |
|
260 | - ->setStatusText( 'fail' ) |
|
261 | - ->setErrorCode( $code ) |
|
262 | - ->respondWithMessage(); |
|
263 | - |
|
264 | - } |
|
9 | + /** |
|
10 | + * Request succeeded and contains json result |
|
11 | + * @param array $data |
|
12 | + * @author Shima Payro <[email protected]> |
|
13 | + * @since May 2, 2016 9:50:51 AM |
|
14 | + * @uses |
|
15 | + * @see |
|
16 | + */ |
|
17 | + public function succeed( $data ) { |
|
18 | + |
|
19 | + return $this->setStatusCode( 200 ) |
|
20 | + ->setStatusText( 'success' ) |
|
21 | + ->respondWithResult( $data ); |
|
22 | + |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * Delete action is succeed |
|
27 | + * @author Shima Payro <[email protected]> |
|
28 | + * @param String $message |
|
29 | + * @since May 2, 2016 9:52:05 AM |
|
30 | + * @uses |
|
31 | + * @see |
|
32 | + */ |
|
33 | + public function deleteSucceeded( $message ) { |
|
34 | + |
|
35 | + if ( empty( $message ) ) |
|
36 | + $message = $this->config[ 'success' ][ 'delete' ]; |
|
37 | + |
|
38 | + return $this->setStatusCode( 200 ) |
|
39 | + ->setStatusText( 'success' ) |
|
40 | + ->respondWithMessage( $message ); |
|
41 | + |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * Update action is succeed |
|
46 | + * @author Shima Payro <[email protected]> |
|
47 | + * @param String $message |
|
48 | + * @since May 2, 2016 9:52:52 AM |
|
49 | + * @uses |
|
50 | + * @see |
|
51 | + */ |
|
52 | + public function updateSucceeded( $message ) { |
|
53 | + |
|
54 | + if ( empty( $message ) ) |
|
55 | + $message = $this->config[ 'success' ][ 'update' ]; |
|
56 | + |
|
57 | + return $this->setStatusCode( 200 ) |
|
58 | + ->setStatusText( 'success' ) |
|
59 | + ->respondWithMessage( $message ); |
|
60 | + |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Insert action is succeed |
|
65 | + * @author Shima Payro <[email protected]> |
|
66 | + * @param String $message |
|
67 | + * @since May 2, 2016 9:53:26 AM |
|
68 | + * @uses |
|
69 | + * @see |
|
70 | + */ |
|
71 | + public function insertSucceeded( $message ) { |
|
72 | + |
|
73 | + if ( empty( $message ) ) |
|
74 | + $message = $this->config[ 'success' ][ 'insert' ]; |
|
75 | + |
|
76 | + return $this->setStatusCode( 200 ) |
|
77 | + ->setStatusText( 'success' ) |
|
78 | + ->respondWithMessage( $message ); |
|
79 | + |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Delete action is faild |
|
84 | + * @author Shima Payro <[email protected]> |
|
85 | + * @param String $message |
|
86 | + * @since May 2, 2016 9:53:53 AM |
|
87 | + * @uses |
|
88 | + * @see |
|
89 | + */ |
|
90 | + public function deleteFaild( $message ) { |
|
91 | + |
|
92 | + return $this->setStatusCode( 447 ) |
|
93 | + ->setStatusText( 'fail' ) |
|
94 | + ->setErrorCode( 5447 ) |
|
95 | + ->respondWithMessage( $message ); |
|
96 | + |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Update action is succeed |
|
101 | + * @author Shima Payro <[email protected]> |
|
102 | + * @param String $message |
|
103 | + * @since May 2, 2016 9:54:09 AM |
|
104 | + * @uses |
|
105 | + * @see |
|
106 | + */ |
|
107 | + public function updateFaild( $message ) { |
|
108 | + |
|
109 | + return $this->setStatusCode( 449 ) |
|
110 | + ->setStatusText( 'fail' ) |
|
111 | + ->setErrorCode( 5449 ) |
|
112 | + ->respondWithMessage( $message ); |
|
113 | + |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Insert action is faild |
|
118 | + * @author Shima Payro <[email protected]> |
|
119 | + * @param String $message |
|
120 | + * @since May 2, 2016 9:54:27 AM |
|
121 | + * @uses |
|
122 | + * @see |
|
123 | + */ |
|
124 | + public function insertFaild( $message ) { |
|
125 | + |
|
126 | + return $this->setStatusCode( 448 ) |
|
127 | + ->setStatusText( 'fail' ) |
|
128 | + ->setErrorCode( 5448 ) |
|
129 | + ->respondWithMessage( $message ); |
|
130 | + |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Database connection is refused |
|
135 | + * @author Shima Payro <[email protected]> |
|
136 | + * @param String $message |
|
137 | + * @since May 2, 2016 9:54:45 AM |
|
138 | + * @uses |
|
139 | + * @see |
|
140 | + */ |
|
141 | + public function connectionRefused() { |
|
142 | + |
|
143 | + return $this->setStatusCode( 445 ) |
|
144 | + ->setStatusText( 'fail' ) |
|
145 | + ->setErrorCode( 5445 ) |
|
146 | + ->respondWithMessage(); |
|
147 | + |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * page requested is not found |
|
152 | + * @author Shima Payro <[email protected]> |
|
153 | + * @param String $message |
|
154 | + * @since May 2, 2016 9:55:20 AM |
|
155 | + * @uses |
|
156 | + * @see |
|
157 | + */ |
|
158 | + public function notFound() { |
|
159 | + |
|
160 | + return $this->setStatusCode( 404 ) |
|
161 | + ->setStatusText( 'fail' ) |
|
162 | + ->setErrorCode( 5404 ) |
|
163 | + ->respondWithMessage(); |
|
164 | + |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Wrong parameters are entered |
|
169 | + * @author Shima Payro <[email protected]> |
|
170 | + * @param String $message |
|
171 | + * @since May 2, 2016 9:55:20 AM |
|
172 | + * @uses |
|
173 | + * @see |
|
174 | + */ |
|
175 | + public function wrongParameters() { |
|
176 | + |
|
177 | + return $this->setStatusCode( 406 ) |
|
178 | + ->setStatusText( 'fail' ) |
|
179 | + ->setErrorCode( 5406 ) |
|
180 | + ->respondWithMessage(); |
|
181 | + |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Method is not allowed |
|
186 | + * @author Shima Payro <[email protected]> |
|
187 | + * @param String $message |
|
188 | + * @since May 2, 2016 9:55:20 AM |
|
189 | + * @uses |
|
190 | + * @see |
|
191 | + */ |
|
192 | + public function methodNotAllowed() { |
|
193 | + |
|
194 | + return $this->setStatusCode( 405 ) |
|
195 | + ->setStatusText( 'fail' ) |
|
196 | + ->setErrorCode( 5405 ) |
|
197 | + ->respondWithMessage(); |
|
198 | + |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * There ara validation errors |
|
203 | + * @author Shima Payro <[email protected]> |
|
204 | + * @param Array $data |
|
205 | + * @since May 2, 2016 9:55:20 AM |
|
206 | + * @uses |
|
207 | + * @see |
|
208 | + */ |
|
209 | + public function validationErrors( $data ) { |
|
210 | + |
|
211 | + return $this->setStatusCode( 420 ) |
|
212 | + ->setStatusText( 'fail' ) |
|
213 | + ->setErrorCode( 5420 ) |
|
214 | + ->respondWithResult( $data ); |
|
215 | + |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * The request field is not found |
|
220 | + * @author Shima Payro <[email protected]> |
|
221 | + * @param String $message |
|
222 | + * @since May 2, 2016 9:55:20 AM |
|
223 | + * @uses |
|
224 | + * @see |
|
225 | + */ |
|
226 | + public function requestFieldNotFound() { |
|
227 | + |
|
228 | + return $this->setStatusCode( 446 ) |
|
229 | + ->setStatusText( 'fail' ) |
|
230 | + ->setErrorCode( 1001 ) |
|
231 | + ->respondWithMessage(); |
|
232 | + |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * The request field is doublicated |
|
237 | + * @author Mehdi Hosseini <[email protected]> |
|
238 | + * @since August 24, 2016 |
|
239 | + * @return json |
|
240 | + */ |
|
241 | + public function requestFieldDuplicated() { |
|
242 | + |
|
243 | + return $this->setStatusCode( 400 ) |
|
244 | + ->setStatusText( 'fail' ) |
|
245 | + ->SetErrorCode(1004) |
|
246 | + ->respondWithMessage(); |
|
247 | + |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Custom error message according to error config file |
|
252 | + * @author Mehdi Hosseini <[email protected]> |
|
253 | + * @since August 24, 2016 |
|
254 | + * @param $code integer |
|
255 | + * @return json |
|
256 | + */ |
|
257 | + public function error( $code ) { |
|
258 | + |
|
259 | + return $this->SetStatusCode( 400 ) |
|
260 | + ->setStatusText( 'fail' ) |
|
261 | + ->setErrorCode( $code ) |
|
262 | + ->respondWithMessage(); |
|
263 | + |
|
264 | + } |
|
265 | 265 | |
266 | 266 | |
267 | 267 | } |
@@ -14,11 +14,11 @@ discard block |
||
14 | 14 | * @uses |
15 | 15 | * @see |
16 | 16 | */ |
17 | - public function succeed( $data ) { |
|
17 | + public function succeed($data) { |
|
18 | 18 | |
19 | - return $this->setStatusCode( 200 ) |
|
20 | - ->setStatusText( 'success' ) |
|
21 | - ->respondWithResult( $data ); |
|
19 | + return $this->setStatusCode(200) |
|
20 | + ->setStatusText('success') |
|
21 | + ->respondWithResult($data); |
|
22 | 22 | |
23 | 23 | } |
24 | 24 | |
@@ -30,14 +30,14 @@ discard block |
||
30 | 30 | * @uses |
31 | 31 | * @see |
32 | 32 | */ |
33 | - public function deleteSucceeded( $message ) { |
|
33 | + public function deleteSucceeded($message) { |
|
34 | 34 | |
35 | - if ( empty( $message ) ) |
|
35 | + if (empty($message)) |
|
36 | 36 | $message = $this->config[ 'success' ][ 'delete' ]; |
37 | 37 | |
38 | - return $this->setStatusCode( 200 ) |
|
39 | - ->setStatusText( 'success' ) |
|
40 | - ->respondWithMessage( $message ); |
|
38 | + return $this->setStatusCode(200) |
|
39 | + ->setStatusText('success') |
|
40 | + ->respondWithMessage($message); |
|
41 | 41 | |
42 | 42 | } |
43 | 43 | |
@@ -49,14 +49,14 @@ discard block |
||
49 | 49 | * @uses |
50 | 50 | * @see |
51 | 51 | */ |
52 | - public function updateSucceeded( $message ) { |
|
52 | + public function updateSucceeded($message) { |
|
53 | 53 | |
54 | - if ( empty( $message ) ) |
|
54 | + if (empty($message)) |
|
55 | 55 | $message = $this->config[ 'success' ][ 'update' ]; |
56 | 56 | |
57 | - return $this->setStatusCode( 200 ) |
|
58 | - ->setStatusText( 'success' ) |
|
59 | - ->respondWithMessage( $message ); |
|
57 | + return $this->setStatusCode(200) |
|
58 | + ->setStatusText('success') |
|
59 | + ->respondWithMessage($message); |
|
60 | 60 | |
61 | 61 | } |
62 | 62 | |
@@ -68,14 +68,14 @@ discard block |
||
68 | 68 | * @uses |
69 | 69 | * @see |
70 | 70 | */ |
71 | - public function insertSucceeded( $message ) { |
|
71 | + public function insertSucceeded($message) { |
|
72 | 72 | |
73 | - if ( empty( $message ) ) |
|
73 | + if (empty($message)) |
|
74 | 74 | $message = $this->config[ 'success' ][ 'insert' ]; |
75 | 75 | |
76 | - return $this->setStatusCode( 200 ) |
|
77 | - ->setStatusText( 'success' ) |
|
78 | - ->respondWithMessage( $message ); |
|
76 | + return $this->setStatusCode(200) |
|
77 | + ->setStatusText('success') |
|
78 | + ->respondWithMessage($message); |
|
79 | 79 | |
80 | 80 | } |
81 | 81 | |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | * @uses |
88 | 88 | * @see |
89 | 89 | */ |
90 | - public function deleteFaild( $message ) { |
|
90 | + public function deleteFaild($message) { |
|
91 | 91 | |
92 | - return $this->setStatusCode( 447 ) |
|
93 | - ->setStatusText( 'fail' ) |
|
94 | - ->setErrorCode( 5447 ) |
|
95 | - ->respondWithMessage( $message ); |
|
92 | + return $this->setStatusCode(447) |
|
93 | + ->setStatusText('fail') |
|
94 | + ->setErrorCode(5447) |
|
95 | + ->respondWithMessage($message); |
|
96 | 96 | |
97 | 97 | } |
98 | 98 | |
@@ -104,12 +104,12 @@ discard block |
||
104 | 104 | * @uses |
105 | 105 | * @see |
106 | 106 | */ |
107 | - public function updateFaild( $message ) { |
|
107 | + public function updateFaild($message) { |
|
108 | 108 | |
109 | - return $this->setStatusCode( 449 ) |
|
110 | - ->setStatusText( 'fail' ) |
|
111 | - ->setErrorCode( 5449 ) |
|
112 | - ->respondWithMessage( $message ); |
|
109 | + return $this->setStatusCode(449) |
|
110 | + ->setStatusText('fail') |
|
111 | + ->setErrorCode(5449) |
|
112 | + ->respondWithMessage($message); |
|
113 | 113 | |
114 | 114 | } |
115 | 115 | |
@@ -121,12 +121,12 @@ discard block |
||
121 | 121 | * @uses |
122 | 122 | * @see |
123 | 123 | */ |
124 | - public function insertFaild( $message ) { |
|
124 | + public function insertFaild($message) { |
|
125 | 125 | |
126 | - return $this->setStatusCode( 448 ) |
|
127 | - ->setStatusText( 'fail' ) |
|
128 | - ->setErrorCode( 5448 ) |
|
129 | - ->respondWithMessage( $message ); |
|
126 | + return $this->setStatusCode(448) |
|
127 | + ->setStatusText('fail') |
|
128 | + ->setErrorCode(5448) |
|
129 | + ->respondWithMessage($message); |
|
130 | 130 | |
131 | 131 | } |
132 | 132 | |
@@ -140,9 +140,9 @@ discard block |
||
140 | 140 | */ |
141 | 141 | public function connectionRefused() { |
142 | 142 | |
143 | - return $this->setStatusCode( 445 ) |
|
144 | - ->setStatusText( 'fail' ) |
|
145 | - ->setErrorCode( 5445 ) |
|
143 | + return $this->setStatusCode(445) |
|
144 | + ->setStatusText('fail') |
|
145 | + ->setErrorCode(5445) |
|
146 | 146 | ->respondWithMessage(); |
147 | 147 | |
148 | 148 | } |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | */ |
158 | 158 | public function notFound() { |
159 | 159 | |
160 | - return $this->setStatusCode( 404 ) |
|
161 | - ->setStatusText( 'fail' ) |
|
162 | - ->setErrorCode( 5404 ) |
|
160 | + return $this->setStatusCode(404) |
|
161 | + ->setStatusText('fail') |
|
162 | + ->setErrorCode(5404) |
|
163 | 163 | ->respondWithMessage(); |
164 | 164 | |
165 | 165 | } |
@@ -174,9 +174,9 @@ discard block |
||
174 | 174 | */ |
175 | 175 | public function wrongParameters() { |
176 | 176 | |
177 | - return $this->setStatusCode( 406 ) |
|
178 | - ->setStatusText( 'fail' ) |
|
179 | - ->setErrorCode( 5406 ) |
|
177 | + return $this->setStatusCode(406) |
|
178 | + ->setStatusText('fail') |
|
179 | + ->setErrorCode(5406) |
|
180 | 180 | ->respondWithMessage(); |
181 | 181 | |
182 | 182 | } |
@@ -191,9 +191,9 @@ discard block |
||
191 | 191 | */ |
192 | 192 | public function methodNotAllowed() { |
193 | 193 | |
194 | - return $this->setStatusCode( 405 ) |
|
195 | - ->setStatusText( 'fail' ) |
|
196 | - ->setErrorCode( 5405 ) |
|
194 | + return $this->setStatusCode(405) |
|
195 | + ->setStatusText('fail') |
|
196 | + ->setErrorCode(5405) |
|
197 | 197 | ->respondWithMessage(); |
198 | 198 | |
199 | 199 | } |
@@ -206,12 +206,12 @@ discard block |
||
206 | 206 | * @uses |
207 | 207 | * @see |
208 | 208 | */ |
209 | - public function validationErrors( $data ) { |
|
209 | + public function validationErrors($data) { |
|
210 | 210 | |
211 | - return $this->setStatusCode( 420 ) |
|
212 | - ->setStatusText( 'fail' ) |
|
213 | - ->setErrorCode( 5420 ) |
|
214 | - ->respondWithResult( $data ); |
|
211 | + return $this->setStatusCode(420) |
|
212 | + ->setStatusText('fail') |
|
213 | + ->setErrorCode(5420) |
|
214 | + ->respondWithResult($data); |
|
215 | 215 | |
216 | 216 | } |
217 | 217 | |
@@ -225,9 +225,9 @@ discard block |
||
225 | 225 | */ |
226 | 226 | public function requestFieldNotFound() { |
227 | 227 | |
228 | - return $this->setStatusCode( 446 ) |
|
229 | - ->setStatusText( 'fail' ) |
|
230 | - ->setErrorCode( 1001 ) |
|
228 | + return $this->setStatusCode(446) |
|
229 | + ->setStatusText('fail') |
|
230 | + ->setErrorCode(1001) |
|
231 | 231 | ->respondWithMessage(); |
232 | 232 | |
233 | 233 | } |
@@ -240,8 +240,8 @@ discard block |
||
240 | 240 | */ |
241 | 241 | public function requestFieldDuplicated() { |
242 | 242 | |
243 | - return $this->setStatusCode( 400 ) |
|
244 | - ->setStatusText( 'fail' ) |
|
243 | + return $this->setStatusCode(400) |
|
244 | + ->setStatusText('fail') |
|
245 | 245 | ->SetErrorCode(1004) |
246 | 246 | ->respondWithMessage(); |
247 | 247 | |
@@ -254,11 +254,11 @@ discard block |
||
254 | 254 | * @param $code integer |
255 | 255 | * @return json |
256 | 256 | */ |
257 | - public function error( $code ) { |
|
257 | + public function error($code) { |
|
258 | 258 | |
259 | - return $this->SetStatusCode( 400 ) |
|
260 | - ->setStatusText( 'fail' ) |
|
261 | - ->setErrorCode( $code ) |
|
259 | + return $this->SetStatusCode(400) |
|
260 | + ->setStatusText('fail') |
|
261 | + ->setErrorCode($code) |
|
262 | 262 | ->respondWithMessage(); |
263 | 263 | |
264 | 264 | } |
@@ -6,267 +6,267 @@ |
||
6 | 6 | |
7 | 7 | class Main { |
8 | 8 | |
9 | - /** |
|
10 | - * Http status code |
|
11 | - * @var integer |
|
12 | - */ |
|
13 | - protected $statusCode = 200; |
|
14 | - |
|
15 | - /** |
|
16 | - * Status text |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - protected $statusText = 'success'; |
|
20 | - |
|
21 | - /** |
|
22 | - * Error code, message and text-key |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - protected $error; |
|
26 | - |
|
27 | - /** |
|
28 | - * Error code |
|
29 | - * @var integer |
|
30 | - */ |
|
31 | - protected $errorCode; |
|
32 | - |
|
33 | - /** |
|
34 | - * Haeders |
|
35 | - * @var array |
|
36 | - */ |
|
37 | - protected $headers = []; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - protected $lang; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var arry |
|
46 | - */ |
|
47 | - protected $config; |
|
48 | - |
|
49 | - /** |
|
50 | - * @author Shahrokh Niakan <[email protected]> |
|
51 | - * @since Sep 24, 2016 |
|
52 | - */ |
|
53 | - public function __construct() { |
|
54 | - |
|
55 | - |
|
56 | - $this->lang = \App::getLocale(); |
|
57 | - |
|
58 | - $this->config = include __DIR__ . '/../errors/lang/' . $this->lang . '.php'; |
|
59 | - |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Getter for $statusCode |
|
64 | - * @author Shima Payro <[email protected]> |
|
65 | - * @since May 2, 2016 9:46:27 AM |
|
66 | - * @uses |
|
67 | - * @see |
|
68 | - */ |
|
69 | - public function getStatusCode() { |
|
70 | - |
|
71 | - return $this->statusCode; |
|
72 | - |
|
73 | - } |
|
9 | + /** |
|
10 | + * Http status code |
|
11 | + * @var integer |
|
12 | + */ |
|
13 | + protected $statusCode = 200; |
|
14 | + |
|
15 | + /** |
|
16 | + * Status text |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + protected $statusText = 'success'; |
|
20 | + |
|
21 | + /** |
|
22 | + * Error code, message and text-key |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + protected $error; |
|
26 | + |
|
27 | + /** |
|
28 | + * Error code |
|
29 | + * @var integer |
|
30 | + */ |
|
31 | + protected $errorCode; |
|
32 | + |
|
33 | + /** |
|
34 | + * Haeders |
|
35 | + * @var array |
|
36 | + */ |
|
37 | + protected $headers = []; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + protected $lang; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var arry |
|
46 | + */ |
|
47 | + protected $config; |
|
48 | + |
|
49 | + /** |
|
50 | + * @author Shahrokh Niakan <[email protected]> |
|
51 | + * @since Sep 24, 2016 |
|
52 | + */ |
|
53 | + public function __construct() { |
|
54 | + |
|
55 | + |
|
56 | + $this->lang = \App::getLocale(); |
|
57 | + |
|
58 | + $this->config = include __DIR__ . '/../errors/lang/' . $this->lang . '.php'; |
|
59 | + |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Getter for $statusCode |
|
64 | + * @author Shima Payro <[email protected]> |
|
65 | + * @since May 2, 2016 9:46:27 AM |
|
66 | + * @uses |
|
67 | + * @see |
|
68 | + */ |
|
69 | + public function getStatusCode() { |
|
70 | + |
|
71 | + return $this->statusCode; |
|
72 | + |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Setter for $statusCode |
|
77 | - * @param integer $statusCode |
|
78 | - * @return App\Htpp\Responds\Respond |
|
79 | - * @author Shima Payro <[email protected]> |
|
80 | - * @since May 2, 2016 9:47:04 AM |
|
81 | - * @uses |
|
82 | - * @see |
|
83 | - */ |
|
84 | - public function setStatusCode( $statusCode ) { |
|
85 | - |
|
86 | - $this->statusCode = $statusCode; |
|
75 | + /** |
|
76 | + * Setter for $statusCode |
|
77 | + * @param integer $statusCode |
|
78 | + * @return App\Htpp\Responds\Respond |
|
79 | + * @author Shima Payro <[email protected]> |
|
80 | + * @since May 2, 2016 9:47:04 AM |
|
81 | + * @uses |
|
82 | + * @see |
|
83 | + */ |
|
84 | + public function setStatusCode( $statusCode ) { |
|
85 | + |
|
86 | + $this->statusCode = $statusCode; |
|
87 | 87 | |
88 | - return $this; |
|
88 | + return $this; |
|
89 | 89 | |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Getter for $statusText |
|
94 | - * @author Shima Payro <[email protected]> |
|
95 | - * @since May 2, 2016 9:47:36 AM |
|
96 | - * @uses |
|
97 | - * @see |
|
98 | - */ |
|
99 | - public function getStatusText() { |
|
92 | + /** |
|
93 | + * Getter for $statusText |
|
94 | + * @author Shima Payro <[email protected]> |
|
95 | + * @since May 2, 2016 9:47:36 AM |
|
96 | + * @uses |
|
97 | + * @see |
|
98 | + */ |
|
99 | + public function getStatusText() { |
|
100 | 100 | |
101 | - return $this->statusText; |
|
101 | + return $this->statusText; |
|
102 | 102 | |
103 | - } |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Setter for $statusText |
|
107 | - * @param String $statusText |
|
108 | - * @return App\HtppApp\Htpp\Responds\Respond |
|
109 | - * @author Shima Payro <[email protected]> |
|
110 | - * @since May 2, 2016 9:48:23 AM |
|
111 | - * @uses |
|
112 | - * @see |
|
113 | - */ |
|
114 | - public function setStatusText( $statusText ) { |
|
105 | + /** |
|
106 | + * Setter for $statusText |
|
107 | + * @param String $statusText |
|
108 | + * @return App\HtppApp\Htpp\Responds\Respond |
|
109 | + * @author Shima Payro <[email protected]> |
|
110 | + * @since May 2, 2016 9:48:23 AM |
|
111 | + * @uses |
|
112 | + * @see |
|
113 | + */ |
|
114 | + public function setStatusText( $statusText ) { |
|
115 | 115 | |
116 | - $this->statusText = $statusText; |
|
116 | + $this->statusText = $statusText; |
|
117 | 117 | |
118 | - return $this; |
|
118 | + return $this; |
|
119 | 119 | |
120 | - } |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Response |
|
124 | - * @param json $data |
|
125 | - * @return jsom |
|
126 | - * @author Shima Payro <[email protected]> |
|
127 | - * @since May 2, 2016 9:48:45 AM |
|
128 | - * @uses |
|
129 | - * @see |
|
130 | - */ |
|
131 | - public function respond( $data ) { |
|
122 | + /** |
|
123 | + * Response |
|
124 | + * @param json $data |
|
125 | + * @return jsom |
|
126 | + * @author Shima Payro <[email protected]> |
|
127 | + * @since May 2, 2016 9:48:45 AM |
|
128 | + * @uses |
|
129 | + * @see |
|
130 | + */ |
|
131 | + public function respond( $data ) { |
|
132 | 132 | |
133 | - $result = array_filter( $this->getHeaders() ); |
|
133 | + $result = array_filter( $this->getHeaders() ); |
|
134 | 134 | |
135 | - if ( empty( $result ) ) |
|
136 | - return response()->json( $data, $this->getStatusCode() ); |
|
135 | + if ( empty( $result ) ) |
|
136 | + return response()->json( $data, $this->getStatusCode() ); |
|
137 | 137 | |
138 | - return response()->json( $data, $this->getStatusCode() ) |
|
139 | - ->withHeaders( $this->getHeaders() ); |
|
138 | + return response()->json( $data, $this->getStatusCode() ) |
|
139 | + ->withHeaders( $this->getHeaders() ); |
|
140 | 140 | |
141 | - } |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * Response which conteins just a message |
|
145 | - * @param string $message |
|
146 | - * @author Shima Payro <[email protected]> |
|
147 | - * @since May 2, 2016 9:49:21 AM |
|
148 | - * @return json |
|
149 | - * @uses |
|
150 | - * @see |
|
151 | - */ |
|
152 | - public function respondWithMessage( $message ) { |
|
143 | + /** |
|
144 | + * Response which conteins just a message |
|
145 | + * @param string $message |
|
146 | + * @author Shima Payro <[email protected]> |
|
147 | + * @since May 2, 2016 9:49:21 AM |
|
148 | + * @return json |
|
149 | + * @uses |
|
150 | + * @see |
|
151 | + */ |
|
152 | + public function respondWithMessage( $message ) { |
|
153 | 153 | |
154 | - $res[ 'status' ] = $this->getStatusText(); |
|
154 | + $res[ 'status' ] = $this->getStatusText(); |
|
155 | 155 | |
156 | - //if it's about failure |
|
157 | - if ( $this->getErrorCode() ) { |
|
156 | + //if it's about failure |
|
157 | + if ( $this->getErrorCode() ) { |
|
158 | 158 | |
159 | - $res[ 'error' ] = $this->getErrorCode(); |
|
159 | + $res[ 'error' ] = $this->getErrorCode(); |
|
160 | 160 | |
161 | - if ( empty( $message ) ) |
|
162 | - $res[ 'message' ] = $this->getErrorMessage(); |
|
161 | + if ( empty( $message ) ) |
|
162 | + $res[ 'message' ] = $this->getErrorMessage(); |
|
163 | 163 | |
164 | - $res[ 'message' ] = $message; |
|
164 | + $res[ 'message' ] = $message; |
|
165 | 165 | |
166 | - } else { |
|
166 | + } else { |
|
167 | 167 | |
168 | - $res[ 'message' ] = $message; |
|
168 | + $res[ 'message' ] = $message; |
|
169 | 169 | |
170 | - } |
|
170 | + } |
|
171 | 171 | |
172 | - return $this->respond( $res ); |
|
172 | + return $this->respond( $res ); |
|
173 | 173 | |
174 | - } |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * Set error code in our result |
|
178 | - * @author Mehdi Hosseini <[email protected]> |
|
179 | - * @since August 24, 2016 |
|
180 | - * @param $errorCode integer |
|
181 | - * @return instance |
|
182 | - */ |
|
183 | - public function setErrorCode( $errorCode ) { |
|
176 | + /** |
|
177 | + * Set error code in our result |
|
178 | + * @author Mehdi Hosseini <[email protected]> |
|
179 | + * @since August 24, 2016 |
|
180 | + * @param $errorCode integer |
|
181 | + * @return instance |
|
182 | + */ |
|
183 | + public function setErrorCode( $errorCode ) { |
|
184 | 184 | |
185 | - $this->error = $this->config[ $errorCode ]; |
|
185 | + $this->error = $this->config[ $errorCode ]; |
|
186 | 186 | |
187 | - $this->errorCode = $errorCode; |
|
187 | + $this->errorCode = $errorCode; |
|
188 | 188 | |
189 | - return $this; |
|
189 | + return $this; |
|
190 | 190 | |
191 | - } |
|
191 | + } |
|
192 | 192 | |
193 | - /** |
|
194 | - * Return Error code |
|
195 | - * @author Mehdi Hosseini <[email protected]> |
|
196 | - * @since August 24, 2016 |
|
197 | - * @return integer |
|
198 | - */ |
|
199 | - public function getErrorCode() { |
|
193 | + /** |
|
194 | + * Return Error code |
|
195 | + * @author Mehdi Hosseini <[email protected]> |
|
196 | + * @since August 24, 2016 |
|
197 | + * @return integer |
|
198 | + */ |
|
199 | + public function getErrorCode() { |
|
200 | 200 | |
201 | - return $this->errorCode; |
|
201 | + return $this->errorCode; |
|
202 | 202 | |
203 | - } |
|
203 | + } |
|
204 | 204 | |
205 | - /** |
|
206 | - * Get error message |
|
207 | - * @author Mehdi Hosseini <[email protected]> |
|
208 | - * @since August 24, 2016 |
|
209 | - * @return string |
|
210 | - */ |
|
211 | - public function getErrorMessage() { |
|
205 | + /** |
|
206 | + * Get error message |
|
207 | + * @author Mehdi Hosseini <[email protected]> |
|
208 | + * @since August 24, 2016 |
|
209 | + * @return string |
|
210 | + */ |
|
211 | + public function getErrorMessage() { |
|
212 | 212 | |
213 | - return $this->error['message']; |
|
213 | + return $this->error['message']; |
|
214 | 214 | |
215 | - } |
|
215 | + } |
|
216 | 216 | |
217 | - /** |
|
218 | - * Get headers |
|
219 | - * @author Shima Payro <[email protected]> |
|
220 | - * @since Sep 13, 2016 |
|
221 | - * @return array |
|
222 | - */ |
|
223 | - public function getHeaders() { |
|
217 | + /** |
|
218 | + * Get headers |
|
219 | + * @author Shima Payro <[email protected]> |
|
220 | + * @since Sep 13, 2016 |
|
221 | + * @return array |
|
222 | + */ |
|
223 | + public function getHeaders() { |
|
224 | 224 | |
225 | - return $this->headers; |
|
225 | + return $this->headers; |
|
226 | 226 | |
227 | - } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * Set headers |
|
231 | - * @author Shima Payro <[email protected]> |
|
232 | - * @since Sep 13, 2016 |
|
233 | - * @return array |
|
234 | - */ |
|
235 | - public function setHeaders( $headers = [] ) { |
|
229 | + /** |
|
230 | + * Set headers |
|
231 | + * @author Shima Payro <[email protected]> |
|
232 | + * @since Sep 13, 2016 |
|
233 | + * @return array |
|
234 | + */ |
|
235 | + public function setHeaders( $headers = [] ) { |
|
236 | 236 | |
237 | - $this->headers = $headers; |
|
237 | + $this->headers = $headers; |
|
238 | 238 | |
239 | - return $this; |
|
239 | + return $this; |
|
240 | 240 | |
241 | - } |
|
241 | + } |
|
242 | 242 | |
243 | - /** |
|
244 | - * Response which contains status and data |
|
245 | - * @param json $data |
|
246 | - * @author Shima Payro <[email protected]> |
|
247 | - * @since May 2, 2016 9:50:19 AM |
|
248 | - * @return json |
|
249 | - * @uses |
|
250 | - * @see |
|
251 | - */ |
|
252 | - public function respondWithResult( $data = NULL ) { |
|
243 | + /** |
|
244 | + * Response which contains status and data |
|
245 | + * @param json $data |
|
246 | + * @author Shima Payro <[email protected]> |
|
247 | + * @since May 2, 2016 9:50:19 AM |
|
248 | + * @return json |
|
249 | + * @uses |
|
250 | + * @see |
|
251 | + */ |
|
252 | + public function respondWithResult( $data = NULL ) { |
|
253 | 253 | |
254 | - $res[ 'status' ] = $this->getStatusText(); |
|
254 | + $res[ 'status' ] = $this->getStatusText(); |
|
255 | 255 | |
256 | - //if it's about laravel validation error |
|
257 | - if ( $this->getErrorCode() && $this->getStatusCode() == 420 ) { |
|
256 | + //if it's about laravel validation error |
|
257 | + if ( $this->getErrorCode() && $this->getStatusCode() == 420 ) { |
|
258 | 258 | |
259 | - $res[ 'error' ] = $this->getErrorCode(); |
|
260 | - $res[ 'message' ] = $data; |
|
259 | + $res[ 'error' ] = $this->getErrorCode(); |
|
260 | + $res[ 'message' ] = $data; |
|
261 | 261 | |
262 | - } else { |
|
262 | + } else { |
|
263 | 263 | |
264 | - $res[ 'result' ] = $data; |
|
264 | + $res[ 'result' ] = $data; |
|
265 | 265 | |
266 | - } |
|
266 | + } |
|
267 | 267 | |
268 | - return $this->respond( $res ); |
|
268 | + return $this->respond( $res ); |
|
269 | 269 | |
270 | - } |
|
270 | + } |
|
271 | 271 | |
272 | 272 | } |