Completed
Push — master ( 2bda8d...a58264 )
by
unknown
02:30
created
src/Facades/Respond.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -7,11 +7,11 @@
 block discarded – undo
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() { return 'Anetwork\Respond\Messages'; }
10
+ /**
11
+  * Get the registered name of the component.
12
+  *
13
+  * @return string
14
+  */
15
+ protected static function getFacadeAccessor() { return 'Anetwork\Respond\Messages'; }
16 16
 
17 17
 }
18 18
\ No newline at end of file
Please login to merge, or discard this patch.
src/config/errors.php 1 patch
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -2,170 +2,170 @@
 block discarded – undo
2 2
 
3 3
 return [
4 4
 
5
-	1001 => [
6
-		'message' => 'Oops... Requested field is not found!',
7
-		'type' => 'error'
8
-	],
9
-
10
-	1002 => [
11
-		'message' => 'Oops... Requested User does not exists!',
12
-		'type' => 'error'
13
-	],
14
-
15
-	1003 => [
16
-		'message' => 'Oops... Client type is not entered!',
17
-		'type' => 'error'
18
-	],
19
-
20
-	1004 => [
21
-		'message' => 'Failed because of duplicate',
22
-		'type' => 'error'
23
-	],
24
-
25
-	1005 => [
26
-		'message' => 'Failed because of dablicated user role',
27
-		'type' => 'error'
28
-	],
29
-
30
-	3001 => [
31
-		'message' => 'You are not logged on',
32
-		'type' => 'error',
33
-		'cat' => 'auth',
34
-		'short' => 'not-logged-on'
35
-	],
36
-
37
-	3002 => [
38
-		'message' => 'Application token did not generated successfully',
39
-		'type' => 'error',
40
-		'cat' => 'auth'
41
-	],
42
-
43
-	3003 =>[
44
-		'message' => 'User token did not generated successfully',
45
-		'type' => 'error',
46
-		'cat' => 'auth'
47
-	],
48
-
49
-	3004 => [
50
-		'message' => 'Request token have no agency access',
51
-		'type' => 'error',
52
-		'cat' => 'auth'
53
-	],
54
-
55
-	3005 => [
56
-		'message' => 'Request token did not contains user information',
57
-		'type' => 'error',
58
-		'cat' => 'auth'
59
-	],
60
-
61
-	3006 => [
62
-		'message' => 'Did not set request token',
63
-		'type' => 'error',
64
-		'cat' => 'auth'
65
-	],
66
-
67
-	3007 => [
68
-		'message' => 'can not decode the token',
69
-		'type' => 'error',
70
-		'cat' => 'auth'
71
-	],
72
-
73
-	3008 => [
74
-		'message' => 'can not generate token for authentication',
75
-		'type' => 'error',
76
-		'cat' => 'auth'
77
-	],
78
-
79
-	3009 => [
80
-		'message' => 'can not create token',
81
-		'type' => 'error',
82
-		'cat' => 'auth'
83
-	],
84
-
85
-	3010 => [
86
-		'message' => 'Token expired!',
87
-		'type' => 'error',
88
-		'cat' => 'auth'
89
-	],
90
-
91
-	3011 => [
92
-		'message' => 'Token is invalid!',
93
-		'type' => 'error',
94
-		'cat' => 'auth'
95
-	],
96
-
97
-	3012 => [
98
-		'message' => 'Token Blacklisted',
99
-		'type' => 'error',
100
-		'cat' => 'auth'
101
-	],
102
-
103
-	3013 => [
104
-		'message' => 'Payload invalid!',
105
-		'type' => 'error',
106
-		'cat' => 'auth'
107
-	],
108
-
109
-	3014 => [
110
-		'message' => 'Claim Invalid',
111
-		'type' => 'error',
112
-		'cat' => 'auth'
113
-	],
114
-
115
-	3015 => [
116
-		'message' => 'An error occurred on token validation',
117
-		'type' => 'error',
118
-		'cat' => 'auth'
119
-	],
120
-
121
-	5401 => [
122
-		'message' => 'Authentication unauthorized...',
123
-		'type' => 'error'
124
-	],
125
-
126
-	5404 => [
127
-		'message' => 'Oops... The requested page not found!',
128
-		'type' => 'error'
129
-	],
130
-
131
-	5405 => [
132
-		'message' => 'Oops... The method you requested is not allowed!',
133
-		'type' => 'error'
134
-	],
135
-
136
-	5406 => [
137
-		'message' => 'Oops... The parameters you entered are wrong!',
138
-		'type' => 'error'
139
-	],
140
-
141
-	5420 => [
142
-		'message' => 'Validation Error',
143
-		'type' => 'error'
144
-	],
145
-
146
-	5422 => [
147
-		'message' => 'Token is not valid',
148
-		'type' => 'error'
149
-	],
150
-
151
-	5445 => [
152
-		'message' => 'Oops... Database connection refused',
153
-		'type' => 'error'
154
-	],
155
-
156
-	5448 => [
157
-		'message' => 'Oops... Insert action was not successfully executed',
158
-		'type' => 'error'
159
-	],
160
-
161
-	5447 => [
162
-		'message' => 'Oops... Delete action was not successfully executed',
163
-		'type' => 'error'
164
-	],
165
-
166
-	5449 => [
167
-		'message' => 'Oops... Update action was not successfully executed',
168
-		'type' => 'error'
169
-	]
5
+ 1001 => [
6
+  'message' => 'Oops... Requested field is not found!',
7
+  'type' => 'error'
8
+ ],
9
+
10
+ 1002 => [
11
+  'message' => 'Oops... Requested User does not exists!',
12
+  'type' => 'error'
13
+ ],
14
+
15
+ 1003 => [
16
+  'message' => 'Oops... Client type is not entered!',
17
+  'type' => 'error'
18
+ ],
19
+
20
+ 1004 => [
21
+  'message' => 'Failed because of duplicate',
22
+  'type' => 'error'
23
+ ],
24
+
25
+ 1005 => [
26
+  'message' => 'Failed because of dablicated user role',
27
+  'type' => 'error'
28
+ ],
29
+
30
+ 3001 => [
31
+  'message' => 'You are not logged on',
32
+  'type' => 'error',
33
+  'cat' => 'auth',
34
+  'short' => 'not-logged-on'
35
+ ],
36
+
37
+ 3002 => [
38
+  'message' => 'Application token did not generated successfully',
39
+  'type' => 'error',
40
+  'cat' => 'auth'
41
+ ],
42
+
43
+ 3003 =>[
44
+  'message' => 'User token did not generated successfully',
45
+  'type' => 'error',
46
+  'cat' => 'auth'
47
+ ],
48
+
49
+ 3004 => [
50
+  'message' => 'Request token have no agency access',
51
+  'type' => 'error',
52
+  'cat' => 'auth'
53
+ ],
54
+
55
+ 3005 => [
56
+  'message' => 'Request token did not contains user information',
57
+  'type' => 'error',
58
+  'cat' => 'auth'
59
+ ],
60
+
61
+ 3006 => [
62
+  'message' => 'Did not set request token',
63
+  'type' => 'error',
64
+  'cat' => 'auth'
65
+ ],
66
+
67
+ 3007 => [
68
+  'message' => 'can not decode the token',
69
+  'type' => 'error',
70
+  'cat' => 'auth'
71
+ ],
72
+
73
+ 3008 => [
74
+  'message' => 'can not generate token for authentication',
75
+  'type' => 'error',
76
+  'cat' => 'auth'
77
+ ],
78
+
79
+ 3009 => [
80
+  'message' => 'can not create token',
81
+  'type' => 'error',
82
+  'cat' => 'auth'
83
+ ],
84
+
85
+ 3010 => [
86
+  'message' => 'Token expired!',
87
+  'type' => 'error',
88
+  'cat' => 'auth'
89
+ ],
90
+
91
+ 3011 => [
92
+  'message' => 'Token is invalid!',
93
+  'type' => 'error',
94
+  'cat' => 'auth'
95
+ ],
96
+
97
+ 3012 => [
98
+  'message' => 'Token Blacklisted',
99
+  'type' => 'error',
100
+  'cat' => 'auth'
101
+ ],
102
+
103
+ 3013 => [
104
+  'message' => 'Payload invalid!',
105
+  'type' => 'error',
106
+  'cat' => 'auth'
107
+ ],
108
+
109
+ 3014 => [
110
+  'message' => 'Claim Invalid',
111
+  'type' => 'error',
112
+  'cat' => 'auth'
113
+ ],
114
+
115
+ 3015 => [
116
+  'message' => 'An error occurred on token validation',
117
+  'type' => 'error',
118
+  'cat' => 'auth'
119
+ ],
120
+
121
+ 5401 => [
122
+  'message' => 'Authentication unauthorized...',
123
+  'type' => 'error'
124
+ ],
125
+
126
+ 5404 => [
127
+  'message' => 'Oops... The requested page not found!',
128
+  'type' => 'error'
129
+ ],
130
+
131
+ 5405 => [
132
+  'message' => 'Oops... The method you requested is not allowed!',
133
+  'type' => 'error'
134
+ ],
135
+
136
+ 5406 => [
137
+  'message' => 'Oops... The parameters you entered are wrong!',
138
+  'type' => 'error'
139
+ ],
140
+
141
+ 5420 => [
142
+  'message' => 'Validation Error',
143
+  'type' => 'error'
144
+ ],
145
+
146
+ 5422 => [
147
+  'message' => 'Token is not valid',
148
+  'type' => 'error'
149
+ ],
150
+
151
+ 5445 => [
152
+  'message' => 'Oops... Database connection refused',
153
+  'type' => 'error'
154
+ ],
155
+
156
+ 5448 => [
157
+  'message' => 'Oops... Insert action was not successfully executed',
158
+  'type' => 'error'
159
+ ],
160
+
161
+ 5447 => [
162
+  'message' => 'Oops... Delete action was not successfully executed',
163
+  'type' => 'error'
164
+ ],
165
+
166
+ 5449 => [
167
+  'message' => 'Oops... Update action was not successfully executed',
168
+  'type' => 'error'
169
+ ]
170 170
 
171 171
 ];
Please login to merge, or discard this patch.
src/RespondServiceProvider.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -6,42 +6,42 @@
 block discarded – undo
6 6
 
7 7
 class RespondServiceProvider extends ServiceProvider
8 8
 {
9
-	/**
10
-	* Perform post-registration booting of services.
11
-	*
12
-	* @return void
13
-	*/
14
-	public function boot()
15
-	{
9
+ /**
10
+  * Perform post-registration booting of services.
11
+  *
12
+  * @return void
13
+  */
14
+ public function boot()
15
+ {
16 16
 
17
-		$this->publishes([
18
-			__DIR__.'/config/errors.php' => config_path('errors.php'),
19
-		]);
17
+  $this->publishes([
18
+   __DIR__.'/config/errors.php' => config_path('errors.php'),
19
+  ]);
20 20
 
21
-	}
21
+ }
22 22
 
23 23
 
24
-	/**
25
-	* Register any package services.
26
-	*
27
-	* @return void
28
-	*/
29
-	public function register()
30
-	{
24
+ /**
25
+  * Register any package services.
26
+  *
27
+  * @return void
28
+  */
29
+ public function register()
30
+ {
31 31
 
32
-		$this->registerMessages();
32
+  $this->registerMessages();
33 33
 
34
-	}
34
+ }
35 35
 
36
-	private function registerMessages()
37
-	{
36
+ private function registerMessages()
37
+ {
38 38
 
39
-		$this->app->bind( 'Anetwork\Respond\Messages', function() {
39
+  $this->app->bind( 'Anetwork\Respond\Messages', function() {
40 40
 
41
-			return new Messages();
41
+   return new Messages();
42 42
 
43
-		});
43
+  });
44 44
 
45
-	}
45
+ }
46 46
 
47 47
 }
Please login to merge, or discard this patch.
src/Messages.php 1 patch
Indentation   +247 added lines, -247 removed lines patch added patch discarded remove patch
@@ -5,253 +5,253 @@
 block discarded – undo
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 = '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
-	}
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 255
 
256 256
 
257 257
 }
Please login to merge, or discard this patch.
src/Main.php 1 patch
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -6,240 +6,240 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.