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