@@ -6,240 +6,240 @@ |
||
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 | - * Getter for $statusCode |
|
41 | - * @author Shima Payro <[email protected]> |
|
42 | - * @since May 2, 2016 9:46:27 AM |
|
43 | - * @uses |
|
44 | - * @see |
|
45 | - */ |
|
46 | - public function getStatusCode() { |
|
47 | - |
|
48 | - return $this->statusCode; |
|
49 | - |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Setter for $statusCode |
|
54 | - * @param integer $statusCode |
|
55 | - * @return App\Htpp\Responds\Respond |
|
56 | - * @author Shima Payro <[email protected]> |
|
57 | - * @since May 2, 2016 9:47:04 AM |
|
58 | - * @uses |
|
59 | - * @see |
|
60 | - */ |
|
61 | - public function setStatusCode( $statusCode ) { |
|
62 | - |
|
63 | - $this->statusCode = $statusCode; |
|
64 | - |
|
65 | - return $this; |
|
66 | - |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Getter for $statusText |
|
71 | - * @author Shima Payro <[email protected]> |
|
72 | - * @since May 2, 2016 9:47:36 AM |
|
73 | - * @uses |
|
74 | - * @see |
|
75 | - */ |
|
76 | - public function getStatusText() { |
|
77 | - |
|
78 | - return $this->statusText; |
|
79 | - |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Setter for $statusText |
|
84 | - * @param String $statusText |
|
85 | - * @return App\HtppApp\Htpp\Responds\Respond |
|
86 | - * @author Shima Payro <[email protected]> |
|
87 | - * @since May 2, 2016 9:48:23 AM |
|
88 | - * @uses |
|
89 | - * @see |
|
90 | - */ |
|
91 | - public function setStatusText( $statusText ) { |
|
92 | - |
|
93 | - $this->statusText = $statusText; |
|
94 | - |
|
95 | - return $this; |
|
96 | - |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Response |
|
101 | - * @param json $data |
|
102 | - * @return jsom |
|
103 | - * @author Shima Payro <[email protected]> |
|
104 | - * @since May 2, 2016 9:48:45 AM |
|
105 | - * @uses |
|
106 | - * @see |
|
107 | - */ |
|
108 | - public function respond( $data ) { |
|
109 | - |
|
110 | - $result = array_filter( $this->getHeaders() ); |
|
111 | - |
|
112 | - if ( empty( $result ) ); |
|
113 | - return response()->json( $data, $this->getStatusCode() ); |
|
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 | + * Getter for $statusCode |
|
41 | + * @author Shima Payro <[email protected]> |
|
42 | + * @since May 2, 2016 9:46:27 AM |
|
43 | + * @uses |
|
44 | + * @see |
|
45 | + */ |
|
46 | + public function getStatusCode() { |
|
47 | + |
|
48 | + return $this->statusCode; |
|
49 | + |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Setter for $statusCode |
|
54 | + * @param integer $statusCode |
|
55 | + * @return App\Htpp\Responds\Respond |
|
56 | + * @author Shima Payro <[email protected]> |
|
57 | + * @since May 2, 2016 9:47:04 AM |
|
58 | + * @uses |
|
59 | + * @see |
|
60 | + */ |
|
61 | + public function setStatusCode( $statusCode ) { |
|
62 | + |
|
63 | + $this->statusCode = $statusCode; |
|
64 | + |
|
65 | + return $this; |
|
66 | + |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Getter for $statusText |
|
71 | + * @author Shima Payro <[email protected]> |
|
72 | + * @since May 2, 2016 9:47:36 AM |
|
73 | + * @uses |
|
74 | + * @see |
|
75 | + */ |
|
76 | + public function getStatusText() { |
|
77 | + |
|
78 | + return $this->statusText; |
|
79 | + |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Setter for $statusText |
|
84 | + * @param String $statusText |
|
85 | + * @return App\HtppApp\Htpp\Responds\Respond |
|
86 | + * @author Shima Payro <[email protected]> |
|
87 | + * @since May 2, 2016 9:48:23 AM |
|
88 | + * @uses |
|
89 | + * @see |
|
90 | + */ |
|
91 | + public function setStatusText( $statusText ) { |
|
92 | + |
|
93 | + $this->statusText = $statusText; |
|
94 | + |
|
95 | + return $this; |
|
96 | + |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Response |
|
101 | + * @param json $data |
|
102 | + * @return jsom |
|
103 | + * @author Shima Payro <[email protected]> |
|
104 | + * @since May 2, 2016 9:48:45 AM |
|
105 | + * @uses |
|
106 | + * @see |
|
107 | + */ |
|
108 | + public function respond( $data ) { |
|
109 | + |
|
110 | + $result = array_filter( $this->getHeaders() ); |
|
111 | + |
|
112 | + if ( empty( $result ) ); |
|
113 | + return response()->json( $data, $this->getStatusCode() ); |
|
114 | 114 | |
115 | - return response()->json( $data, $this->getStatusCode() ) |
|
116 | - ->withHeaders( $this->getHeaders() ); |
|
115 | + return response()->json( $data, $this->getStatusCode() ) |
|
116 | + ->withHeaders( $this->getHeaders() ); |
|
117 | 117 | |
118 | - } |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Response which conteins just a message |
|
122 | - * @param string $message |
|
123 | - * @author Shima Payro <[email protected]> |
|
124 | - * @since May 2, 2016 9:49:21 AM |
|
125 | - * @return json |
|
126 | - * @uses |
|
127 | - * @see |
|
128 | - */ |
|
129 | - public function respondWithMessage( $message = NULL ) { |
|
120 | + /** |
|
121 | + * Response which conteins just a message |
|
122 | + * @param string $message |
|
123 | + * @author Shima Payro <[email protected]> |
|
124 | + * @since May 2, 2016 9:49:21 AM |
|
125 | + * @return json |
|
126 | + * @uses |
|
127 | + * @see |
|
128 | + */ |
|
129 | + public function respondWithMessage( $message = NULL ) { |
|
130 | 130 | |
131 | - $res[ 'status' ] = $this->getStatusText(); |
|
131 | + $res[ 'status' ] = $this->getStatusText(); |
|
132 | 132 | |
133 | - //if it's about failure |
|
134 | - if ( $this->getErrorCode() ) { |
|
133 | + //if it's about failure |
|
134 | + if ( $this->getErrorCode() ) { |
|
135 | 135 | |
136 | - $res[ 'error' ] = $this->getErrorCode(); |
|
137 | - $res[ 'message' ] = $this->getErrorMessage(); |
|
136 | + $res[ 'error' ] = $this->getErrorCode(); |
|
137 | + $res[ 'message' ] = $this->getErrorMessage(); |
|
138 | 138 | |
139 | - } else { |
|
139 | + } else { |
|
140 | 140 | |
141 | - $res[ 'message' ] = $message; |
|
141 | + $res[ 'message' ] = $message; |
|
142 | 142 | |
143 | - } |
|
143 | + } |
|
144 | 144 | |
145 | - return $this->respond( $res ); |
|
145 | + return $this->respond( $res ); |
|
146 | 146 | |
147 | - } |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * Set error code in our result |
|
151 | - * @author Mehdi Hosseini <[email protected]> |
|
152 | - * @since August 24, 2016 |
|
153 | - * @param $errorCode integer |
|
154 | - * @return instance |
|
155 | - */ |
|
156 | - public function setErrorCode( $errorCode ) { |
|
149 | + /** |
|
150 | + * Set error code in our result |
|
151 | + * @author Mehdi Hosseini <[email protected]> |
|
152 | + * @since August 24, 2016 |
|
153 | + * @param $errorCode integer |
|
154 | + * @return instance |
|
155 | + */ |
|
156 | + public function setErrorCode( $errorCode ) { |
|
157 | 157 | |
158 | - $this->error = config( 'errors.' . $errorCode ); |
|
158 | + $this->error = config( 'errors.' . $errorCode ); |
|
159 | 159 | |
160 | - $this->errorCode = $errorCode; |
|
160 | + $this->errorCode = $errorCode; |
|
161 | 161 | |
162 | - return $this; |
|
162 | + return $this; |
|
163 | 163 | |
164 | - } |
|
164 | + } |
|
165 | 165 | |
166 | - /** |
|
167 | - * Return Error code |
|
168 | - * @author Mehdi Hosseini <[email protected]> |
|
169 | - * @since August 24, 2016 |
|
170 | - * @return integer |
|
171 | - */ |
|
172 | - public function getErrorCode() { |
|
166 | + /** |
|
167 | + * Return Error code |
|
168 | + * @author Mehdi Hosseini <[email protected]> |
|
169 | + * @since August 24, 2016 |
|
170 | + * @return integer |
|
171 | + */ |
|
172 | + public function getErrorCode() { |
|
173 | 173 | |
174 | - return $this->errorCode; |
|
174 | + return $this->errorCode; |
|
175 | 175 | |
176 | - } |
|
176 | + } |
|
177 | 177 | |
178 | - /** |
|
179 | - * Get error message |
|
180 | - * @author Mehdi Hosseini <[email protected]> |
|
181 | - * @since August 24, 2016 |
|
182 | - * @return string |
|
183 | - */ |
|
184 | - public function getErrorMessage() { |
|
178 | + /** |
|
179 | + * Get error message |
|
180 | + * @author Mehdi Hosseini <[email protected]> |
|
181 | + * @since August 24, 2016 |
|
182 | + * @return string |
|
183 | + */ |
|
184 | + public function getErrorMessage() { |
|
185 | 185 | |
186 | - return $this->error['message']; |
|
186 | + return $this->error['message']; |
|
187 | 187 | |
188 | - } |
|
188 | + } |
|
189 | 189 | |
190 | - /** |
|
191 | - * Get headers |
|
192 | - * @author Shima Payro <[email protected]> |
|
193 | - * @since Sep 13, 2016 |
|
194 | - * @return array |
|
195 | - */ |
|
196 | - public function getHeaders() { |
|
190 | + /** |
|
191 | + * Get headers |
|
192 | + * @author Shima Payro <[email protected]> |
|
193 | + * @since Sep 13, 2016 |
|
194 | + * @return array |
|
195 | + */ |
|
196 | + public function getHeaders() { |
|
197 | 197 | |
198 | - return $this->headers; |
|
198 | + return $this->headers; |
|
199 | 199 | |
200 | - } |
|
200 | + } |
|
201 | 201 | |
202 | - /** |
|
203 | - * Set headers |
|
204 | - * @author Shima Payro <[email protected]> |
|
205 | - * @since Sep 13, 2016 |
|
206 | - * @return array |
|
207 | - */ |
|
208 | - public function setHeaders( $headers = [] ) { |
|
202 | + /** |
|
203 | + * Set headers |
|
204 | + * @author Shima Payro <[email protected]> |
|
205 | + * @since Sep 13, 2016 |
|
206 | + * @return array |
|
207 | + */ |
|
208 | + public function setHeaders( $headers = [] ) { |
|
209 | 209 | |
210 | - $this->headers = $headers; |
|
210 | + $this->headers = $headers; |
|
211 | 211 | |
212 | - return $this; |
|
212 | + return $this; |
|
213 | 213 | |
214 | - } |
|
214 | + } |
|
215 | 215 | |
216 | - /** |
|
217 | - * Response which contains status and data |
|
218 | - * @param json $data |
|
219 | - * @author Shima Payro <[email protected]> |
|
220 | - * @since May 2, 2016 9:50:19 AM |
|
221 | - * @return json |
|
222 | - * @uses |
|
223 | - * @see |
|
224 | - */ |
|
225 | - public function respondWithResult( $data = NULL ) { |
|
216 | + /** |
|
217 | + * Response which contains status and data |
|
218 | + * @param json $data |
|
219 | + * @author Shima Payro <[email protected]> |
|
220 | + * @since May 2, 2016 9:50:19 AM |
|
221 | + * @return json |
|
222 | + * @uses |
|
223 | + * @see |
|
224 | + */ |
|
225 | + public function respondWithResult( $data = NULL ) { |
|
226 | 226 | |
227 | - $res[ 'status' ] = $this->getStatusText(); |
|
227 | + $res[ 'status' ] = $this->getStatusText(); |
|
228 | 228 | |
229 | - //if it's about laravel validation error |
|
230 | - if ( $this->getErrorCode() && $this->getStatusCode() == 420 ) { |
|
229 | + //if it's about laravel validation error |
|
230 | + if ( $this->getErrorCode() && $this->getStatusCode() == 420 ) { |
|
231 | 231 | |
232 | - $res[ 'error' ] = $this->getErrorCode(); |
|
233 | - $res[ 'message' ] = $data; |
|
232 | + $res[ 'error' ] = $this->getErrorCode(); |
|
233 | + $res[ 'message' ] = $data; |
|
234 | 234 | |
235 | - } else { |
|
235 | + } else { |
|
236 | 236 | |
237 | - $res[ 'result' ] = $data; |
|
237 | + $res[ 'result' ] = $data; |
|
238 | 238 | |
239 | - } |
|
239 | + } |
|
240 | 240 | |
241 | - return $this->respond( $res ); |
|
241 | + return $this->respond( $res ); |
|
242 | 242 | |
243 | - } |
|
243 | + } |
|
244 | 244 | |
245 | 245 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * Haeders |
35 | 35 | * @var array |
36 | 36 | */ |
37 | - protected $headers = []; |
|
37 | + protected $headers = [ ]; |
|
38 | 38 | |
39 | 39 | /** |
40 | 40 | * Getter for $statusCode |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @uses |
59 | 59 | * @see |
60 | 60 | */ |
61 | - public function setStatusCode( $statusCode ) { |
|
61 | + public function setStatusCode($statusCode) { |
|
62 | 62 | |
63 | 63 | $this->statusCode = $statusCode; |
64 | 64 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @uses |
89 | 89 | * @see |
90 | 90 | */ |
91 | - public function setStatusText( $statusText ) { |
|
91 | + public function setStatusText($statusText) { |
|
92 | 92 | |
93 | 93 | $this->statusText = $statusText; |
94 | 94 | |
@@ -105,15 +105,15 @@ discard block |
||
105 | 105 | * @uses |
106 | 106 | * @see |
107 | 107 | */ |
108 | - public function respond( $data ) { |
|
108 | + public function respond($data) { |
|
109 | 109 | |
110 | - $result = array_filter( $this->getHeaders() ); |
|
110 | + $result = array_filter($this->getHeaders()); |
|
111 | 111 | |
112 | - if ( empty( $result ) ); |
|
113 | - return response()->json( $data, $this->getStatusCode() ); |
|
112 | + if (empty($result)); |
|
113 | + return response()->json($data, $this->getStatusCode()); |
|
114 | 114 | |
115 | - return response()->json( $data, $this->getStatusCode() ) |
|
116 | - ->withHeaders( $this->getHeaders() ); |
|
115 | + return response()->json($data, $this->getStatusCode()) |
|
116 | + ->withHeaders($this->getHeaders()); |
|
117 | 117 | |
118 | 118 | } |
119 | 119 | |
@@ -126,12 +126,12 @@ discard block |
||
126 | 126 | * @uses |
127 | 127 | * @see |
128 | 128 | */ |
129 | - public function respondWithMessage( $message = NULL ) { |
|
129 | + public function respondWithMessage($message = NULL) { |
|
130 | 130 | |
131 | 131 | $res[ 'status' ] = $this->getStatusText(); |
132 | 132 | |
133 | 133 | //if it's about failure |
134 | - if ( $this->getErrorCode() ) { |
|
134 | + if ($this->getErrorCode()) { |
|
135 | 135 | |
136 | 136 | $res[ 'error' ] = $this->getErrorCode(); |
137 | 137 | $res[ 'message' ] = $this->getErrorMessage(); |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | |
143 | 143 | } |
144 | 144 | |
145 | - return $this->respond( $res ); |
|
145 | + return $this->respond($res); |
|
146 | 146 | |
147 | 147 | } |
148 | 148 | |
@@ -153,9 +153,9 @@ discard block |
||
153 | 153 | * @param $errorCode integer |
154 | 154 | * @return instance |
155 | 155 | */ |
156 | - public function setErrorCode( $errorCode ) { |
|
156 | + public function setErrorCode($errorCode) { |
|
157 | 157 | |
158 | - $this->error = config( 'errors.' . $errorCode ); |
|
158 | + $this->error = config('errors.'.$errorCode); |
|
159 | 159 | |
160 | 160 | $this->errorCode = $errorCode; |
161 | 161 | |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | */ |
184 | 184 | public function getErrorMessage() { |
185 | 185 | |
186 | - return $this->error['message']; |
|
186 | + return $this->error[ 'message' ]; |
|
187 | 187 | |
188 | 188 | } |
189 | 189 | |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | * @since Sep 13, 2016 |
206 | 206 | * @return array |
207 | 207 | */ |
208 | - public function setHeaders( $headers = [] ) { |
|
208 | + public function setHeaders($headers = [ ]) { |
|
209 | 209 | |
210 | 210 | $this->headers = $headers; |
211 | 211 | |
@@ -222,12 +222,12 @@ discard block |
||
222 | 222 | * @uses |
223 | 223 | * @see |
224 | 224 | */ |
225 | - public function respondWithResult( $data = NULL ) { |
|
225 | + public function respondWithResult($data = NULL) { |
|
226 | 226 | |
227 | 227 | $res[ 'status' ] = $this->getStatusText(); |
228 | 228 | |
229 | 229 | //if it's about laravel validation error |
230 | - if ( $this->getErrorCode() && $this->getStatusCode() == 420 ) { |
|
230 | + if ($this->getErrorCode() && $this->getStatusCode() == 420) { |
|
231 | 231 | |
232 | 232 | $res[ 'error' ] = $this->getErrorCode(); |
233 | 233 | $res[ 'message' ] = $data; |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | |
239 | 239 | } |
240 | 240 | |
241 | - return $this->respond( $res ); |
|
241 | + return $this->respond($res); |
|
242 | 242 | |
243 | 243 | } |
244 | 244 |