Completed
Push — master ( 46828e...77588e )
by CodexShaper
07:35 queued 04:43
created
src/Support/Facades/Config.php 2 patches
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -21,62 +21,62 @@
 block discarded – undo
21 21
  */
22 22
 class Config {
23 23
 
24
-	/**
25
-	 * The config.
26
-	 *
27
-	 * @since    1.0.0
28
-	 * @access   protected
29
-	 * @var      array    $config    The config array.
30
-	 */
31
-	protected $config = array();
24
+    /**
25
+     * The config.
26
+     *
27
+     * @since    1.0.0
28
+     * @access   protected
29
+     * @var      array    $config    The config array.
30
+     */
31
+    protected $config = array();
32 32
 
33
-	/**
34
-	 * Factory class.
35
-	 *
36
-	 * @since    1.0.0
37
-	 * @param array $options The defaut configuration option.
38
-	 *
39
-	 * @return void
40
-	 */
41
-	public function __construct( $options = array() ) {
42
-		$dir = __DIR__ . '/../../../../../../';
33
+    /**
34
+     * Factory class.
35
+     *
36
+     * @since    1.0.0
37
+     * @param array $options The defaut configuration option.
38
+     *
39
+     * @return void
40
+     */
41
+    public function __construct( $options = array() ) {
42
+        $dir = __DIR__ . '/../../../../../../';
43 43
 
44
-		if ( ! empty( $options ) && isset( $options['paths']['root'] ) ) {
45
-			$dir = rtrim( $options['paths']['root'], '/' ) . '/';
46
-		}
44
+        if ( ! empty( $options ) && isset( $options['paths']['root'] ) ) {
45
+            $dir = rtrim( $options['paths']['root'], '/' ) . '/';
46
+        }
47 47
 
48
-		foreach ( glob( $dir . 'config/*.php' ) as $file ) {
49
-			$index                  = pathinfo( $file )['filename'];
50
-			$this->config[ $index ] = require_once $file;
51
-		}
52
-	}
48
+        foreach ( glob( $dir . 'config/*.php' ) as $file ) {
49
+            $index                  = pathinfo( $file )['filename'];
50
+            $this->config[ $index ] = require_once $file;
51
+        }
52
+    }
53 53
 
54
-	/**
55
-	 * Get the config value.
56
-	 *
57
-	 * @since    1.0.0
58
-	 * @param string $config The config key.
59
-	 * @param string $default The default config value.
60
-	 *
61
-	 * @return null|string
62
-	 */
63
-	public function get( $config, $default = null ) {
64
-		$keys     = explode( '.', $config );
65
-		$filename = array_shift( $keys );
66
-		$data     = $this->config[ $filename ];
54
+    /**
55
+     * Get the config value.
56
+     *
57
+     * @since    1.0.0
58
+     * @param string $config The config key.
59
+     * @param string $default The default config value.
60
+     *
61
+     * @return null|string
62
+     */
63
+    public function get( $config, $default = null ) {
64
+        $keys     = explode( '.', $config );
65
+        $filename = array_shift( $keys );
66
+        $data     = $this->config[ $filename ];
67 67
 
68
-		foreach ( $keys as $key ) {
69
-			if ( is_array( $data ) && array_key_exists( $key, $data ) ) {
70
-				$data = $data[ $key ];
71
-			} else {
72
-				$data = null;
73
-			}
74
-		}
68
+        foreach ( $keys as $key ) {
69
+            if ( is_array( $data ) && array_key_exists( $key, $data ) ) {
70
+                $data = $data[ $key ];
71
+            } else {
72
+                $data = null;
73
+            }
74
+        }
75 75
 
76
-		if ( ! $data ) {
77
-			$data = $default;
78
-		}
76
+        if ( ! $data ) {
77
+            $data = $default;
78
+        }
79 79
 
80
-		return $data;
81
-	}
80
+        return $data;
81
+    }
82 82
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -38,16 +38,16 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @return void
40 40
 	 */
41
-	public function __construct( $options = array() ) {
42
-		$dir = __DIR__ . '/../../../../../../';
41
+	public function __construct($options = array()) {
42
+		$dir = __DIR__.'/../../../../../../';
43 43
 
44
-		if ( ! empty( $options ) && isset( $options['paths']['root'] ) ) {
45
-			$dir = rtrim( $options['paths']['root'], '/' ) . '/';
44
+		if (!empty($options) && isset($options['paths']['root'])) {
45
+			$dir = rtrim($options['paths']['root'], '/').'/';
46 46
 		}
47 47
 
48
-		foreach ( glob( $dir . 'config/*.php' ) as $file ) {
49
-			$index                  = pathinfo( $file )['filename'];
50
-			$this->config[ $index ] = require_once $file;
48
+		foreach (glob($dir.'config/*.php') as $file) {
49
+			$index                  = pathinfo($file)['filename'];
50
+			$this->config[$index] = require_once $file;
51 51
 		}
52 52
 	}
53 53
 
@@ -60,20 +60,20 @@  discard block
 block discarded – undo
60 60
 	 *
61 61
 	 * @return null|string
62 62
 	 */
63
-	public function get( $config, $default = null ) {
64
-		$keys     = explode( '.', $config );
65
-		$filename = array_shift( $keys );
66
-		$data     = $this->config[ $filename ];
63
+	public function get($config, $default = null) {
64
+		$keys     = explode('.', $config);
65
+		$filename = array_shift($keys);
66
+		$data     = $this->config[$filename];
67 67
 
68
-		foreach ( $keys as $key ) {
69
-			if ( is_array( $data ) && array_key_exists( $key, $data ) ) {
70
-				$data = $data[ $key ];
68
+		foreach ($keys as $key) {
69
+			if (is_array($data) && array_key_exists($key, $data)) {
70
+				$data = $data[$key];
71 71
 			} else {
72 72
 				$data = null;
73 73
 			}
74 74
 		}
75 75
 
76
-		if ( ! $data ) {
76
+		if (!$data) {
77 77
 			$data = $default;
78 78
 		}
79 79
 
Please login to merge, or discard this patch.
src/Support/Facades/Route.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -23,12 +23,12 @@
 block discarded – undo
23 23
  */
24 24
 class Route extends Facade {
25 25
 
26
-	/**
27
-	 * Get the registered name of the component.
28
-	 *
29
-	 * @return string
30
-	 */
31
-	protected static function getFacadeAccessor() {
32
-		return \WPB\Router::class;
33
-	}
26
+    /**
27
+     * Get the registered name of the component.
28
+     *
29
+     * @return string
30
+     */
31
+    protected static function getFacadeAccessor() {
32
+        return \WPB\Router::class;
33
+    }
34 34
 }
Please login to merge, or discard this patch.
src/Exceptions/Handler.php 2 patches
Indentation   +512 added lines, -512 removed lines patch added patch discarded remove patch
@@ -54,516 +54,516 @@
 block discarded – undo
54 54
  */
55 55
 class Handler implements ExceptionHandlerContract {
56 56
 
57
-	/**
58
-	 * The container implementation.
59
-	 *
60
-	 * @var \Illuminate\Contracts\Container\Container
61
-	 */
62
-	protected $container;
63
-
64
-	/**
65
-	 * A list of the exception types that are not reported.
66
-	 *
67
-	 * @var array
68
-	 */
69
-	protected $dont_report = array();
70
-
71
-	/**
72
-	 * A list of the internal exception types that should not be reported.
73
-	 *
74
-	 * @var array
75
-	 */
76
-	protected $internal_dont_report = array(
77
-		AuthenticationException::class,
78
-		AuthorizationException::class,
79
-		HttpException::class,
80
-		HttpResponseException::class,
81
-		ModelNotFoundException::class,
82
-		SuspiciousOperationException::class,
83
-		TokenMismatchException::class,
84
-		ValidationException::class,
85
-	);
86
-
87
-	/**
88
-	 * A list of the inputs that are never flashed for validation exceptions.
89
-	 *
90
-	 * @var array
91
-	 */
92
-	protected $dont_flash = array(
93
-		'password',
94
-		'password_confirmation',
95
-	);
96
-
97
-	/**
98
-	 * Create a new exception handler instance.
99
-	 *
100
-	 * @param \Illuminate\Contracts\Container\Container $container The app container.
101
-	 *
102
-	 * @return void
103
-	 */
104
-	public function __construct( Container $container ) {
105
-		$this->container = $container;
106
-	}
107
-
108
-	/**
109
-	 * Report or log an exception.
110
-	 *
111
-	 * @param \Throwable $e The throwable exception.
112
-	 *
113
-	 * @throws \Exception Throw the exception.
114
-	 *
115
-	 * @return void
116
-	 */
117
-	public function report( Throwable $e ) {
118
-		if ( $this->shouldnt_report( $e ) ) {
119
-			return;
120
-		}
121
-
122
-		$report_callable = array( $e, 'report' );
123
-
124
-		if ( is_callable( $report_callable ) ) {
125
-			$this->container->call( $report_callable );
126
-
127
-			return;
128
-		}
129
-
130
-		try {
131
-			$logger = $this->container->make( LoggerInterface::class );
132
-		} catch ( Exception $ex ) {
133
-			throw $e;
134
-		}
135
-
136
-		$logger->error(
137
-			$e->getMessage(),
138
-			array_merge(
139
-				$this->exception_context( $e ),
140
-				$this->context(),
141
-				array( 'exception' => $e )
142
-			)
143
-		);
144
-	}
145
-
146
-	/**
147
-	 * Determine if the exception should be reported.
148
-	 *
149
-	 * @param \Throwable $e The throwable exception.
150
-	 *
151
-	 * @return bool
152
-	 */
153
-	public function should_report( Throwable $e ) {
154
-		return ! $this->shouldnt_report( $e );
155
-	}
156
-
157
-	/**
158
-	 * Determine if the exception is in the "do not report" list.
159
-	 *
160
-	 * @param \Throwable $e The throwable exception.
161
-	 *
162
-	 * @return bool
163
-	 */
164
-	protected function shouldnt_report( Throwable $e ) {
165
-		$dont_report = array_merge( $this->dont_report, $this->internal_dont_report );
166
-
167
-		return ! is_null(
168
-			Arr::first(
169
-				$dont_report,
170
-				function ( $type ) use ( $e ) {
171
-					return $e instanceof $type;
172
-				}
173
-			)
174
-		);
175
-	}
176
-
177
-	/**
178
-	 * Get the default exception context variables for logging.
179
-	 *
180
-	 * @param \Throwable $e The throwable exception.
181
-	 *
182
-	 * @return array
183
-	 */
184
-	protected function exception_context( Throwable $e ) {
185
-		return array();
186
-	}
187
-
188
-	/**
189
-	 * Get the default context variables for logging.
190
-	 *
191
-	 * @return array
192
-	 */
193
-	protected function context() {
194
-		try {
195
-			return array_filter(
196
-				array(
197
-					'userId' => Auth::id(),
198
-				// 'email' => optional(Auth::user())->email,
199
-				)
200
-			);
201
-		} catch ( Throwable $e ) {
202
-			return array();
203
-		}
204
-	}
205
-
206
-	/**
207
-	 * Render an exception into an HTTP response.
208
-	 *
209
-	 * @param \Illuminate\Http\Request $request The app request.
210
-	 * @param \Throwable               $e The throwable exception.
211
-	 *
212
-	 * @throws \Throwable Throw the exception.
213
-	 *
214
-	 * @return \Symfony\Component\HttpFoundation\Response
215
-	 */
216
-	public function render( $request, Throwable $e ) {
217
-		$response = $e->render( $request );
218
-		if ( method_exists( $e, 'render' ) && $response ) {
219
-			return Router::toResponse( $request, $response );
220
-		} elseif ( $e instanceof Responsable ) {
221
-			return $e->toResponse( $request );
222
-		}
223
-
224
-		$e = $this->prepare_exception( $e );
225
-
226
-		if ( $e instanceof HttpResponseException ) {
227
-			return $e->getResponse();
228
-		} elseif ( $e instanceof AuthenticationException ) {
229
-			return $this->unauthenticated( $request, $e );
230
-		} elseif ( $e instanceof ValidationException ) {
231
-			return $this->convert_validation_exception_to_response( $e, $request );
232
-		}
233
-
234
-		return $request->expectsJson()
235
-					? $this->prepare_json_response( $request, $e )
236
-					: $this->prepare_response( $request, $e );
237
-	}
238
-
239
-	/**
240
-	 * Prepare exception for rendering.
241
-	 *
242
-	 * @param \Throwable $e The throwable exception.
243
-	 *
244
-	 * @return \Throwable
245
-	 */
246
-	protected function prepare_exception( Throwable $e ) {
247
-		if ( $e instanceof ModelNotFoundException ) {
248
-			$e = new NotFoundHttpException( $e->getMessage(), $e );
249
-		} elseif ( $e instanceof AuthorizationException ) {
250
-			$e = new AccessDeniedHttpException( $e->getMessage(), $e );
251
-		} elseif ( $e instanceof TokenMismatchException ) {
252
-			$e = new HttpException( 419, $e->getMessage(), $e );
253
-		} elseif ( $e instanceof SuspiciousOperationException ) {
254
-			$e = new NotFoundHttpException( 'Bad hostname provided.', $e );
255
-		}
256
-
257
-		return $e;
258
-	}
259
-
260
-	/**
261
-	 * Convert an authentication exception into a response.
262
-	 *
263
-	 * @param \Illuminate\Http\Request                 $request The app request.
264
-	 * @param \Illuminate\Auth\AuthenticationException $exception The authenticated exception.
265
-	 *
266
-	 * @return \Symfony\Component\HttpFoundation\Response
267
-	 */
268
-	protected function unauthenticated( $request, AuthenticationException $exception ) {
269
-		return $request->expectsJson()
270
-					? response()->json( array( 'message' => $exception->getMessage() ), 401 )
271
-					: redirect()->guest( $exception->redirectTo() ?? route( 'login' ) );
272
-	}
273
-
274
-	/**
275
-	 * Create a response object from the given validation exception.
276
-	 *
277
-	 * @param \Illuminate\Validation\ValidationException $e The validation exception.
278
-	 * @param \Illuminate\Http\Request                   $request The app request.
279
-	 *
280
-	 * @return \Symfony\Component\HttpFoundation\Response
281
-	 */
282
-	protected function convert_validation_exception_to_response( ValidationException $e, $request ) {
283
-		if ( $e->response ) {
284
-			return $e->response;
285
-		}
286
-
287
-		return $request->expectsJson()
288
-					? $this->invalid_json( $request, $e )
289
-					: $this->invalid( $request, $e );
290
-	}
291
-
292
-	/**
293
-	 * Convert a validation exception into a response.
294
-	 *
295
-	 * @param \Illuminate\Http\Request                   $request The app request.
296
-	 * @param \Illuminate\Validation\ValidationException $exception The validation exception.
297
-	 *
298
-	 * @return \Illuminate\Http\Response
299
-	 */
300
-	protected function invalid( $request, ValidationException $exception ) {
301
-		return redirect( $exception->redirectTo ?? url()->previous() )
302
-					->withInput( Arr::except( $request->input(), $this->dont_flash ) )
303
-					->withErrors( $exception->errors(), $exception->errorBag );
304
-	}
305
-
306
-	/**
307
-	 * Convert a validation exception into a JSON response.
308
-	 *
309
-	 * @param \Illuminate\Http\Request                   $request The app request.
310
-	 * @param \Illuminate\Validation\ValidationException $exception The validation exception.
311
-	 *
312
-	 * @return \Illuminate\Http\JsonResponse
313
-	 */
314
-	protected function invalid_json( $request, ValidationException $exception ) {
315
-		return response()->json(
316
-			array(
317
-				'message' => $exception->getMessage(),
318
-				'errors'  => $exception->errors(),
319
-			),
320
-			$exception->status
321
-		);
322
-	}
323
-
324
-	/**
325
-	 * Prepare a response for the given exception.
326
-	 *
327
-	 * @param \Illuminate\Http\Request $request The app request.
328
-	 * @param \Throwable               $e The throwable exception.
329
-	 *
330
-	 * @return \Symfony\Component\HttpFoundation\Response
331
-	 */
332
-	protected function prepare_response( $request, Throwable $e ) {
333
-		if ( ! $this->is_http_exception( $e ) && $this->container['config']['app.debug'] ) {
334
-			return $this->to_illuminate_response( $this->convert_exception_to_response( $e ), $e );
335
-		}
336
-
337
-		if ( ! $this->is_http_exception( $e ) ) {
338
-			$e = new HttpException( 500, $e->getMessage() );
339
-		}
340
-
341
-		return $this->to_illuminate_response(
342
-			$this->render_http_exception( $e ),
343
-			$e
344
-		);
345
-	}
346
-
347
-	/**
348
-	 * Create a Symfony response for the given exception.
349
-	 *
350
-	 * @param \Throwable $e The throwable exception.
351
-	 *
352
-	 * @return \Symfony\Component\HttpFoundation\Response
353
-	 */
354
-	protected function convert_exception_to_response( Throwable $e ) {
355
-		return SymfonyResponse::create(
356
-			$this->render_exception_content( $e ),
357
-			$this->is_http_exception( $e ) ? $e->getStatusCode() : 500,
358
-			$this->is_http_exception( $e ) ? $e->getHeaders() : array()
359
-		);
360
-	}
361
-
362
-	/**
363
-	 * Get the response content for the given exception.
364
-	 *
365
-	 * @param \Throwable $e The throwable exception.
366
-	 *
367
-	 * @return string
368
-	 */
369
-	protected function render_exception_content( Throwable $e ) {
370
-		try {
371
-			return $this->container['config']['app.debug'] && class_exists( Whoops::class )
372
-						? $this->render_exception_with_whoops( $e )
373
-						: $this->render_exception_with_symfony( $e, $this->container['config']['app.debug'] );
374
-		} catch ( Exception $e ) {
375
-			return $this->render_exception_with_symfony( $e, $this->container['config']['app.debug'] );
376
-		}
377
-	}
378
-
379
-	/**
380
-	 * Render an exception to a string using "Whoops".
381
-	 *
382
-	 * @param \Throwable $e The throwable exception.
383
-	 *
384
-	 * @return string
385
-	 */
386
-	protected function render_exception_with_whoops( Throwable $e ) {
387
-		return tap(
388
-			new Whoops(),
389
-			function ( $whoops ) {
390
-				$whoops->appendHandler( $this->whoops_handler() );
391
-
392
-				$whoops->writeToOutput( false );
393
-
394
-				$whoops->allowQuit( false );
395
-			}
396
-		)->handleException( $e );
397
-	}
398
-
399
-	/**
400
-	 * Get the Whoops handler for the application.
401
-	 *
402
-	 * @return \Whoops\Handler\Handler
403
-	 */
404
-	protected function whoops_handler() {
405
-		try {
406
-			return $this->container( HandlerInterface::class );
407
-		} catch ( BindingResolutionException $e ) {
408
-			return ( new WhoopsHandler() )->forDebug();
409
-		}
410
-	}
411
-
412
-	/**
413
-	 * Render an exception to a string using Symfony.
414
-	 *
415
-	 * @param \Throwable $e The throwable exception.
416
-	 * @param bool       $debug Enable or disable debug.
417
-	 *
418
-	 * @return string
419
-	 */
420
-	protected function render_exception_with_symfony( Throwable $e, $debug ) {
421
-		$renderer = new HtmlErrorRenderer( $debug );
422
-
423
-		return $renderer->getBody( $renderer->render( $e ) );
424
-	}
425
-
426
-	/**
427
-	 * Render the given HttpException.
428
-	 *
429
-	 * @param \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface $e The http exception.
430
-	 *
431
-	 * @return \Symfony\Component\HttpFoundation\Response
432
-	 */
433
-	protected function render_http_exception( HttpExceptionInterface $e ) {
434
-		$this->register_error_view_paths();
435
-		$view = $this->get_http_exception_view( $e );
436
-
437
-		if ( view()->exists( $view ) ) {
438
-			return response()->view(
439
-				$view,
440
-				array(
441
-					'errors'    => new ViewErrorBag(),
442
-					'exception' => $e,
443
-				),
444
-				$e->getStatusCode(),
445
-				$e->getHeaders()
446
-			);
447
-		}
448
-
449
-		return $this->convert_exception_to_response( $e );
450
-	}
451
-
452
-	/**
453
-	 * Register the error template hint paths.
454
-	 *
455
-	 * @return void
456
-	 */
457
-	protected function register_error_view_paths() {
458
-		$paths = collect( $this->container['config']['view.paths'] );
459
-
460
-		View::replaceNamespace(
461
-			'errors',
462
-			$paths->map(
463
-				function ( $path ) {
464
-					return "{$path}/errors";
465
-				}
466
-			)->push( __DIR__ . '/views' )->all()
467
-		);
468
-	}
469
-
470
-	/**
471
-	 * Get the view used to render HTTP exceptions.
472
-	 *
473
-	 * @param \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface $e The http exceptions.
474
-	 *
475
-	 * @return string
476
-	 */
477
-	protected function get_http_exception_view( HttpExceptionInterface $e ) {
478
-		return "errors::{$e->getStatusCode()}";
479
-	}
480
-
481
-	/**
482
-	 * Map the given exception into an Illuminate response.
483
-	 *
484
-	 * @param \Symfony\Component\HttpFoundation\Response $response The app http response.
485
-	 * @param \Throwable                                 $e The throwable exception.
486
-	 *
487
-	 * @return \Illuminate\Http\Response
488
-	 */
489
-	protected function to_illuminate_response( $response, Throwable $e ) {
490
-		if ( $response instanceof SymfonyRedirectResponse ) {
491
-			$response = new RedirectResponse(
492
-				$response->getTargetUrl(),
493
-				$response->getStatusCode(),
494
-				$response->headers->all()
495
-			);
496
-		} else {
497
-			$response = new Response(
498
-				$response->getContent(),
499
-				$response->getStatusCode(),
500
-				$response->headers->all()
501
-			);
502
-		}
503
-
504
-		return $response->withException( $e );
505
-	}
506
-
507
-	/**
508
-	 * Prepare a JSON response for the given exception.
509
-	 *
510
-	 * @param \Illuminate\Http\Request $request The app http request.
511
-	 * @param \Throwable               $e The throwable exception.
512
-	 *
513
-	 * @return \Illuminate\Http\JsonResponse
514
-	 */
515
-	protected function prepare_json_response( $request, Throwable $e ) {
516
-		return new Json_response(
517
-			$this->convert_exception_to_array( $e ),
518
-			$this->is_http_exception( $e ) ? $e->getStatusCode() : 500,
519
-			$this->is_http_exception( $e ) ? $e->getHeaders() : array(),
520
-			JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
521
-		);
522
-	}
523
-
524
-	/**
525
-	 * Convert the given exception to an array.
526
-	 *
527
-	 * @param \Throwable $e The throwable exception.
528
-	 *
529
-	 * @return array
530
-	 */
531
-	protected function convert_exception_to_array( Throwable $e ) {
532
-		return $this->container['config']['app.debug'] ? array(
533
-			'message'   => $e->getMessage(),
534
-			'exception' => get_class( $e ),
535
-			'file'      => $e->getFile(),
536
-			'line'      => $e->getLine(),
537
-			'trace'     => collect( $e->getTrace() )->map(
538
-				function ( $trace ) {
539
-					return Arr::except( $trace, array( 'args' ) );
540
-				}
541
-			)->all(),
542
-		) : array(
543
-			'message' => $this->is_http_exception( $e ) ? $e->getMessage() : 'Server Error',
544
-		);
545
-	}
546
-
547
-	/**
548
-	 * Render an exception to the console.
549
-	 *
550
-	 * @param \Symfony\Component\Console\Output\OutputInterface $output The symfony console output.
551
-	 * @param \Throwable                                        $e The throwable exception.
552
-	 *
553
-	 * @return void
554
-	 */
555
-	public function render_for_console( $output, Throwable $e ) {
556
-		( new ConsoleApplication() )->renderThrowable( $e, $output );
557
-	}
558
-
559
-	/**
560
-	 * Determine if the given exception is an HTTP exception.
561
-	 *
562
-	 * @param \Throwable $e The throwable exception.
563
-	 *
564
-	 * @return bool
565
-	 */
566
-	protected function is_http_exception( Throwable $e ) {
567
-		return $e instanceof HttpExceptionInterface;
568
-	}
57
+    /**
58
+     * The container implementation.
59
+     *
60
+     * @var \Illuminate\Contracts\Container\Container
61
+     */
62
+    protected $container;
63
+
64
+    /**
65
+     * A list of the exception types that are not reported.
66
+     *
67
+     * @var array
68
+     */
69
+    protected $dont_report = array();
70
+
71
+    /**
72
+     * A list of the internal exception types that should not be reported.
73
+     *
74
+     * @var array
75
+     */
76
+    protected $internal_dont_report = array(
77
+        AuthenticationException::class,
78
+        AuthorizationException::class,
79
+        HttpException::class,
80
+        HttpResponseException::class,
81
+        ModelNotFoundException::class,
82
+        SuspiciousOperationException::class,
83
+        TokenMismatchException::class,
84
+        ValidationException::class,
85
+    );
86
+
87
+    /**
88
+     * A list of the inputs that are never flashed for validation exceptions.
89
+     *
90
+     * @var array
91
+     */
92
+    protected $dont_flash = array(
93
+        'password',
94
+        'password_confirmation',
95
+    );
96
+
97
+    /**
98
+     * Create a new exception handler instance.
99
+     *
100
+     * @param \Illuminate\Contracts\Container\Container $container The app container.
101
+     *
102
+     * @return void
103
+     */
104
+    public function __construct( Container $container ) {
105
+        $this->container = $container;
106
+    }
107
+
108
+    /**
109
+     * Report or log an exception.
110
+     *
111
+     * @param \Throwable $e The throwable exception.
112
+     *
113
+     * @throws \Exception Throw the exception.
114
+     *
115
+     * @return void
116
+     */
117
+    public function report( Throwable $e ) {
118
+        if ( $this->shouldnt_report( $e ) ) {
119
+            return;
120
+        }
121
+
122
+        $report_callable = array( $e, 'report' );
123
+
124
+        if ( is_callable( $report_callable ) ) {
125
+            $this->container->call( $report_callable );
126
+
127
+            return;
128
+        }
129
+
130
+        try {
131
+            $logger = $this->container->make( LoggerInterface::class );
132
+        } catch ( Exception $ex ) {
133
+            throw $e;
134
+        }
135
+
136
+        $logger->error(
137
+            $e->getMessage(),
138
+            array_merge(
139
+                $this->exception_context( $e ),
140
+                $this->context(),
141
+                array( 'exception' => $e )
142
+            )
143
+        );
144
+    }
145
+
146
+    /**
147
+     * Determine if the exception should be reported.
148
+     *
149
+     * @param \Throwable $e The throwable exception.
150
+     *
151
+     * @return bool
152
+     */
153
+    public function should_report( Throwable $e ) {
154
+        return ! $this->shouldnt_report( $e );
155
+    }
156
+
157
+    /**
158
+     * Determine if the exception is in the "do not report" list.
159
+     *
160
+     * @param \Throwable $e The throwable exception.
161
+     *
162
+     * @return bool
163
+     */
164
+    protected function shouldnt_report( Throwable $e ) {
165
+        $dont_report = array_merge( $this->dont_report, $this->internal_dont_report );
166
+
167
+        return ! is_null(
168
+            Arr::first(
169
+                $dont_report,
170
+                function ( $type ) use ( $e ) {
171
+                    return $e instanceof $type;
172
+                }
173
+            )
174
+        );
175
+    }
176
+
177
+    /**
178
+     * Get the default exception context variables for logging.
179
+     *
180
+     * @param \Throwable $e The throwable exception.
181
+     *
182
+     * @return array
183
+     */
184
+    protected function exception_context( Throwable $e ) {
185
+        return array();
186
+    }
187
+
188
+    /**
189
+     * Get the default context variables for logging.
190
+     *
191
+     * @return array
192
+     */
193
+    protected function context() {
194
+        try {
195
+            return array_filter(
196
+                array(
197
+                    'userId' => Auth::id(),
198
+                // 'email' => optional(Auth::user())->email,
199
+                )
200
+            );
201
+        } catch ( Throwable $e ) {
202
+            return array();
203
+        }
204
+    }
205
+
206
+    /**
207
+     * Render an exception into an HTTP response.
208
+     *
209
+     * @param \Illuminate\Http\Request $request The app request.
210
+     * @param \Throwable               $e The throwable exception.
211
+     *
212
+     * @throws \Throwable Throw the exception.
213
+     *
214
+     * @return \Symfony\Component\HttpFoundation\Response
215
+     */
216
+    public function render( $request, Throwable $e ) {
217
+        $response = $e->render( $request );
218
+        if ( method_exists( $e, 'render' ) && $response ) {
219
+            return Router::toResponse( $request, $response );
220
+        } elseif ( $e instanceof Responsable ) {
221
+            return $e->toResponse( $request );
222
+        }
223
+
224
+        $e = $this->prepare_exception( $e );
225
+
226
+        if ( $e instanceof HttpResponseException ) {
227
+            return $e->getResponse();
228
+        } elseif ( $e instanceof AuthenticationException ) {
229
+            return $this->unauthenticated( $request, $e );
230
+        } elseif ( $e instanceof ValidationException ) {
231
+            return $this->convert_validation_exception_to_response( $e, $request );
232
+        }
233
+
234
+        return $request->expectsJson()
235
+                    ? $this->prepare_json_response( $request, $e )
236
+                    : $this->prepare_response( $request, $e );
237
+    }
238
+
239
+    /**
240
+     * Prepare exception for rendering.
241
+     *
242
+     * @param \Throwable $e The throwable exception.
243
+     *
244
+     * @return \Throwable
245
+     */
246
+    protected function prepare_exception( Throwable $e ) {
247
+        if ( $e instanceof ModelNotFoundException ) {
248
+            $e = new NotFoundHttpException( $e->getMessage(), $e );
249
+        } elseif ( $e instanceof AuthorizationException ) {
250
+            $e = new AccessDeniedHttpException( $e->getMessage(), $e );
251
+        } elseif ( $e instanceof TokenMismatchException ) {
252
+            $e = new HttpException( 419, $e->getMessage(), $e );
253
+        } elseif ( $e instanceof SuspiciousOperationException ) {
254
+            $e = new NotFoundHttpException( 'Bad hostname provided.', $e );
255
+        }
256
+
257
+        return $e;
258
+    }
259
+
260
+    /**
261
+     * Convert an authentication exception into a response.
262
+     *
263
+     * @param \Illuminate\Http\Request                 $request The app request.
264
+     * @param \Illuminate\Auth\AuthenticationException $exception The authenticated exception.
265
+     *
266
+     * @return \Symfony\Component\HttpFoundation\Response
267
+     */
268
+    protected function unauthenticated( $request, AuthenticationException $exception ) {
269
+        return $request->expectsJson()
270
+                    ? response()->json( array( 'message' => $exception->getMessage() ), 401 )
271
+                    : redirect()->guest( $exception->redirectTo() ?? route( 'login' ) );
272
+    }
273
+
274
+    /**
275
+     * Create a response object from the given validation exception.
276
+     *
277
+     * @param \Illuminate\Validation\ValidationException $e The validation exception.
278
+     * @param \Illuminate\Http\Request                   $request The app request.
279
+     *
280
+     * @return \Symfony\Component\HttpFoundation\Response
281
+     */
282
+    protected function convert_validation_exception_to_response( ValidationException $e, $request ) {
283
+        if ( $e->response ) {
284
+            return $e->response;
285
+        }
286
+
287
+        return $request->expectsJson()
288
+                    ? $this->invalid_json( $request, $e )
289
+                    : $this->invalid( $request, $e );
290
+    }
291
+
292
+    /**
293
+     * Convert a validation exception into a response.
294
+     *
295
+     * @param \Illuminate\Http\Request                   $request The app request.
296
+     * @param \Illuminate\Validation\ValidationException $exception The validation exception.
297
+     *
298
+     * @return \Illuminate\Http\Response
299
+     */
300
+    protected function invalid( $request, ValidationException $exception ) {
301
+        return redirect( $exception->redirectTo ?? url()->previous() )
302
+                    ->withInput( Arr::except( $request->input(), $this->dont_flash ) )
303
+                    ->withErrors( $exception->errors(), $exception->errorBag );
304
+    }
305
+
306
+    /**
307
+     * Convert a validation exception into a JSON response.
308
+     *
309
+     * @param \Illuminate\Http\Request                   $request The app request.
310
+     * @param \Illuminate\Validation\ValidationException $exception The validation exception.
311
+     *
312
+     * @return \Illuminate\Http\JsonResponse
313
+     */
314
+    protected function invalid_json( $request, ValidationException $exception ) {
315
+        return response()->json(
316
+            array(
317
+                'message' => $exception->getMessage(),
318
+                'errors'  => $exception->errors(),
319
+            ),
320
+            $exception->status
321
+        );
322
+    }
323
+
324
+    /**
325
+     * Prepare a response for the given exception.
326
+     *
327
+     * @param \Illuminate\Http\Request $request The app request.
328
+     * @param \Throwable               $e The throwable exception.
329
+     *
330
+     * @return \Symfony\Component\HttpFoundation\Response
331
+     */
332
+    protected function prepare_response( $request, Throwable $e ) {
333
+        if ( ! $this->is_http_exception( $e ) && $this->container['config']['app.debug'] ) {
334
+            return $this->to_illuminate_response( $this->convert_exception_to_response( $e ), $e );
335
+        }
336
+
337
+        if ( ! $this->is_http_exception( $e ) ) {
338
+            $e = new HttpException( 500, $e->getMessage() );
339
+        }
340
+
341
+        return $this->to_illuminate_response(
342
+            $this->render_http_exception( $e ),
343
+            $e
344
+        );
345
+    }
346
+
347
+    /**
348
+     * Create a Symfony response for the given exception.
349
+     *
350
+     * @param \Throwable $e The throwable exception.
351
+     *
352
+     * @return \Symfony\Component\HttpFoundation\Response
353
+     */
354
+    protected function convert_exception_to_response( Throwable $e ) {
355
+        return SymfonyResponse::create(
356
+            $this->render_exception_content( $e ),
357
+            $this->is_http_exception( $e ) ? $e->getStatusCode() : 500,
358
+            $this->is_http_exception( $e ) ? $e->getHeaders() : array()
359
+        );
360
+    }
361
+
362
+    /**
363
+     * Get the response content for the given exception.
364
+     *
365
+     * @param \Throwable $e The throwable exception.
366
+     *
367
+     * @return string
368
+     */
369
+    protected function render_exception_content( Throwable $e ) {
370
+        try {
371
+            return $this->container['config']['app.debug'] && class_exists( Whoops::class )
372
+                        ? $this->render_exception_with_whoops( $e )
373
+                        : $this->render_exception_with_symfony( $e, $this->container['config']['app.debug'] );
374
+        } catch ( Exception $e ) {
375
+            return $this->render_exception_with_symfony( $e, $this->container['config']['app.debug'] );
376
+        }
377
+    }
378
+
379
+    /**
380
+     * Render an exception to a string using "Whoops".
381
+     *
382
+     * @param \Throwable $e The throwable exception.
383
+     *
384
+     * @return string
385
+     */
386
+    protected function render_exception_with_whoops( Throwable $e ) {
387
+        return tap(
388
+            new Whoops(),
389
+            function ( $whoops ) {
390
+                $whoops->appendHandler( $this->whoops_handler() );
391
+
392
+                $whoops->writeToOutput( false );
393
+
394
+                $whoops->allowQuit( false );
395
+            }
396
+        )->handleException( $e );
397
+    }
398
+
399
+    /**
400
+     * Get the Whoops handler for the application.
401
+     *
402
+     * @return \Whoops\Handler\Handler
403
+     */
404
+    protected function whoops_handler() {
405
+        try {
406
+            return $this->container( HandlerInterface::class );
407
+        } catch ( BindingResolutionException $e ) {
408
+            return ( new WhoopsHandler() )->forDebug();
409
+        }
410
+    }
411
+
412
+    /**
413
+     * Render an exception to a string using Symfony.
414
+     *
415
+     * @param \Throwable $e The throwable exception.
416
+     * @param bool       $debug Enable or disable debug.
417
+     *
418
+     * @return string
419
+     */
420
+    protected function render_exception_with_symfony( Throwable $e, $debug ) {
421
+        $renderer = new HtmlErrorRenderer( $debug );
422
+
423
+        return $renderer->getBody( $renderer->render( $e ) );
424
+    }
425
+
426
+    /**
427
+     * Render the given HttpException.
428
+     *
429
+     * @param \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface $e The http exception.
430
+     *
431
+     * @return \Symfony\Component\HttpFoundation\Response
432
+     */
433
+    protected function render_http_exception( HttpExceptionInterface $e ) {
434
+        $this->register_error_view_paths();
435
+        $view = $this->get_http_exception_view( $e );
436
+
437
+        if ( view()->exists( $view ) ) {
438
+            return response()->view(
439
+                $view,
440
+                array(
441
+                    'errors'    => new ViewErrorBag(),
442
+                    'exception' => $e,
443
+                ),
444
+                $e->getStatusCode(),
445
+                $e->getHeaders()
446
+            );
447
+        }
448
+
449
+        return $this->convert_exception_to_response( $e );
450
+    }
451
+
452
+    /**
453
+     * Register the error template hint paths.
454
+     *
455
+     * @return void
456
+     */
457
+    protected function register_error_view_paths() {
458
+        $paths = collect( $this->container['config']['view.paths'] );
459
+
460
+        View::replaceNamespace(
461
+            'errors',
462
+            $paths->map(
463
+                function ( $path ) {
464
+                    return "{$path}/errors";
465
+                }
466
+            )->push( __DIR__ . '/views' )->all()
467
+        );
468
+    }
469
+
470
+    /**
471
+     * Get the view used to render HTTP exceptions.
472
+     *
473
+     * @param \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface $e The http exceptions.
474
+     *
475
+     * @return string
476
+     */
477
+    protected function get_http_exception_view( HttpExceptionInterface $e ) {
478
+        return "errors::{$e->getStatusCode()}";
479
+    }
480
+
481
+    /**
482
+     * Map the given exception into an Illuminate response.
483
+     *
484
+     * @param \Symfony\Component\HttpFoundation\Response $response The app http response.
485
+     * @param \Throwable                                 $e The throwable exception.
486
+     *
487
+     * @return \Illuminate\Http\Response
488
+     */
489
+    protected function to_illuminate_response( $response, Throwable $e ) {
490
+        if ( $response instanceof SymfonyRedirectResponse ) {
491
+            $response = new RedirectResponse(
492
+                $response->getTargetUrl(),
493
+                $response->getStatusCode(),
494
+                $response->headers->all()
495
+            );
496
+        } else {
497
+            $response = new Response(
498
+                $response->getContent(),
499
+                $response->getStatusCode(),
500
+                $response->headers->all()
501
+            );
502
+        }
503
+
504
+        return $response->withException( $e );
505
+    }
506
+
507
+    /**
508
+     * Prepare a JSON response for the given exception.
509
+     *
510
+     * @param \Illuminate\Http\Request $request The app http request.
511
+     * @param \Throwable               $e The throwable exception.
512
+     *
513
+     * @return \Illuminate\Http\JsonResponse
514
+     */
515
+    protected function prepare_json_response( $request, Throwable $e ) {
516
+        return new Json_response(
517
+            $this->convert_exception_to_array( $e ),
518
+            $this->is_http_exception( $e ) ? $e->getStatusCode() : 500,
519
+            $this->is_http_exception( $e ) ? $e->getHeaders() : array(),
520
+            JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
521
+        );
522
+    }
523
+
524
+    /**
525
+     * Convert the given exception to an array.
526
+     *
527
+     * @param \Throwable $e The throwable exception.
528
+     *
529
+     * @return array
530
+     */
531
+    protected function convert_exception_to_array( Throwable $e ) {
532
+        return $this->container['config']['app.debug'] ? array(
533
+            'message'   => $e->getMessage(),
534
+            'exception' => get_class( $e ),
535
+            'file'      => $e->getFile(),
536
+            'line'      => $e->getLine(),
537
+            'trace'     => collect( $e->getTrace() )->map(
538
+                function ( $trace ) {
539
+                    return Arr::except( $trace, array( 'args' ) );
540
+                }
541
+            )->all(),
542
+        ) : array(
543
+            'message' => $this->is_http_exception( $e ) ? $e->getMessage() : 'Server Error',
544
+        );
545
+    }
546
+
547
+    /**
548
+     * Render an exception to the console.
549
+     *
550
+     * @param \Symfony\Component\Console\Output\OutputInterface $output The symfony console output.
551
+     * @param \Throwable                                        $e The throwable exception.
552
+     *
553
+     * @return void
554
+     */
555
+    public function render_for_console( $output, Throwable $e ) {
556
+        ( new ConsoleApplication() )->renderThrowable( $e, $output );
557
+    }
558
+
559
+    /**
560
+     * Determine if the given exception is an HTTP exception.
561
+     *
562
+     * @param \Throwable $e The throwable exception.
563
+     *
564
+     * @return bool
565
+     */
566
+    protected function is_http_exception( Throwable $e ) {
567
+        return $e instanceof HttpExceptionInterface;
568
+    }
569 569
 }
Please login to merge, or discard this patch.
Spacing   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 	 *
102 102
 	 * @return void
103 103
 	 */
104
-	public function __construct( Container $container ) {
104
+	public function __construct(Container $container) {
105 105
 		$this->container = $container;
106 106
 	}
107 107
 
@@ -114,31 +114,31 @@  discard block
 block discarded – undo
114 114
 	 *
115 115
 	 * @return void
116 116
 	 */
117
-	public function report( Throwable $e ) {
118
-		if ( $this->shouldnt_report( $e ) ) {
117
+	public function report(Throwable $e) {
118
+		if ($this->shouldnt_report($e)) {
119 119
 			return;
120 120
 		}
121 121
 
122
-		$report_callable = array( $e, 'report' );
122
+		$report_callable = array($e, 'report');
123 123
 
124
-		if ( is_callable( $report_callable ) ) {
125
-			$this->container->call( $report_callable );
124
+		if (is_callable($report_callable)) {
125
+			$this->container->call($report_callable);
126 126
 
127 127
 			return;
128 128
 		}
129 129
 
130 130
 		try {
131
-			$logger = $this->container->make( LoggerInterface::class );
132
-		} catch ( Exception $ex ) {
131
+			$logger = $this->container->make(LoggerInterface::class);
132
+		} catch (Exception $ex) {
133 133
 			throw $e;
134 134
 		}
135 135
 
136 136
 		$logger->error(
137 137
 			$e->getMessage(),
138 138
 			array_merge(
139
-				$this->exception_context( $e ),
139
+				$this->exception_context($e),
140 140
 				$this->context(),
141
-				array( 'exception' => $e )
141
+				array('exception' => $e)
142 142
 			)
143 143
 		);
144 144
 	}
@@ -150,8 +150,8 @@  discard block
 block discarded – undo
150 150
 	 *
151 151
 	 * @return bool
152 152
 	 */
153
-	public function should_report( Throwable $e ) {
154
-		return ! $this->shouldnt_report( $e );
153
+	public function should_report(Throwable $e) {
154
+		return !$this->shouldnt_report($e);
155 155
 	}
156 156
 
157 157
 	/**
@@ -161,13 +161,13 @@  discard block
 block discarded – undo
161 161
 	 *
162 162
 	 * @return bool
163 163
 	 */
164
-	protected function shouldnt_report( Throwable $e ) {
165
-		$dont_report = array_merge( $this->dont_report, $this->internal_dont_report );
164
+	protected function shouldnt_report(Throwable $e) {
165
+		$dont_report = array_merge($this->dont_report, $this->internal_dont_report);
166 166
 
167
-		return ! is_null(
167
+		return !is_null(
168 168
 			Arr::first(
169 169
 				$dont_report,
170
-				function ( $type ) use ( $e ) {
170
+				function($type) use ($e) {
171 171
 					return $e instanceof $type;
172 172
 				}
173 173
 			)
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 	 *
182 182
 	 * @return array
183 183
 	 */
184
-	protected function exception_context( Throwable $e ) {
184
+	protected function exception_context(Throwable $e) {
185 185
 		return array();
186 186
 	}
187 187
 
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 				// 'email' => optional(Auth::user())->email,
199 199
 				)
200 200
 			);
201
-		} catch ( Throwable $e ) {
201
+		} catch (Throwable $e) {
202 202
 			return array();
203 203
 		}
204 204
 	}
@@ -213,27 +213,27 @@  discard block
 block discarded – undo
213 213
 	 *
214 214
 	 * @return \Symfony\Component\HttpFoundation\Response
215 215
 	 */
216
-	public function render( $request, Throwable $e ) {
217
-		$response = $e->render( $request );
218
-		if ( method_exists( $e, 'render' ) && $response ) {
219
-			return Router::toResponse( $request, $response );
220
-		} elseif ( $e instanceof Responsable ) {
221
-			return $e->toResponse( $request );
216
+	public function render($request, Throwable $e) {
217
+		$response = $e->render($request);
218
+		if (method_exists($e, 'render') && $response) {
219
+			return Router::toResponse($request, $response);
220
+		} elseif ($e instanceof Responsable) {
221
+			return $e->toResponse($request);
222 222
 		}
223 223
 
224
-		$e = $this->prepare_exception( $e );
224
+		$e = $this->prepare_exception($e);
225 225
 
226
-		if ( $e instanceof HttpResponseException ) {
226
+		if ($e instanceof HttpResponseException) {
227 227
 			return $e->getResponse();
228
-		} elseif ( $e instanceof AuthenticationException ) {
229
-			return $this->unauthenticated( $request, $e );
230
-		} elseif ( $e instanceof ValidationException ) {
231
-			return $this->convert_validation_exception_to_response( $e, $request );
228
+		} elseif ($e instanceof AuthenticationException) {
229
+			return $this->unauthenticated($request, $e);
230
+		} elseif ($e instanceof ValidationException) {
231
+			return $this->convert_validation_exception_to_response($e, $request);
232 232
 		}
233 233
 
234 234
 		return $request->expectsJson()
235
-					? $this->prepare_json_response( $request, $e )
236
-					: $this->prepare_response( $request, $e );
235
+					? $this->prepare_json_response($request, $e)
236
+					: $this->prepare_response($request, $e);
237 237
 	}
238 238
 
239 239
 	/**
@@ -243,15 +243,15 @@  discard block
 block discarded – undo
243 243
 	 *
244 244
 	 * @return \Throwable
245 245
 	 */
246
-	protected function prepare_exception( Throwable $e ) {
247
-		if ( $e instanceof ModelNotFoundException ) {
248
-			$e = new NotFoundHttpException( $e->getMessage(), $e );
249
-		} elseif ( $e instanceof AuthorizationException ) {
250
-			$e = new AccessDeniedHttpException( $e->getMessage(), $e );
251
-		} elseif ( $e instanceof TokenMismatchException ) {
252
-			$e = new HttpException( 419, $e->getMessage(), $e );
253
-		} elseif ( $e instanceof SuspiciousOperationException ) {
254
-			$e = new NotFoundHttpException( 'Bad hostname provided.', $e );
246
+	protected function prepare_exception(Throwable $e) {
247
+		if ($e instanceof ModelNotFoundException) {
248
+			$e = new NotFoundHttpException($e->getMessage(), $e);
249
+		} elseif ($e instanceof AuthorizationException) {
250
+			$e = new AccessDeniedHttpException($e->getMessage(), $e);
251
+		} elseif ($e instanceof TokenMismatchException) {
252
+			$e = new HttpException(419, $e->getMessage(), $e);
253
+		} elseif ($e instanceof SuspiciousOperationException) {
254
+			$e = new NotFoundHttpException('Bad hostname provided.', $e);
255 255
 		}
256 256
 
257 257
 		return $e;
@@ -265,10 +265,10 @@  discard block
 block discarded – undo
265 265
 	 *
266 266
 	 * @return \Symfony\Component\HttpFoundation\Response
267 267
 	 */
268
-	protected function unauthenticated( $request, AuthenticationException $exception ) {
268
+	protected function unauthenticated($request, AuthenticationException $exception) {
269 269
 		return $request->expectsJson()
270
-					? response()->json( array( 'message' => $exception->getMessage() ), 401 )
271
-					: redirect()->guest( $exception->redirectTo() ?? route( 'login' ) );
270
+					? response()->json(array('message' => $exception->getMessage()), 401)
271
+					: redirect()->guest($exception->redirectTo() ?? route('login'));
272 272
 	}
273 273
 
274 274
 	/**
@@ -279,14 +279,14 @@  discard block
 block discarded – undo
279 279
 	 *
280 280
 	 * @return \Symfony\Component\HttpFoundation\Response
281 281
 	 */
282
-	protected function convert_validation_exception_to_response( ValidationException $e, $request ) {
283
-		if ( $e->response ) {
282
+	protected function convert_validation_exception_to_response(ValidationException $e, $request) {
283
+		if ($e->response) {
284 284
 			return $e->response;
285 285
 		}
286 286
 
287 287
 		return $request->expectsJson()
288
-					? $this->invalid_json( $request, $e )
289
-					: $this->invalid( $request, $e );
288
+					? $this->invalid_json($request, $e)
289
+					: $this->invalid($request, $e);
290 290
 	}
291 291
 
292 292
 	/**
@@ -297,10 +297,10 @@  discard block
 block discarded – undo
297 297
 	 *
298 298
 	 * @return \Illuminate\Http\Response
299 299
 	 */
300
-	protected function invalid( $request, ValidationException $exception ) {
301
-		return redirect( $exception->redirectTo ?? url()->previous() )
302
-					->withInput( Arr::except( $request->input(), $this->dont_flash ) )
303
-					->withErrors( $exception->errors(), $exception->errorBag );
300
+	protected function invalid($request, ValidationException $exception) {
301
+		return redirect($exception->redirectTo ?? url()->previous())
302
+					->withInput(Arr::except($request->input(), $this->dont_flash))
303
+					->withErrors($exception->errors(), $exception->errorBag);
304 304
 	}
305 305
 
306 306
 	/**
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 	 *
312 312
 	 * @return \Illuminate\Http\JsonResponse
313 313
 	 */
314
-	protected function invalid_json( $request, ValidationException $exception ) {
314
+	protected function invalid_json($request, ValidationException $exception) {
315 315
 		return response()->json(
316 316
 			array(
317 317
 				'message' => $exception->getMessage(),
@@ -329,17 +329,17 @@  discard block
 block discarded – undo
329 329
 	 *
330 330
 	 * @return \Symfony\Component\HttpFoundation\Response
331 331
 	 */
332
-	protected function prepare_response( $request, Throwable $e ) {
333
-		if ( ! $this->is_http_exception( $e ) && $this->container['config']['app.debug'] ) {
334
-			return $this->to_illuminate_response( $this->convert_exception_to_response( $e ), $e );
332
+	protected function prepare_response($request, Throwable $e) {
333
+		if (!$this->is_http_exception($e) && $this->container['config']['app.debug']) {
334
+			return $this->to_illuminate_response($this->convert_exception_to_response($e), $e);
335 335
 		}
336 336
 
337
-		if ( ! $this->is_http_exception( $e ) ) {
338
-			$e = new HttpException( 500, $e->getMessage() );
337
+		if (!$this->is_http_exception($e)) {
338
+			$e = new HttpException(500, $e->getMessage());
339 339
 		}
340 340
 
341 341
 		return $this->to_illuminate_response(
342
-			$this->render_http_exception( $e ),
342
+			$this->render_http_exception($e),
343 343
 			$e
344 344
 		);
345 345
 	}
@@ -351,11 +351,11 @@  discard block
 block discarded – undo
351 351
 	 *
352 352
 	 * @return \Symfony\Component\HttpFoundation\Response
353 353
 	 */
354
-	protected function convert_exception_to_response( Throwable $e ) {
354
+	protected function convert_exception_to_response(Throwable $e) {
355 355
 		return SymfonyResponse::create(
356
-			$this->render_exception_content( $e ),
357
-			$this->is_http_exception( $e ) ? $e->getStatusCode() : 500,
358
-			$this->is_http_exception( $e ) ? $e->getHeaders() : array()
356
+			$this->render_exception_content($e),
357
+			$this->is_http_exception($e) ? $e->getStatusCode() : 500,
358
+			$this->is_http_exception($e) ? $e->getHeaders() : array()
359 359
 		);
360 360
 	}
361 361
 
@@ -366,13 +366,13 @@  discard block
 block discarded – undo
366 366
 	 *
367 367
 	 * @return string
368 368
 	 */
369
-	protected function render_exception_content( Throwable $e ) {
369
+	protected function render_exception_content(Throwable $e) {
370 370
 		try {
371
-			return $this->container['config']['app.debug'] && class_exists( Whoops::class )
372
-						? $this->render_exception_with_whoops( $e )
373
-						: $this->render_exception_with_symfony( $e, $this->container['config']['app.debug'] );
374
-		} catch ( Exception $e ) {
375
-			return $this->render_exception_with_symfony( $e, $this->container['config']['app.debug'] );
371
+			return $this->container['config']['app.debug'] && class_exists(Whoops::class)
372
+						? $this->render_exception_with_whoops($e)
373
+						: $this->render_exception_with_symfony($e, $this->container['config']['app.debug']);
374
+		} catch (Exception $e) {
375
+			return $this->render_exception_with_symfony($e, $this->container['config']['app.debug']);
376 376
 		}
377 377
 	}
378 378
 
@@ -383,17 +383,17 @@  discard block
 block discarded – undo
383 383
 	 *
384 384
 	 * @return string
385 385
 	 */
386
-	protected function render_exception_with_whoops( Throwable $e ) {
386
+	protected function render_exception_with_whoops(Throwable $e) {
387 387
 		return tap(
388 388
 			new Whoops(),
389
-			function ( $whoops ) {
390
-				$whoops->appendHandler( $this->whoops_handler() );
389
+			function($whoops) {
390
+				$whoops->appendHandler($this->whoops_handler());
391 391
 
392
-				$whoops->writeToOutput( false );
392
+				$whoops->writeToOutput(false);
393 393
 
394
-				$whoops->allowQuit( false );
394
+				$whoops->allowQuit(false);
395 395
 			}
396
-		)->handleException( $e );
396
+		)->handleException($e);
397 397
 	}
398 398
 
399 399
 	/**
@@ -403,9 +403,9 @@  discard block
 block discarded – undo
403 403
 	 */
404 404
 	protected function whoops_handler() {
405 405
 		try {
406
-			return $this->container( HandlerInterface::class );
407
-		} catch ( BindingResolutionException $e ) {
408
-			return ( new WhoopsHandler() )->forDebug();
406
+			return $this->container(HandlerInterface::class);
407
+		} catch (BindingResolutionException $e) {
408
+			return (new WhoopsHandler())->forDebug();
409 409
 		}
410 410
 	}
411 411
 
@@ -417,10 +417,10 @@  discard block
 block discarded – undo
417 417
 	 *
418 418
 	 * @return string
419 419
 	 */
420
-	protected function render_exception_with_symfony( Throwable $e, $debug ) {
421
-		$renderer = new HtmlErrorRenderer( $debug );
420
+	protected function render_exception_with_symfony(Throwable $e, $debug) {
421
+		$renderer = new HtmlErrorRenderer($debug);
422 422
 
423
-		return $renderer->getBody( $renderer->render( $e ) );
423
+		return $renderer->getBody($renderer->render($e));
424 424
 	}
425 425
 
426 426
 	/**
@@ -430,11 +430,11 @@  discard block
 block discarded – undo
430 430
 	 *
431 431
 	 * @return \Symfony\Component\HttpFoundation\Response
432 432
 	 */
433
-	protected function render_http_exception( HttpExceptionInterface $e ) {
433
+	protected function render_http_exception(HttpExceptionInterface $e) {
434 434
 		$this->register_error_view_paths();
435
-		$view = $this->get_http_exception_view( $e );
435
+		$view = $this->get_http_exception_view($e);
436 436
 
437
-		if ( view()->exists( $view ) ) {
437
+		if (view()->exists($view)) {
438 438
 			return response()->view(
439 439
 				$view,
440 440
 				array(
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 			);
447 447
 		}
448 448
 
449
-		return $this->convert_exception_to_response( $e );
449
+		return $this->convert_exception_to_response($e);
450 450
 	}
451 451
 
452 452
 	/**
@@ -455,15 +455,15 @@  discard block
 block discarded – undo
455 455
 	 * @return void
456 456
 	 */
457 457
 	protected function register_error_view_paths() {
458
-		$paths = collect( $this->container['config']['view.paths'] );
458
+		$paths = collect($this->container['config']['view.paths']);
459 459
 
460 460
 		View::replaceNamespace(
461 461
 			'errors',
462 462
 			$paths->map(
463
-				function ( $path ) {
463
+				function($path) {
464 464
 					return "{$path}/errors";
465 465
 				}
466
-			)->push( __DIR__ . '/views' )->all()
466
+			)->push(__DIR__.'/views')->all()
467 467
 		);
468 468
 	}
469 469
 
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
 	 *
475 475
 	 * @return string
476 476
 	 */
477
-	protected function get_http_exception_view( HttpExceptionInterface $e ) {
477
+	protected function get_http_exception_view(HttpExceptionInterface $e) {
478 478
 		return "errors::{$e->getStatusCode()}";
479 479
 	}
480 480
 
@@ -486,8 +486,8 @@  discard block
 block discarded – undo
486 486
 	 *
487 487
 	 * @return \Illuminate\Http\Response
488 488
 	 */
489
-	protected function to_illuminate_response( $response, Throwable $e ) {
490
-		if ( $response instanceof SymfonyRedirectResponse ) {
489
+	protected function to_illuminate_response($response, Throwable $e) {
490
+		if ($response instanceof SymfonyRedirectResponse) {
491 491
 			$response = new RedirectResponse(
492 492
 				$response->getTargetUrl(),
493 493
 				$response->getStatusCode(),
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
 			);
502 502
 		}
503 503
 
504
-		return $response->withException( $e );
504
+		return $response->withException($e);
505 505
 	}
506 506
 
507 507
 	/**
@@ -512,11 +512,11 @@  discard block
 block discarded – undo
512 512
 	 *
513 513
 	 * @return \Illuminate\Http\JsonResponse
514 514
 	 */
515
-	protected function prepare_json_response( $request, Throwable $e ) {
515
+	protected function prepare_json_response($request, Throwable $e) {
516 516
 		return new Json_response(
517
-			$this->convert_exception_to_array( $e ),
518
-			$this->is_http_exception( $e ) ? $e->getStatusCode() : 500,
519
-			$this->is_http_exception( $e ) ? $e->getHeaders() : array(),
517
+			$this->convert_exception_to_array($e),
518
+			$this->is_http_exception($e) ? $e->getStatusCode() : 500,
519
+			$this->is_http_exception($e) ? $e->getHeaders() : array(),
520 520
 			JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
521 521
 		);
522 522
 	}
@@ -528,19 +528,19 @@  discard block
 block discarded – undo
528 528
 	 *
529 529
 	 * @return array
530 530
 	 */
531
-	protected function convert_exception_to_array( Throwable $e ) {
531
+	protected function convert_exception_to_array(Throwable $e) {
532 532
 		return $this->container['config']['app.debug'] ? array(
533 533
 			'message'   => $e->getMessage(),
534
-			'exception' => get_class( $e ),
534
+			'exception' => get_class($e),
535 535
 			'file'      => $e->getFile(),
536 536
 			'line'      => $e->getLine(),
537
-			'trace'     => collect( $e->getTrace() )->map(
538
-				function ( $trace ) {
539
-					return Arr::except( $trace, array( 'args' ) );
537
+			'trace'     => collect($e->getTrace())->map(
538
+				function($trace) {
539
+					return Arr::except($trace, array('args'));
540 540
 				}
541 541
 			)->all(),
542 542
 		) : array(
543
-			'message' => $this->is_http_exception( $e ) ? $e->getMessage() : 'Server Error',
543
+			'message' => $this->is_http_exception($e) ? $e->getMessage() : 'Server Error',
544 544
 		);
545 545
 	}
546 546
 
@@ -552,8 +552,8 @@  discard block
 block discarded – undo
552 552
 	 *
553 553
 	 * @return void
554 554
 	 */
555
-	public function render_for_console( $output, Throwable $e ) {
556
-		( new ConsoleApplication() )->renderThrowable( $e, $output );
555
+	public function render_for_console($output, Throwable $e) {
556
+		(new ConsoleApplication())->renderThrowable($e, $output);
557 557
 	}
558 558
 
559 559
 	/**
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
 	 *
564 564
 	 * @return bool
565 565
 	 */
566
-	protected function is_http_exception( Throwable $e ) {
566
+	protected function is_http_exception(Throwable $e) {
567 567
 		return $e instanceof HttpExceptionInterface;
568 568
 	}
569 569
 }
Please login to merge, or discard this patch.
src/Http/Kernel.php 2 patches
Indentation   +406 added lines, -406 removed lines patch added patch discarded remove patch
@@ -31,410 +31,410 @@
 block discarded – undo
31 31
  */
32 32
 class Kernel implements KernelContract {
33 33
 
34
-	/**
35
-	 * The application implementation.
36
-	 *
37
-	 * @var \Illuminate\Contracts\Foundation\Application
38
-	 */
39
-	protected $app;
40
-
41
-	/**
42
-	 * The router instance.
43
-	 *
44
-	 * @var \Illuminate\Routing\Router
45
-	 */
46
-	protected $router;
47
-
48
-	/**
49
-	 * The bootstrap classes for the application.
50
-	 *
51
-	 * @var array
52
-	 */
53
-	protected $bootstrappers = array();
54
-
55
-	/**
56
-	 * The application's middleware stack.
57
-	 *
58
-	 * @var array
59
-	 */
60
-	protected $middleware = array();
61
-
62
-	/**
63
-	 * The application's route middleware groups.
64
-	 *
65
-	 * @var array
66
-	 */
67
-	protected $middleware_groups = array();
68
-
69
-	/**
70
-	 * The application's route middleware.
71
-	 *
72
-	 * @var array
73
-	 */
74
-	protected $route_middleware = array();
75
-
76
-	/**
77
-	 * The priority-sorted list of middleware.
78
-	 *
79
-	 * Forces non-global middleware to always be in the given order.
80
-	 *
81
-	 * @var array
82
-	 */
83
-	protected $middleware_priority = array();
84
-
85
-	/**
86
-	 * Create a new HTTP kernel instance.
87
-	 *
88
-	 * @param \Illuminate\Contracts\Container\Container $app The app.
89
-	 * @param \Illuminate\Routing\Router                $router The app router.
90
-	 *
91
-	 * @return void
92
-	 */
93
-	public function __construct( Container $app, Router $router ) {
94
-		$this->app    = $app;
95
-		$this->router = $router;
96
-
97
-		$this->sync_middleware_to_router();
98
-	}
99
-
100
-	/**
101
-	 * Handle an incoming HTTP request.
102
-	 *
103
-	 * @param \Illuminate\Http\Request $request The app http request.
104
-	 *
105
-	 * @throws \Exception The throwable exception.
106
-	 *
107
-	 * @return \Illuminate\Http\Response
108
-	 */
109
-	public function handle( $request ) {
110
-		try {
111
-			$request->enableHttpMethodParameterOverride();
112
-			$response = $this->send_request_through_router( $request );
113
-		} catch ( Throwable $e ) {
114
-			$this->report_exception( $e );
115
-			$response = $this->render_exception( $request, $e );
116
-		}
117
-
118
-		$this->app['events']->dispatch(
119
-			new RequestHandled( $request, $response )
120
-		);
121
-
122
-		return $response;
123
-	}
124
-
125
-	/**
126
-	 * Send the given request through the middleware / router.
127
-	 *
128
-	 * @param \Illuminate\Http\Request $request The app http request.
129
-	 *
130
-	 * @return \Illuminate\Http\Response
131
-	 */
132
-	protected function send_request_through_router( $request ) {
133
-		$this->app->instance( 'request', $request );
134
-
135
-		Facade::clearResolvedInstance( 'request' );
136
-
137
-		$this->bootstrap();
138
-
139
-		return ( new Pipeline( $this->app ) )
140
-					->send( $request )
141
-					->through( $this->middleware )
142
-					->then( $this->dispatch_to_router() );
143
-	}
144
-
145
-	/**
146
-	 * Bootstrap the application for HTTP requests.
147
-	 *
148
-	 * @return void
149
-	 */
150
-	public function bootstrap() {}
151
-
152
-	/**
153
-	 * Get the route dispatcher callback.
154
-	 *
155
-	 * @return \Closure
156
-	 */
157
-	protected function dispatch_to_router() {
158
-		return function ( $request ) {
159
-			$this->app->instance( 'request', $request );
160
-
161
-			return $this->router->dispatch( $request );
162
-		};
163
-	}
164
-
165
-	/**
166
-	 * Call the terminate method on any terminable middleware.
167
-	 *
168
-	 * @param \Illuminate\Http\Request  $request The app http request.
169
-	 * @param \Illuminate\Http\Response $response The app http response.
170
-	 *
171
-	 * @return void
172
-	 */
173
-	public function terminate( $request, $response ) {
174
-		$this->terminate_middleware( $request, $response );
175
-
176
-		$this->app->terminate();
177
-	}
178
-
179
-	/**
180
-	 * Call the terminate method on any terminable middleware.
181
-	 *
182
-	 * @param \Illuminate\Http\Request  $request The app http request.
183
-	 * @param \Illuminate\Http\Response $response The app http response.
184
-	 *
185
-	 * @return void
186
-	 */
187
-	protected function terminate_middleware( $request, $response ) {
188
-		$middlewares = $this->app->shouldSkipMiddleware() ? array() : array_merge(
189
-			$this->gather_route_middleware( $request ),
190
-			$this->middleware
191
-		);
192
-
193
-		foreach ( $middlewares as $middleware ) {
194
-			if ( ! is_string( $middleware ) ) {
195
-				continue;
196
-			}
197
-
198
-			list( $name ) = $this->parse_middleware( $middleware );
199
-
200
-			$instance = $this->app->make( $name );
201
-
202
-			if ( method_exists( $instance, 'terminate' ) ) {
203
-				$instance->terminate( $request, $response );
204
-			}
205
-		}
206
-	}
207
-
208
-	/**
209
-	 * Gather the route middleware for the given request.
210
-	 *
211
-	 * @param \Illuminate\Http\Request $request The app http request.
212
-	 *
213
-	 * @return array
214
-	 */
215
-	protected function gather_route_middleware( $request ) {
216
-		$route = $request->route();
217
-		if ( $route ) {
218
-			return $this->router->gatherRouteMiddleware( $route );
219
-		}
220
-
221
-		return array();
222
-	}
223
-
224
-	/**
225
-	 * Parse a middleware string to get the name and parameters.
226
-	 *
227
-	 * @param string $middleware The app middleware.
228
-	 *
229
-	 * @return array
230
-	 */
231
-	protected function parse_middleware( $middleware ) {
232
-
233
-		list( $name, $parameters ) = array_pad( explode( ':', $middleware, 2 ), 2, array() );
234
-
235
-		if ( is_string( $parameters ) ) {
236
-			$parameters = explode( ',', $parameters );
237
-		}
238
-
239
-		return array( $name, $parameters );
240
-	}
241
-
242
-	/**
243
-	 * Determine if the kernel has a given middleware.
244
-	 *
245
-	 * @param string $middleware The app middleware.
246
-	 *
247
-	 * @return bool
248
-	 */
249
-	public function has_middleware( $middleware ) {
250
-		return in_array( $middleware, $this->middleware );
251
-	}
252
-
253
-	/**
254
-	 * Add a new middleware to beginning of the stack if it does not already exist.
255
-	 *
256
-	 * @param string $middleware The app middleware.
257
-	 *
258
-	 * @return $this
259
-	 */
260
-	public function prepend_middleware( $middleware ) {
261
-		if ( array_search( $middleware, $this->middleware ) === false ) {
262
-			array_unshift( $this->middleware, $middleware );
263
-		}
264
-
265
-		return $this;
266
-	}
267
-
268
-	/**
269
-	 * Add a new middleware to end of the stack if it does not already exist.
270
-	 *
271
-	 * @param string $middleware The app middleware.
272
-	 *
273
-	 * @return $this
274
-	 */
275
-	public function push_middleware( $middleware ) {
276
-		if ( array_search( $middleware, $this->middleware ) === false ) {
277
-			$this->middleware[] = $middleware;
278
-		}
279
-
280
-		return $this;
281
-	}
282
-
283
-	/**
284
-	 * Prepend the given middleware to the given middleware group.
285
-	 *
286
-	 * @param string $group The app group.
287
-	 * @param string $middleware The app middleware.
288
-	 *
289
-	 * @throws \InvalidArgumentException The invalid argument exception.
290
-	 *
291
-	 * @return $this
292
-	 */
293
-	public function prepend_middleware_to_group( $group, $middleware ) {
294
-		if ( ! isset( $this->middleware_groups[ $group ] ) ) {
295
-			throw new InvalidArgumentException( "The [{$group}] middleware group has not been defined." );
296
-		}
297
-
298
-		if ( array_search( $middleware, $this->middleware_groups[ $group ] ) === false ) {
299
-			array_unshift( $this->middleware_groups[ $group ], $middleware );
300
-		}
301
-
302
-		$this->sync_middleware_to_router();
303
-
304
-		return $this;
305
-	}
306
-
307
-	/**
308
-	 * Append the given middleware to the given middleware group.
309
-	 *
310
-	 * @param string $group The app group.
311
-	 * @param string $middleware The app middleware.
312
-	 *
313
-	 * @throws \InvalidArgumentException The invalid argument exception.
314
-	 *
315
-	 * @return $this
316
-	 */
317
-	public function append_middleware_to_group( $group, $middleware ) {
318
-		if ( ! isset( $this->middleware_groups[ $group ] ) ) {
319
-			throw new InvalidArgumentException( "The [{$group}] middleware group has not been defined." );
320
-		}
321
-
322
-		if ( array_search( $middleware, $this->middleware_groups[ $group ] ) === false ) {
323
-			$this->middleware_groups[ $group ][] = $middleware;
324
-		}
325
-
326
-		$this->sync_middleware_to_router();
327
-
328
-		return $this;
329
-	}
330
-
331
-	/**
332
-	 * Prepend the given middleware to the middleware priority list.
333
-	 *
334
-	 * @param string $middleware The app middleware.
335
-	 *
336
-	 * @return $this
337
-	 */
338
-	public function prepend_to_middleware_priority( $middleware ) {
339
-		if ( ! in_array( $middleware, $this->middleware_priority ) ) {
340
-			array_unshift( $this->middleware_priority, $middleware );
341
-		}
342
-
343
-		$this->sync_middleware_to_router();
344
-
345
-		return $this;
346
-	}
347
-
348
-	/**
349
-	 * Append the given middleware to the middleware priority list.
350
-	 *
351
-	 * @param string $middleware The app middleware.
352
-	 *
353
-	 * @return $this
354
-	 */
355
-	public function append_to_middleware_priority( $middleware ) {
356
-		if ( ! in_array( $middleware, $this->middleware_priority ) ) {
357
-			$this->middleware_priority[] = $middleware;
358
-		}
359
-
360
-		$this->sync_middleware_to_router();
361
-
362
-		return $this;
363
-	}
364
-
365
-	/**
366
-	 * Sync the current state of the middleware to the router.
367
-	 *
368
-	 * @return void
369
-	 */
370
-	protected function sync_middleware_to_router() {
371
-		$this->router->middlewarePriority = $this->middleware_priority;
372
-
373
-		foreach ( $this->middleware_groups as $key => $middleware ) {
374
-			$this->router->middlewareGroup( $key, $middleware );
375
-		}
376
-
377
-		foreach ( $this->route_middleware as $key => $middleware ) {
378
-			$this->router->aliasMiddleware( $key, $middleware );
379
-		}
380
-	}
381
-
382
-	/**
383
-	 * Get the bootstrap classes for the application.
384
-	 *
385
-	 * @return array
386
-	 */
387
-	protected function bootstrappers() {
388
-		return $this->bootstrappers;
389
-	}
390
-
391
-	/**
392
-	 * Report the exception to the exception handler.
393
-	 *
394
-	 * @param \Throwable $e The throwable exception.
395
-	 *
396
-	 * @return void
397
-	 */
398
-	protected function report_exception( Throwable $e ) {
399
-		$this->app[ ExceptionHandler::class ]->report( $e );
400
-	}
401
-
402
-	/**
403
-	 * Render the exception to a response.
404
-	 *
405
-	 * @param \Illuminate\Http\Request $request The app http request.
406
-	 * @param \Throwable               $e The throwable exception.
407
-	 *
408
-	 * @return \Symfony\Component\HttpFoundation\Response
409
-	 */
410
-	protected function render_exception( $request, Throwable $e ) {
411
-		return $this->app[ ExceptionHandler::class ]->render( $request, $e );
412
-	}
413
-
414
-	/**
415
-	 * Get the application's route middleware groups.
416
-	 *
417
-	 * @return array
418
-	 */
419
-	public function get_middleware_groups() {
420
-		return $this->middleware_groups;
421
-	}
422
-
423
-	/**
424
-	 * Get the application's route middleware.
425
-	 *
426
-	 * @return array
427
-	 */
428
-	public function get_route_middleware() {
429
-		return $this->route_middleware;
430
-	}
431
-
432
-	/**
433
-	 * Get the Laravel application instance.
434
-	 *
435
-	 * @return \Illuminate\Contracts\Foundation\Application
436
-	 */
437
-	public function get_application() {
438
-		return $this->app;
439
-	}
34
+    /**
35
+     * The application implementation.
36
+     *
37
+     * @var \Illuminate\Contracts\Foundation\Application
38
+     */
39
+    protected $app;
40
+
41
+    /**
42
+     * The router instance.
43
+     *
44
+     * @var \Illuminate\Routing\Router
45
+     */
46
+    protected $router;
47
+
48
+    /**
49
+     * The bootstrap classes for the application.
50
+     *
51
+     * @var array
52
+     */
53
+    protected $bootstrappers = array();
54
+
55
+    /**
56
+     * The application's middleware stack.
57
+     *
58
+     * @var array
59
+     */
60
+    protected $middleware = array();
61
+
62
+    /**
63
+     * The application's route middleware groups.
64
+     *
65
+     * @var array
66
+     */
67
+    protected $middleware_groups = array();
68
+
69
+    /**
70
+     * The application's route middleware.
71
+     *
72
+     * @var array
73
+     */
74
+    protected $route_middleware = array();
75
+
76
+    /**
77
+     * The priority-sorted list of middleware.
78
+     *
79
+     * Forces non-global middleware to always be in the given order.
80
+     *
81
+     * @var array
82
+     */
83
+    protected $middleware_priority = array();
84
+
85
+    /**
86
+     * Create a new HTTP kernel instance.
87
+     *
88
+     * @param \Illuminate\Contracts\Container\Container $app The app.
89
+     * @param \Illuminate\Routing\Router                $router The app router.
90
+     *
91
+     * @return void
92
+     */
93
+    public function __construct( Container $app, Router $router ) {
94
+        $this->app    = $app;
95
+        $this->router = $router;
96
+
97
+        $this->sync_middleware_to_router();
98
+    }
99
+
100
+    /**
101
+     * Handle an incoming HTTP request.
102
+     *
103
+     * @param \Illuminate\Http\Request $request The app http request.
104
+     *
105
+     * @throws \Exception The throwable exception.
106
+     *
107
+     * @return \Illuminate\Http\Response
108
+     */
109
+    public function handle( $request ) {
110
+        try {
111
+            $request->enableHttpMethodParameterOverride();
112
+            $response = $this->send_request_through_router( $request );
113
+        } catch ( Throwable $e ) {
114
+            $this->report_exception( $e );
115
+            $response = $this->render_exception( $request, $e );
116
+        }
117
+
118
+        $this->app['events']->dispatch(
119
+            new RequestHandled( $request, $response )
120
+        );
121
+
122
+        return $response;
123
+    }
124
+
125
+    /**
126
+     * Send the given request through the middleware / router.
127
+     *
128
+     * @param \Illuminate\Http\Request $request The app http request.
129
+     *
130
+     * @return \Illuminate\Http\Response
131
+     */
132
+    protected function send_request_through_router( $request ) {
133
+        $this->app->instance( 'request', $request );
134
+
135
+        Facade::clearResolvedInstance( 'request' );
136
+
137
+        $this->bootstrap();
138
+
139
+        return ( new Pipeline( $this->app ) )
140
+                    ->send( $request )
141
+                    ->through( $this->middleware )
142
+                    ->then( $this->dispatch_to_router() );
143
+    }
144
+
145
+    /**
146
+     * Bootstrap the application for HTTP requests.
147
+     *
148
+     * @return void
149
+     */
150
+    public function bootstrap() {}
151
+
152
+    /**
153
+     * Get the route dispatcher callback.
154
+     *
155
+     * @return \Closure
156
+     */
157
+    protected function dispatch_to_router() {
158
+        return function ( $request ) {
159
+            $this->app->instance( 'request', $request );
160
+
161
+            return $this->router->dispatch( $request );
162
+        };
163
+    }
164
+
165
+    /**
166
+     * Call the terminate method on any terminable middleware.
167
+     *
168
+     * @param \Illuminate\Http\Request  $request The app http request.
169
+     * @param \Illuminate\Http\Response $response The app http response.
170
+     *
171
+     * @return void
172
+     */
173
+    public function terminate( $request, $response ) {
174
+        $this->terminate_middleware( $request, $response );
175
+
176
+        $this->app->terminate();
177
+    }
178
+
179
+    /**
180
+     * Call the terminate method on any terminable middleware.
181
+     *
182
+     * @param \Illuminate\Http\Request  $request The app http request.
183
+     * @param \Illuminate\Http\Response $response The app http response.
184
+     *
185
+     * @return void
186
+     */
187
+    protected function terminate_middleware( $request, $response ) {
188
+        $middlewares = $this->app->shouldSkipMiddleware() ? array() : array_merge(
189
+            $this->gather_route_middleware( $request ),
190
+            $this->middleware
191
+        );
192
+
193
+        foreach ( $middlewares as $middleware ) {
194
+            if ( ! is_string( $middleware ) ) {
195
+                continue;
196
+            }
197
+
198
+            list( $name ) = $this->parse_middleware( $middleware );
199
+
200
+            $instance = $this->app->make( $name );
201
+
202
+            if ( method_exists( $instance, 'terminate' ) ) {
203
+                $instance->terminate( $request, $response );
204
+            }
205
+        }
206
+    }
207
+
208
+    /**
209
+     * Gather the route middleware for the given request.
210
+     *
211
+     * @param \Illuminate\Http\Request $request The app http request.
212
+     *
213
+     * @return array
214
+     */
215
+    protected function gather_route_middleware( $request ) {
216
+        $route = $request->route();
217
+        if ( $route ) {
218
+            return $this->router->gatherRouteMiddleware( $route );
219
+        }
220
+
221
+        return array();
222
+    }
223
+
224
+    /**
225
+     * Parse a middleware string to get the name and parameters.
226
+     *
227
+     * @param string $middleware The app middleware.
228
+     *
229
+     * @return array
230
+     */
231
+    protected function parse_middleware( $middleware ) {
232
+
233
+        list( $name, $parameters ) = array_pad( explode( ':', $middleware, 2 ), 2, array() );
234
+
235
+        if ( is_string( $parameters ) ) {
236
+            $parameters = explode( ',', $parameters );
237
+        }
238
+
239
+        return array( $name, $parameters );
240
+    }
241
+
242
+    /**
243
+     * Determine if the kernel has a given middleware.
244
+     *
245
+     * @param string $middleware The app middleware.
246
+     *
247
+     * @return bool
248
+     */
249
+    public function has_middleware( $middleware ) {
250
+        return in_array( $middleware, $this->middleware );
251
+    }
252
+
253
+    /**
254
+     * Add a new middleware to beginning of the stack if it does not already exist.
255
+     *
256
+     * @param string $middleware The app middleware.
257
+     *
258
+     * @return $this
259
+     */
260
+    public function prepend_middleware( $middleware ) {
261
+        if ( array_search( $middleware, $this->middleware ) === false ) {
262
+            array_unshift( $this->middleware, $middleware );
263
+        }
264
+
265
+        return $this;
266
+    }
267
+
268
+    /**
269
+     * Add a new middleware to end of the stack if it does not already exist.
270
+     *
271
+     * @param string $middleware The app middleware.
272
+     *
273
+     * @return $this
274
+     */
275
+    public function push_middleware( $middleware ) {
276
+        if ( array_search( $middleware, $this->middleware ) === false ) {
277
+            $this->middleware[] = $middleware;
278
+        }
279
+
280
+        return $this;
281
+    }
282
+
283
+    /**
284
+     * Prepend the given middleware to the given middleware group.
285
+     *
286
+     * @param string $group The app group.
287
+     * @param string $middleware The app middleware.
288
+     *
289
+     * @throws \InvalidArgumentException The invalid argument exception.
290
+     *
291
+     * @return $this
292
+     */
293
+    public function prepend_middleware_to_group( $group, $middleware ) {
294
+        if ( ! isset( $this->middleware_groups[ $group ] ) ) {
295
+            throw new InvalidArgumentException( "The [{$group}] middleware group has not been defined." );
296
+        }
297
+
298
+        if ( array_search( $middleware, $this->middleware_groups[ $group ] ) === false ) {
299
+            array_unshift( $this->middleware_groups[ $group ], $middleware );
300
+        }
301
+
302
+        $this->sync_middleware_to_router();
303
+
304
+        return $this;
305
+    }
306
+
307
+    /**
308
+     * Append the given middleware to the given middleware group.
309
+     *
310
+     * @param string $group The app group.
311
+     * @param string $middleware The app middleware.
312
+     *
313
+     * @throws \InvalidArgumentException The invalid argument exception.
314
+     *
315
+     * @return $this
316
+     */
317
+    public function append_middleware_to_group( $group, $middleware ) {
318
+        if ( ! isset( $this->middleware_groups[ $group ] ) ) {
319
+            throw new InvalidArgumentException( "The [{$group}] middleware group has not been defined." );
320
+        }
321
+
322
+        if ( array_search( $middleware, $this->middleware_groups[ $group ] ) === false ) {
323
+            $this->middleware_groups[ $group ][] = $middleware;
324
+        }
325
+
326
+        $this->sync_middleware_to_router();
327
+
328
+        return $this;
329
+    }
330
+
331
+    /**
332
+     * Prepend the given middleware to the middleware priority list.
333
+     *
334
+     * @param string $middleware The app middleware.
335
+     *
336
+     * @return $this
337
+     */
338
+    public function prepend_to_middleware_priority( $middleware ) {
339
+        if ( ! in_array( $middleware, $this->middleware_priority ) ) {
340
+            array_unshift( $this->middleware_priority, $middleware );
341
+        }
342
+
343
+        $this->sync_middleware_to_router();
344
+
345
+        return $this;
346
+    }
347
+
348
+    /**
349
+     * Append the given middleware to the middleware priority list.
350
+     *
351
+     * @param string $middleware The app middleware.
352
+     *
353
+     * @return $this
354
+     */
355
+    public function append_to_middleware_priority( $middleware ) {
356
+        if ( ! in_array( $middleware, $this->middleware_priority ) ) {
357
+            $this->middleware_priority[] = $middleware;
358
+        }
359
+
360
+        $this->sync_middleware_to_router();
361
+
362
+        return $this;
363
+    }
364
+
365
+    /**
366
+     * Sync the current state of the middleware to the router.
367
+     *
368
+     * @return void
369
+     */
370
+    protected function sync_middleware_to_router() {
371
+        $this->router->middlewarePriority = $this->middleware_priority;
372
+
373
+        foreach ( $this->middleware_groups as $key => $middleware ) {
374
+            $this->router->middlewareGroup( $key, $middleware );
375
+        }
376
+
377
+        foreach ( $this->route_middleware as $key => $middleware ) {
378
+            $this->router->aliasMiddleware( $key, $middleware );
379
+        }
380
+    }
381
+
382
+    /**
383
+     * Get the bootstrap classes for the application.
384
+     *
385
+     * @return array
386
+     */
387
+    protected function bootstrappers() {
388
+        return $this->bootstrappers;
389
+    }
390
+
391
+    /**
392
+     * Report the exception to the exception handler.
393
+     *
394
+     * @param \Throwable $e The throwable exception.
395
+     *
396
+     * @return void
397
+     */
398
+    protected function report_exception( Throwable $e ) {
399
+        $this->app[ ExceptionHandler::class ]->report( $e );
400
+    }
401
+
402
+    /**
403
+     * Render the exception to a response.
404
+     *
405
+     * @param \Illuminate\Http\Request $request The app http request.
406
+     * @param \Throwable               $e The throwable exception.
407
+     *
408
+     * @return \Symfony\Component\HttpFoundation\Response
409
+     */
410
+    protected function render_exception( $request, Throwable $e ) {
411
+        return $this->app[ ExceptionHandler::class ]->render( $request, $e );
412
+    }
413
+
414
+    /**
415
+     * Get the application's route middleware groups.
416
+     *
417
+     * @return array
418
+     */
419
+    public function get_middleware_groups() {
420
+        return $this->middleware_groups;
421
+    }
422
+
423
+    /**
424
+     * Get the application's route middleware.
425
+     *
426
+     * @return array
427
+     */
428
+    public function get_route_middleware() {
429
+        return $this->route_middleware;
430
+    }
431
+
432
+    /**
433
+     * Get the Laravel application instance.
434
+     *
435
+     * @return \Illuminate\Contracts\Foundation\Application
436
+     */
437
+    public function get_application() {
438
+        return $this->app;
439
+    }
440 440
 }
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	 *
91 91
 	 * @return void
92 92
 	 */
93
-	public function __construct( Container $app, Router $router ) {
93
+	public function __construct(Container $app, Router $router) {
94 94
 		$this->app    = $app;
95 95
 		$this->router = $router;
96 96
 
@@ -106,17 +106,17 @@  discard block
 block discarded – undo
106 106
 	 *
107 107
 	 * @return \Illuminate\Http\Response
108 108
 	 */
109
-	public function handle( $request ) {
109
+	public function handle($request) {
110 110
 		try {
111 111
 			$request->enableHttpMethodParameterOverride();
112
-			$response = $this->send_request_through_router( $request );
113
-		} catch ( Throwable $e ) {
114
-			$this->report_exception( $e );
115
-			$response = $this->render_exception( $request, $e );
112
+			$response = $this->send_request_through_router($request);
113
+		} catch (Throwable $e) {
114
+			$this->report_exception($e);
115
+			$response = $this->render_exception($request, $e);
116 116
 		}
117 117
 
118 118
 		$this->app['events']->dispatch(
119
-			new RequestHandled( $request, $response )
119
+			new RequestHandled($request, $response)
120 120
 		);
121 121
 
122 122
 		return $response;
@@ -129,17 +129,17 @@  discard block
 block discarded – undo
129 129
 	 *
130 130
 	 * @return \Illuminate\Http\Response
131 131
 	 */
132
-	protected function send_request_through_router( $request ) {
133
-		$this->app->instance( 'request', $request );
132
+	protected function send_request_through_router($request) {
133
+		$this->app->instance('request', $request);
134 134
 
135
-		Facade::clearResolvedInstance( 'request' );
135
+		Facade::clearResolvedInstance('request');
136 136
 
137 137
 		$this->bootstrap();
138 138
 
139
-		return ( new Pipeline( $this->app ) )
140
-					->send( $request )
141
-					->through( $this->middleware )
142
-					->then( $this->dispatch_to_router() );
139
+		return (new Pipeline($this->app))
140
+					->send($request)
141
+					->through($this->middleware)
142
+					->then($this->dispatch_to_router());
143 143
 	}
144 144
 
145 145
 	/**
@@ -155,10 +155,10 @@  discard block
 block discarded – undo
155 155
 	 * @return \Closure
156 156
 	 */
157 157
 	protected function dispatch_to_router() {
158
-		return function ( $request ) {
159
-			$this->app->instance( 'request', $request );
158
+		return function($request) {
159
+			$this->app->instance('request', $request);
160 160
 
161
-			return $this->router->dispatch( $request );
161
+			return $this->router->dispatch($request);
162 162
 		};
163 163
 	}
164 164
 
@@ -170,8 +170,8 @@  discard block
 block discarded – undo
170 170
 	 *
171 171
 	 * @return void
172 172
 	 */
173
-	public function terminate( $request, $response ) {
174
-		$this->terminate_middleware( $request, $response );
173
+	public function terminate($request, $response) {
174
+		$this->terminate_middleware($request, $response);
175 175
 
176 176
 		$this->app->terminate();
177 177
 	}
@@ -184,23 +184,23 @@  discard block
 block discarded – undo
184 184
 	 *
185 185
 	 * @return void
186 186
 	 */
187
-	protected function terminate_middleware( $request, $response ) {
187
+	protected function terminate_middleware($request, $response) {
188 188
 		$middlewares = $this->app->shouldSkipMiddleware() ? array() : array_merge(
189
-			$this->gather_route_middleware( $request ),
189
+			$this->gather_route_middleware($request),
190 190
 			$this->middleware
191 191
 		);
192 192
 
193
-		foreach ( $middlewares as $middleware ) {
194
-			if ( ! is_string( $middleware ) ) {
193
+		foreach ($middlewares as $middleware) {
194
+			if (!is_string($middleware)) {
195 195
 				continue;
196 196
 			}
197 197
 
198
-			list( $name ) = $this->parse_middleware( $middleware );
198
+			list($name) = $this->parse_middleware($middleware);
199 199
 
200
-			$instance = $this->app->make( $name );
200
+			$instance = $this->app->make($name);
201 201
 
202
-			if ( method_exists( $instance, 'terminate' ) ) {
203
-				$instance->terminate( $request, $response );
202
+			if (method_exists($instance, 'terminate')) {
203
+				$instance->terminate($request, $response);
204 204
 			}
205 205
 		}
206 206
 	}
@@ -212,10 +212,10 @@  discard block
 block discarded – undo
212 212
 	 *
213 213
 	 * @return array
214 214
 	 */
215
-	protected function gather_route_middleware( $request ) {
215
+	protected function gather_route_middleware($request) {
216 216
 		$route = $request->route();
217
-		if ( $route ) {
218
-			return $this->router->gatherRouteMiddleware( $route );
217
+		if ($route) {
218
+			return $this->router->gatherRouteMiddleware($route);
219 219
 		}
220 220
 
221 221
 		return array();
@@ -228,15 +228,15 @@  discard block
 block discarded – undo
228 228
 	 *
229 229
 	 * @return array
230 230
 	 */
231
-	protected function parse_middleware( $middleware ) {
231
+	protected function parse_middleware($middleware) {
232 232
 
233
-		list( $name, $parameters ) = array_pad( explode( ':', $middleware, 2 ), 2, array() );
233
+		list($name, $parameters) = array_pad(explode(':', $middleware, 2), 2, array());
234 234
 
235
-		if ( is_string( $parameters ) ) {
236
-			$parameters = explode( ',', $parameters );
235
+		if (is_string($parameters)) {
236
+			$parameters = explode(',', $parameters);
237 237
 		}
238 238
 
239
-		return array( $name, $parameters );
239
+		return array($name, $parameters);
240 240
 	}
241 241
 
242 242
 	/**
@@ -246,8 +246,8 @@  discard block
 block discarded – undo
246 246
 	 *
247 247
 	 * @return bool
248 248
 	 */
249
-	public function has_middleware( $middleware ) {
250
-		return in_array( $middleware, $this->middleware );
249
+	public function has_middleware($middleware) {
250
+		return in_array($middleware, $this->middleware);
251 251
 	}
252 252
 
253 253
 	/**
@@ -257,9 +257,9 @@  discard block
 block discarded – undo
257 257
 	 *
258 258
 	 * @return $this
259 259
 	 */
260
-	public function prepend_middleware( $middleware ) {
261
-		if ( array_search( $middleware, $this->middleware ) === false ) {
262
-			array_unshift( $this->middleware, $middleware );
260
+	public function prepend_middleware($middleware) {
261
+		if (array_search($middleware, $this->middleware) === false) {
262
+			array_unshift($this->middleware, $middleware);
263 263
 		}
264 264
 
265 265
 		return $this;
@@ -272,8 +272,8 @@  discard block
 block discarded – undo
272 272
 	 *
273 273
 	 * @return $this
274 274
 	 */
275
-	public function push_middleware( $middleware ) {
276
-		if ( array_search( $middleware, $this->middleware ) === false ) {
275
+	public function push_middleware($middleware) {
276
+		if (array_search($middleware, $this->middleware) === false) {
277 277
 			$this->middleware[] = $middleware;
278 278
 		}
279 279
 
@@ -290,13 +290,13 @@  discard block
 block discarded – undo
290 290
 	 *
291 291
 	 * @return $this
292 292
 	 */
293
-	public function prepend_middleware_to_group( $group, $middleware ) {
294
-		if ( ! isset( $this->middleware_groups[ $group ] ) ) {
295
-			throw new InvalidArgumentException( "The [{$group}] middleware group has not been defined." );
293
+	public function prepend_middleware_to_group($group, $middleware) {
294
+		if (!isset($this->middleware_groups[$group])) {
295
+			throw new InvalidArgumentException("The [{$group}] middleware group has not been defined.");
296 296
 		}
297 297
 
298
-		if ( array_search( $middleware, $this->middleware_groups[ $group ] ) === false ) {
299
-			array_unshift( $this->middleware_groups[ $group ], $middleware );
298
+		if (array_search($middleware, $this->middleware_groups[$group]) === false) {
299
+			array_unshift($this->middleware_groups[$group], $middleware);
300 300
 		}
301 301
 
302 302
 		$this->sync_middleware_to_router();
@@ -314,13 +314,13 @@  discard block
 block discarded – undo
314 314
 	 *
315 315
 	 * @return $this
316 316
 	 */
317
-	public function append_middleware_to_group( $group, $middleware ) {
318
-		if ( ! isset( $this->middleware_groups[ $group ] ) ) {
319
-			throw new InvalidArgumentException( "The [{$group}] middleware group has not been defined." );
317
+	public function append_middleware_to_group($group, $middleware) {
318
+		if (!isset($this->middleware_groups[$group])) {
319
+			throw new InvalidArgumentException("The [{$group}] middleware group has not been defined.");
320 320
 		}
321 321
 
322
-		if ( array_search( $middleware, $this->middleware_groups[ $group ] ) === false ) {
323
-			$this->middleware_groups[ $group ][] = $middleware;
322
+		if (array_search($middleware, $this->middleware_groups[$group]) === false) {
323
+			$this->middleware_groups[$group][] = $middleware;
324 324
 		}
325 325
 
326 326
 		$this->sync_middleware_to_router();
@@ -335,9 +335,9 @@  discard block
 block discarded – undo
335 335
 	 *
336 336
 	 * @return $this
337 337
 	 */
338
-	public function prepend_to_middleware_priority( $middleware ) {
339
-		if ( ! in_array( $middleware, $this->middleware_priority ) ) {
340
-			array_unshift( $this->middleware_priority, $middleware );
338
+	public function prepend_to_middleware_priority($middleware) {
339
+		if (!in_array($middleware, $this->middleware_priority)) {
340
+			array_unshift($this->middleware_priority, $middleware);
341 341
 		}
342 342
 
343 343
 		$this->sync_middleware_to_router();
@@ -352,8 +352,8 @@  discard block
 block discarded – undo
352 352
 	 *
353 353
 	 * @return $this
354 354
 	 */
355
-	public function append_to_middleware_priority( $middleware ) {
356
-		if ( ! in_array( $middleware, $this->middleware_priority ) ) {
355
+	public function append_to_middleware_priority($middleware) {
356
+		if (!in_array($middleware, $this->middleware_priority)) {
357 357
 			$this->middleware_priority[] = $middleware;
358 358
 		}
359 359
 
@@ -370,12 +370,12 @@  discard block
 block discarded – undo
370 370
 	protected function sync_middleware_to_router() {
371 371
 		$this->router->middlewarePriority = $this->middleware_priority;
372 372
 
373
-		foreach ( $this->middleware_groups as $key => $middleware ) {
374
-			$this->router->middlewareGroup( $key, $middleware );
373
+		foreach ($this->middleware_groups as $key => $middleware) {
374
+			$this->router->middlewareGroup($key, $middleware);
375 375
 		}
376 376
 
377
-		foreach ( $this->route_middleware as $key => $middleware ) {
378
-			$this->router->aliasMiddleware( $key, $middleware );
377
+		foreach ($this->route_middleware as $key => $middleware) {
378
+			$this->router->aliasMiddleware($key, $middleware);
379 379
 		}
380 380
 	}
381 381
 
@@ -395,8 +395,8 @@  discard block
 block discarded – undo
395 395
 	 *
396 396
 	 * @return void
397 397
 	 */
398
-	protected function report_exception( Throwable $e ) {
399
-		$this->app[ ExceptionHandler::class ]->report( $e );
398
+	protected function report_exception(Throwable $e) {
399
+		$this->app[ExceptionHandler::class]->report($e);
400 400
 	}
401 401
 
402 402
 	/**
@@ -407,8 +407,8 @@  discard block
 block discarded – undo
407 407
 	 *
408 408
 	 * @return \Symfony\Component\HttpFoundation\Response
409 409
 	 */
410
-	protected function render_exception( $request, Throwable $e ) {
411
-		return $this->app[ ExceptionHandler::class ]->render( $request, $e );
410
+	protected function render_exception($request, Throwable $e) {
411
+		return $this->app[ExceptionHandler::class]->render($request, $e);
412 412
 	}
413 413
 
414 414
 	/**
Please login to merge, or discard this patch.
includes/class-wpb.php 2 patches
Indentation   +319 added lines, -319 removed lines patch added patch discarded remove patch
@@ -28,323 +28,323 @@
 block discarded – undo
28 28
  */
29 29
 class WPB {
30 30
 
31
-	/**
32
-	 * The loader that's responsible for maintaining and registering all hooks that power
33
-	 * the plugin.
34
-	 *
35
-	 * @since    1.0.0
36
-	 * @access   protected
37
-	 * @var      WPB_Loader    $loader    Maintains and registers all hooks for the plugin.
38
-	 */
39
-	protected $loader;
40
-
41
-	/**
42
-	 * The unique identifier of this plugin.
43
-	 *
44
-	 * @since    1.0.0
45
-	 * @access   protected
46
-	 * @var      string    $plugin_name    The string used to uniquely identify this plugin.
47
-	 */
48
-	protected $plugin_name;
49
-
50
-	/**
51
-	 * The current version of the plugin.
52
-	 *
53
-	 * @since    1.0.0
54
-	 * @access   protected
55
-	 * @var      string    $version    The current version of the plugin.
56
-	 */
57
-	protected $version;
58
-
59
-	/**
60
-	 * Define the core functionality of the plugin.
61
-	 *
62
-	 * Set the plugin name and the plugin version that can be used throughout the plugin.
63
-	 * Load the dependencies, define the locale, and set the hooks for the admin area and
64
-	 * the public-facing side of the site.
65
-	 *
66
-	 * @since    1.0.0
67
-	 */
68
-	public function __construct() {
69
-
70
-		$this->define_constants();
71
-
72
-		if ( defined( 'WPB_VERSION' ) ) {
73
-			$this->version = WPB_VERSION;
74
-		} else {
75
-			$this->version = '1.0.0';
76
-		}
77
-		$this->plugin_name = 'wpb';
78
-		$this->load_dependencies();
79
-		$this->set_locale();
80
-		$this->define_admin_hooks();
81
-		$this->define_public_hooks();
82
-		$this->register_assets();
83
-	}
84
-
85
-	/**
86
-	 * Load the required dependencies for this plugin.
87
-	 *
88
-	 * Include the following files that make up the plugin:
89
-	 *
90
-	 * - WPB_Loader. Orchestrates the hooks of the plugin.
91
-	 * - WPB_i18n. Defines internationalization functionality.
92
-	 * - WPB_Admin. Defines all hooks for the admin area.
93
-	 * - WPB_Public. Defines all hooks for the public side of the site.
94
-	 *
95
-	 * Create an instance of the loader which will be used to register the hooks
96
-	 * with WordPress.
97
-	 *
98
-	 * @since    1.0.0
99
-	 * @access   private
100
-	 */
101
-	private function load_dependencies() {
102
-
103
-		/**
104
-		 * The class responsible for orchestrating the actions and filters of the
105
-		 * core plugin.
106
-		 */
107
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpb-loader.php';
108
-
109
-		/**
110
-		 * The class responsible for defining internationalization functionality
111
-		 * of the plugin.
112
-		 */
113
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpb-i18n.php';
114
-
115
-		/**
116
-		 * The class responsible for defining all actions that occur in the admin area.
117
-		 */
118
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wpb-admin.php';
119
-
120
-		/**
121
-		 * The class responsible for defining all menu actions that occur in the admin area.
122
-		 */
123
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wpb-admin-menu.php';
124
-
125
-		/**
126
-		 * The class responsible for defining all submenu actions that occur in the admin area.
127
-		 */
128
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wpb-admin-submenu.php';
129
-
130
-		/**
131
-		 * The class responsible for defining all actions that occur in the public-facing
132
-		 * side of the site.
133
-		 */
134
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wpb-public.php';
135
-
136
-		$this->loader = new WPB_Loader();
137
-
138
-	}
139
-
140
-	/**
141
-	 * Define the locale for this plugin for internationalization.
142
-	 *
143
-	 * Uses the WPB_i18n class in order to set the domain and to register the hook
144
-	 * with WordPress.
145
-	 *
146
-	 * @since    1.0.0
147
-	 * @access   private
148
-	 */
149
-	private function set_locale() {
150
-
151
-		$plugin_i18n = new WPB_I18n();
152
-
153
-		$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
154
-
155
-	}
156
-
157
-	/**
158
-	 * Register all of the hooks related to the admin area functionality
159
-	 * of the plugin.
160
-	 *
161
-	 * @since    1.0.0
162
-	 * @access   private
163
-	 */
164
-	private function define_admin_hooks() {
165
-
166
-		$plugin_admin = new WPB_Admin( $this->get_plugin_name(), $this->get_version() );
167
-
168
-		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
169
-		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
170
-
171
-	}
172
-
173
-	/**
174
-	 * Register all of the hooks related to the public-facing functionality
175
-	 * of the plugin.
176
-	 *
177
-	 * @since    1.0.0
178
-	 * @access   private
179
-	 */
180
-	private function define_public_hooks() {
181
-
182
-		$plugin_public = new WPB_Public( $this->get_plugin_name(), $this->get_version() );
183
-
184
-		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
185
-		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
186
-
187
-	}
188
-
189
-	/**
190
-	 * Run the loader to execute all of the hooks with WordPress.
191
-	 *
192
-	 * @since    1.0.0
193
-	 */
194
-	public function run() {
195
-		$this->loader->run();
196
-	}
197
-
198
-	/**
199
-	 * The name of the plugin used to uniquely identify it within the context of
200
-	 * WordPress and to define internationalization functionality.
201
-	 *
202
-	 * @since     1.0.0
203
-	 * @return    string    The name of the plugin.
204
-	 */
205
-	public function get_plugin_name() {
206
-		return $this->plugin_name;
207
-	}
208
-
209
-	/**
210
-	 * The reference to the class that orchestrates the hooks with the plugin.
211
-	 *
212
-	 * @since     1.0.0
213
-	 * @return    WPB_Loader    Orchestrates the hooks of the plugin.
214
-	 */
215
-	public function get_loader() {
216
-		return $this->loader;
217
-	}
218
-
219
-	/**
220
-	 * Retrieve the version number of the plugin.
221
-	 *
222
-	 * @since     1.0.0
223
-	 * @return    string    The version number of the plugin.
224
-	 */
225
-	public function get_version() {
226
-		return $this->version;
227
-	}
228
-
229
-	/**
230
-	 * Define the constants.
231
-	 *
232
-	 * @return void
233
-	 */
234
-	public function define_constants() {
235
-		define( 'WPB_VERSION', $this->version );
236
-	}
237
-
238
-	/**
239
-	 * Register our app scripts and styles.
240
-	 *
241
-	 * @return void
242
-	 */
243
-	public function register_assets() {
244
-		$this->register_scripts( $this->get_scripts() );
245
-		$this->register_styles( $this->get_styles() );
246
-	}
247
-
248
-	/**
249
-	 * Register scripts.
250
-	 *
251
-	 * @param  array $scripts All Scripts as an array.
252
-	 *
253
-	 * @return void
254
-	 */
255
-	private function register_scripts( $scripts ) {
256
-		foreach ( $scripts as $handle => $script ) {
257
-			$deps      = isset( $script['deps'] ) ? $script['deps'] : false;
258
-			$in_footer = isset( $script['in_footer'] ) ? $script['in_footer'] : false;
259
-			$version   = isset( $script['version'] ) ? $script['version'] : WPB_VERSION;
260
-
261
-			wp_register_script( $handle, $script['src'], $deps, $version, $in_footer );
262
-		}
263
-	}
264
-
265
-	/**
266
-	 * Register styles.
267
-	 *
268
-	 * @param  array $styles All styles as an array.
269
-	 *
270
-	 * @return void
271
-	 */
272
-	public function register_styles( $styles ) {
273
-		foreach ( $styles as $handle => $style ) {
274
-			$deps = isset( $style['deps'] ) ? $style['deps'] : false;
275
-
276
-			wp_register_style( $handle, $style['src'], $deps, WPB_VERSION );
277
-		}
278
-	}
279
-
280
-	/**
281
-	 * Get all registered scripts.
282
-	 *
283
-	 * @return array
284
-	 */
285
-	public function get_scripts() {
286
-
287
-		$prefix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.min' : '';
288
-
289
-		$scripts = array(
290
-			'wpb-runtime'  => array(
291
-				'src'       => WPB_ASSETS . '/js/runtime.js',
292
-				'version'   => filemtime( WPB_PATH . '/public/js/runtime.js' ),
293
-				'in_footer' => true,
294
-			),
295
-			'wpb-vendor'   => array(
296
-				'src'       => WPB_ASSETS . '/js/vendors.js',
297
-				'version'   => filemtime( WPB_PATH . '/public/js/vendors.js' ),
298
-				'in_footer' => true,
299
-			),
300
-			'wpb-frontend' => array(
301
-				'src'       => WPB_ASSETS . '/js/frontend.js',
302
-				'deps'      => array( 'jquery', 'wpb-vendor', 'wpb-runtime' ),
303
-				'version'   => filemtime( WPB_PATH . '/public/js/frontend.js' ),
304
-				'in_footer' => true,
305
-			),
306
-			'wpb-admin'    => array(
307
-				'src'       => WPB_ASSETS . '/js/admin.js',
308
-				'deps'      => array( 'jquery', 'wpb-vendor', 'wpb-runtime' ),
309
-				'version'   => filemtime( WPB_PATH . '/public/js/admin.js' ),
310
-				'in_footer' => true,
311
-			),
312
-			'wpb-spa'      => array(
313
-				'src'       => WPB_ASSETS . '/js/spa.js',
314
-				'deps'      => array( 'jquery', 'wpb-vendor', 'wpb-runtime' ),
315
-				'version'   => filemtime( WPB_PATH . '/public/js/spa.js' ),
316
-				'in_footer' => true,
317
-			),
318
-		);
319
-
320
-		return $scripts;
321
-	}
322
-
323
-	/**
324
-	 * Get registered styles.
325
-	 *
326
-	 * @return array
327
-	 */
328
-	public function get_styles() {
329
-
330
-		$styles = array(
331
-			'wpb-style'    => array(
332
-				'src' => WPB_ASSETS . '/css/style.css',
333
-			),
334
-			'wpb-frontend' => array(
335
-				'src' => WPB_ASSETS . '/css/frontend.css',
336
-			),
337
-			'wpb-admin'    => array(
338
-				'src' => WPB_ASSETS . '/css/admin.css',
339
-			),
340
-			'wpb-spa'      => array(
341
-				'src' => WPB_ASSETS . '/css/spa.css',
342
-			),
343
-			'wpb-vendors'  => array(
344
-				'src' => WPB_ASSETS . '/css/vendors.css',
345
-			),
346
-		);
347
-
348
-		return $styles;
349
-	}
31
+    /**
32
+     * The loader that's responsible for maintaining and registering all hooks that power
33
+     * the plugin.
34
+     *
35
+     * @since    1.0.0
36
+     * @access   protected
37
+     * @var      WPB_Loader    $loader    Maintains and registers all hooks for the plugin.
38
+     */
39
+    protected $loader;
40
+
41
+    /**
42
+     * The unique identifier of this plugin.
43
+     *
44
+     * @since    1.0.0
45
+     * @access   protected
46
+     * @var      string    $plugin_name    The string used to uniquely identify this plugin.
47
+     */
48
+    protected $plugin_name;
49
+
50
+    /**
51
+     * The current version of the plugin.
52
+     *
53
+     * @since    1.0.0
54
+     * @access   protected
55
+     * @var      string    $version    The current version of the plugin.
56
+     */
57
+    protected $version;
58
+
59
+    /**
60
+     * Define the core functionality of the plugin.
61
+     *
62
+     * Set the plugin name and the plugin version that can be used throughout the plugin.
63
+     * Load the dependencies, define the locale, and set the hooks for the admin area and
64
+     * the public-facing side of the site.
65
+     *
66
+     * @since    1.0.0
67
+     */
68
+    public function __construct() {
69
+
70
+        $this->define_constants();
71
+
72
+        if ( defined( 'WPB_VERSION' ) ) {
73
+            $this->version = WPB_VERSION;
74
+        } else {
75
+            $this->version = '1.0.0';
76
+        }
77
+        $this->plugin_name = 'wpb';
78
+        $this->load_dependencies();
79
+        $this->set_locale();
80
+        $this->define_admin_hooks();
81
+        $this->define_public_hooks();
82
+        $this->register_assets();
83
+    }
84
+
85
+    /**
86
+     * Load the required dependencies for this plugin.
87
+     *
88
+     * Include the following files that make up the plugin:
89
+     *
90
+     * - WPB_Loader. Orchestrates the hooks of the plugin.
91
+     * - WPB_i18n. Defines internationalization functionality.
92
+     * - WPB_Admin. Defines all hooks for the admin area.
93
+     * - WPB_Public. Defines all hooks for the public side of the site.
94
+     *
95
+     * Create an instance of the loader which will be used to register the hooks
96
+     * with WordPress.
97
+     *
98
+     * @since    1.0.0
99
+     * @access   private
100
+     */
101
+    private function load_dependencies() {
102
+
103
+        /**
104
+         * The class responsible for orchestrating the actions and filters of the
105
+         * core plugin.
106
+         */
107
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpb-loader.php';
108
+
109
+        /**
110
+         * The class responsible for defining internationalization functionality
111
+         * of the plugin.
112
+         */
113
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpb-i18n.php';
114
+
115
+        /**
116
+         * The class responsible for defining all actions that occur in the admin area.
117
+         */
118
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wpb-admin.php';
119
+
120
+        /**
121
+         * The class responsible for defining all menu actions that occur in the admin area.
122
+         */
123
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wpb-admin-menu.php';
124
+
125
+        /**
126
+         * The class responsible for defining all submenu actions that occur in the admin area.
127
+         */
128
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wpb-admin-submenu.php';
129
+
130
+        /**
131
+         * The class responsible for defining all actions that occur in the public-facing
132
+         * side of the site.
133
+         */
134
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wpb-public.php';
135
+
136
+        $this->loader = new WPB_Loader();
137
+
138
+    }
139
+
140
+    /**
141
+     * Define the locale for this plugin for internationalization.
142
+     *
143
+     * Uses the WPB_i18n class in order to set the domain and to register the hook
144
+     * with WordPress.
145
+     *
146
+     * @since    1.0.0
147
+     * @access   private
148
+     */
149
+    private function set_locale() {
150
+
151
+        $plugin_i18n = new WPB_I18n();
152
+
153
+        $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
154
+
155
+    }
156
+
157
+    /**
158
+     * Register all of the hooks related to the admin area functionality
159
+     * of the plugin.
160
+     *
161
+     * @since    1.0.0
162
+     * @access   private
163
+     */
164
+    private function define_admin_hooks() {
165
+
166
+        $plugin_admin = new WPB_Admin( $this->get_plugin_name(), $this->get_version() );
167
+
168
+        $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
169
+        $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
170
+
171
+    }
172
+
173
+    /**
174
+     * Register all of the hooks related to the public-facing functionality
175
+     * of the plugin.
176
+     *
177
+     * @since    1.0.0
178
+     * @access   private
179
+     */
180
+    private function define_public_hooks() {
181
+
182
+        $plugin_public = new WPB_Public( $this->get_plugin_name(), $this->get_version() );
183
+
184
+        $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
185
+        $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
186
+
187
+    }
188
+
189
+    /**
190
+     * Run the loader to execute all of the hooks with WordPress.
191
+     *
192
+     * @since    1.0.0
193
+     */
194
+    public function run() {
195
+        $this->loader->run();
196
+    }
197
+
198
+    /**
199
+     * The name of the plugin used to uniquely identify it within the context of
200
+     * WordPress and to define internationalization functionality.
201
+     *
202
+     * @since     1.0.0
203
+     * @return    string    The name of the plugin.
204
+     */
205
+    public function get_plugin_name() {
206
+        return $this->plugin_name;
207
+    }
208
+
209
+    /**
210
+     * The reference to the class that orchestrates the hooks with the plugin.
211
+     *
212
+     * @since     1.0.0
213
+     * @return    WPB_Loader    Orchestrates the hooks of the plugin.
214
+     */
215
+    public function get_loader() {
216
+        return $this->loader;
217
+    }
218
+
219
+    /**
220
+     * Retrieve the version number of the plugin.
221
+     *
222
+     * @since     1.0.0
223
+     * @return    string    The version number of the plugin.
224
+     */
225
+    public function get_version() {
226
+        return $this->version;
227
+    }
228
+
229
+    /**
230
+     * Define the constants.
231
+     *
232
+     * @return void
233
+     */
234
+    public function define_constants() {
235
+        define( 'WPB_VERSION', $this->version );
236
+    }
237
+
238
+    /**
239
+     * Register our app scripts and styles.
240
+     *
241
+     * @return void
242
+     */
243
+    public function register_assets() {
244
+        $this->register_scripts( $this->get_scripts() );
245
+        $this->register_styles( $this->get_styles() );
246
+    }
247
+
248
+    /**
249
+     * Register scripts.
250
+     *
251
+     * @param  array $scripts All Scripts as an array.
252
+     *
253
+     * @return void
254
+     */
255
+    private function register_scripts( $scripts ) {
256
+        foreach ( $scripts as $handle => $script ) {
257
+            $deps      = isset( $script['deps'] ) ? $script['deps'] : false;
258
+            $in_footer = isset( $script['in_footer'] ) ? $script['in_footer'] : false;
259
+            $version   = isset( $script['version'] ) ? $script['version'] : WPB_VERSION;
260
+
261
+            wp_register_script( $handle, $script['src'], $deps, $version, $in_footer );
262
+        }
263
+    }
264
+
265
+    /**
266
+     * Register styles.
267
+     *
268
+     * @param  array $styles All styles as an array.
269
+     *
270
+     * @return void
271
+     */
272
+    public function register_styles( $styles ) {
273
+        foreach ( $styles as $handle => $style ) {
274
+            $deps = isset( $style['deps'] ) ? $style['deps'] : false;
275
+
276
+            wp_register_style( $handle, $style['src'], $deps, WPB_VERSION );
277
+        }
278
+    }
279
+
280
+    /**
281
+     * Get all registered scripts.
282
+     *
283
+     * @return array
284
+     */
285
+    public function get_scripts() {
286
+
287
+        $prefix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.min' : '';
288
+
289
+        $scripts = array(
290
+            'wpb-runtime'  => array(
291
+                'src'       => WPB_ASSETS . '/js/runtime.js',
292
+                'version'   => filemtime( WPB_PATH . '/public/js/runtime.js' ),
293
+                'in_footer' => true,
294
+            ),
295
+            'wpb-vendor'   => array(
296
+                'src'       => WPB_ASSETS . '/js/vendors.js',
297
+                'version'   => filemtime( WPB_PATH . '/public/js/vendors.js' ),
298
+                'in_footer' => true,
299
+            ),
300
+            'wpb-frontend' => array(
301
+                'src'       => WPB_ASSETS . '/js/frontend.js',
302
+                'deps'      => array( 'jquery', 'wpb-vendor', 'wpb-runtime' ),
303
+                'version'   => filemtime( WPB_PATH . '/public/js/frontend.js' ),
304
+                'in_footer' => true,
305
+            ),
306
+            'wpb-admin'    => array(
307
+                'src'       => WPB_ASSETS . '/js/admin.js',
308
+                'deps'      => array( 'jquery', 'wpb-vendor', 'wpb-runtime' ),
309
+                'version'   => filemtime( WPB_PATH . '/public/js/admin.js' ),
310
+                'in_footer' => true,
311
+            ),
312
+            'wpb-spa'      => array(
313
+                'src'       => WPB_ASSETS . '/js/spa.js',
314
+                'deps'      => array( 'jquery', 'wpb-vendor', 'wpb-runtime' ),
315
+                'version'   => filemtime( WPB_PATH . '/public/js/spa.js' ),
316
+                'in_footer' => true,
317
+            ),
318
+        );
319
+
320
+        return $scripts;
321
+    }
322
+
323
+    /**
324
+     * Get registered styles.
325
+     *
326
+     * @return array
327
+     */
328
+    public function get_styles() {
329
+
330
+        $styles = array(
331
+            'wpb-style'    => array(
332
+                'src' => WPB_ASSETS . '/css/style.css',
333
+            ),
334
+            'wpb-frontend' => array(
335
+                'src' => WPB_ASSETS . '/css/frontend.css',
336
+            ),
337
+            'wpb-admin'    => array(
338
+                'src' => WPB_ASSETS . '/css/admin.css',
339
+            ),
340
+            'wpb-spa'      => array(
341
+                'src' => WPB_ASSETS . '/css/spa.css',
342
+            ),
343
+            'wpb-vendors'  => array(
344
+                'src' => WPB_ASSETS . '/css/vendors.css',
345
+            ),
346
+        );
347
+
348
+        return $styles;
349
+    }
350 350
 }
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 
70 70
 		$this->define_constants();
71 71
 
72
-		if ( defined( 'WPB_VERSION' ) ) {
72
+		if (defined('WPB_VERSION')) {
73 73
 			$this->version = WPB_VERSION;
74 74
 		} else {
75 75
 			$this->version = '1.0.0';
@@ -104,34 +104,34 @@  discard block
 block discarded – undo
104 104
 		 * The class responsible for orchestrating the actions and filters of the
105 105
 		 * core plugin.
106 106
 		 */
107
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpb-loader.php';
107
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wpb-loader.php';
108 108
 
109 109
 		/**
110 110
 		 * The class responsible for defining internationalization functionality
111 111
 		 * of the plugin.
112 112
 		 */
113
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpb-i18n.php';
113
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wpb-i18n.php';
114 114
 
115 115
 		/**
116 116
 		 * The class responsible for defining all actions that occur in the admin area.
117 117
 		 */
118
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wpb-admin.php';
118
+		require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wpb-admin.php';
119 119
 
120 120
 		/**
121 121
 		 * The class responsible for defining all menu actions that occur in the admin area.
122 122
 		 */
123
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wpb-admin-menu.php';
123
+		require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wpb-admin-menu.php';
124 124
 
125 125
 		/**
126 126
 		 * The class responsible for defining all submenu actions that occur in the admin area.
127 127
 		 */
128
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wpb-admin-submenu.php';
128
+		require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wpb-admin-submenu.php';
129 129
 
130 130
 		/**
131 131
 		 * The class responsible for defining all actions that occur in the public-facing
132 132
 		 * side of the site.
133 133
 		 */
134
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wpb-public.php';
134
+		require_once plugin_dir_path(dirname(__FILE__)).'public/class-wpb-public.php';
135 135
 
136 136
 		$this->loader = new WPB_Loader();
137 137
 
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 
151 151
 		$plugin_i18n = new WPB_I18n();
152 152
 
153
-		$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
153
+		$this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
154 154
 
155 155
 	}
156 156
 
@@ -163,10 +163,10 @@  discard block
 block discarded – undo
163 163
 	 */
164 164
 	private function define_admin_hooks() {
165 165
 
166
-		$plugin_admin = new WPB_Admin( $this->get_plugin_name(), $this->get_version() );
166
+		$plugin_admin = new WPB_Admin($this->get_plugin_name(), $this->get_version());
167 167
 
168
-		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
169
-		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
168
+		$this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
169
+		$this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts');
170 170
 
171 171
 	}
172 172
 
@@ -179,10 +179,10 @@  discard block
 block discarded – undo
179 179
 	 */
180 180
 	private function define_public_hooks() {
181 181
 
182
-		$plugin_public = new WPB_Public( $this->get_plugin_name(), $this->get_version() );
182
+		$plugin_public = new WPB_Public($this->get_plugin_name(), $this->get_version());
183 183
 
184
-		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
185
-		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
184
+		$this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles');
185
+		$this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts');
186 186
 
187 187
 	}
188 188
 
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 	 * @return void
233 233
 	 */
234 234
 	public function define_constants() {
235
-		define( 'WPB_VERSION', $this->version );
235
+		define('WPB_VERSION', $this->version);
236 236
 	}
237 237
 
238 238
 	/**
@@ -241,8 +241,8 @@  discard block
 block discarded – undo
241 241
 	 * @return void
242 242
 	 */
243 243
 	public function register_assets() {
244
-		$this->register_scripts( $this->get_scripts() );
245
-		$this->register_styles( $this->get_styles() );
244
+		$this->register_scripts($this->get_scripts());
245
+		$this->register_styles($this->get_styles());
246 246
 	}
247 247
 
248 248
 	/**
@@ -252,13 +252,13 @@  discard block
 block discarded – undo
252 252
 	 *
253 253
 	 * @return void
254 254
 	 */
255
-	private function register_scripts( $scripts ) {
256
-		foreach ( $scripts as $handle => $script ) {
257
-			$deps      = isset( $script['deps'] ) ? $script['deps'] : false;
258
-			$in_footer = isset( $script['in_footer'] ) ? $script['in_footer'] : false;
259
-			$version   = isset( $script['version'] ) ? $script['version'] : WPB_VERSION;
255
+	private function register_scripts($scripts) {
256
+		foreach ($scripts as $handle => $script) {
257
+			$deps      = isset($script['deps']) ? $script['deps'] : false;
258
+			$in_footer = isset($script['in_footer']) ? $script['in_footer'] : false;
259
+			$version   = isset($script['version']) ? $script['version'] : WPB_VERSION;
260 260
 
261
-			wp_register_script( $handle, $script['src'], $deps, $version, $in_footer );
261
+			wp_register_script($handle, $script['src'], $deps, $version, $in_footer);
262 262
 		}
263 263
 	}
264 264
 
@@ -269,11 +269,11 @@  discard block
 block discarded – undo
269 269
 	 *
270 270
 	 * @return void
271 271
 	 */
272
-	public function register_styles( $styles ) {
273
-		foreach ( $styles as $handle => $style ) {
274
-			$deps = isset( $style['deps'] ) ? $style['deps'] : false;
272
+	public function register_styles($styles) {
273
+		foreach ($styles as $handle => $style) {
274
+			$deps = isset($style['deps']) ? $style['deps'] : false;
275 275
 
276
-			wp_register_style( $handle, $style['src'], $deps, WPB_VERSION );
276
+			wp_register_style($handle, $style['src'], $deps, WPB_VERSION);
277 277
 		}
278 278
 	}
279 279
 
@@ -284,35 +284,35 @@  discard block
 block discarded – undo
284 284
 	 */
285 285
 	public function get_scripts() {
286 286
 
287
-		$prefix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.min' : '';
287
+		$prefix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '.min' : '';
288 288
 
289 289
 		$scripts = array(
290 290
 			'wpb-runtime'  => array(
291
-				'src'       => WPB_ASSETS . '/js/runtime.js',
292
-				'version'   => filemtime( WPB_PATH . '/public/js/runtime.js' ),
291
+				'src'       => WPB_ASSETS.'/js/runtime.js',
292
+				'version'   => filemtime(WPB_PATH.'/public/js/runtime.js'),
293 293
 				'in_footer' => true,
294 294
 			),
295 295
 			'wpb-vendor'   => array(
296
-				'src'       => WPB_ASSETS . '/js/vendors.js',
297
-				'version'   => filemtime( WPB_PATH . '/public/js/vendors.js' ),
296
+				'src'       => WPB_ASSETS.'/js/vendors.js',
297
+				'version'   => filemtime(WPB_PATH.'/public/js/vendors.js'),
298 298
 				'in_footer' => true,
299 299
 			),
300 300
 			'wpb-frontend' => array(
301
-				'src'       => WPB_ASSETS . '/js/frontend.js',
302
-				'deps'      => array( 'jquery', 'wpb-vendor', 'wpb-runtime' ),
303
-				'version'   => filemtime( WPB_PATH . '/public/js/frontend.js' ),
301
+				'src'       => WPB_ASSETS.'/js/frontend.js',
302
+				'deps'      => array('jquery', 'wpb-vendor', 'wpb-runtime'),
303
+				'version'   => filemtime(WPB_PATH.'/public/js/frontend.js'),
304 304
 				'in_footer' => true,
305 305
 			),
306 306
 			'wpb-admin'    => array(
307
-				'src'       => WPB_ASSETS . '/js/admin.js',
308
-				'deps'      => array( 'jquery', 'wpb-vendor', 'wpb-runtime' ),
309
-				'version'   => filemtime( WPB_PATH . '/public/js/admin.js' ),
307
+				'src'       => WPB_ASSETS.'/js/admin.js',
308
+				'deps'      => array('jquery', 'wpb-vendor', 'wpb-runtime'),
309
+				'version'   => filemtime(WPB_PATH.'/public/js/admin.js'),
310 310
 				'in_footer' => true,
311 311
 			),
312 312
 			'wpb-spa'      => array(
313
-				'src'       => WPB_ASSETS . '/js/spa.js',
314
-				'deps'      => array( 'jquery', 'wpb-vendor', 'wpb-runtime' ),
315
-				'version'   => filemtime( WPB_PATH . '/public/js/spa.js' ),
313
+				'src'       => WPB_ASSETS.'/js/spa.js',
314
+				'deps'      => array('jquery', 'wpb-vendor', 'wpb-runtime'),
315
+				'version'   => filemtime(WPB_PATH.'/public/js/spa.js'),
316 316
 				'in_footer' => true,
317 317
 			),
318 318
 		);
@@ -329,19 +329,19 @@  discard block
 block discarded – undo
329 329
 
330 330
 		$styles = array(
331 331
 			'wpb-style'    => array(
332
-				'src' => WPB_ASSETS . '/css/style.css',
332
+				'src' => WPB_ASSETS.'/css/style.css',
333 333
 			),
334 334
 			'wpb-frontend' => array(
335
-				'src' => WPB_ASSETS . '/css/frontend.css',
335
+				'src' => WPB_ASSETS.'/css/frontend.css',
336 336
 			),
337 337
 			'wpb-admin'    => array(
338
-				'src' => WPB_ASSETS . '/css/admin.css',
338
+				'src' => WPB_ASSETS.'/css/admin.css',
339 339
 			),
340 340
 			'wpb-spa'      => array(
341
-				'src' => WPB_ASSETS . '/css/spa.css',
341
+				'src' => WPB_ASSETS.'/css/spa.css',
342 342
 			),
343 343
 			'wpb-vendors'  => array(
344
-				'src' => WPB_ASSETS . '/css/vendors.css',
344
+				'src' => WPB_ASSETS.'/css/vendors.css',
345 345
 			),
346 346
 		);
347 347
 
Please login to merge, or discard this patch.
admin/class-wpb-admin.php 2 patches
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -21,106 +21,106 @@
 block discarded – undo
21 21
  */
22 22
 class WPB_Admin {
23 23
 
24
-	/**
25
-	 * The ID of this plugin.
26
-	 *
27
-	 * @since    1.0.0
28
-	 * @access   private
29
-	 * @var      string    $plugin_name    The ID of this plugin.
30
-	 */
31
-	private $plugin_name;
24
+    /**
25
+     * The ID of this plugin.
26
+     *
27
+     * @since    1.0.0
28
+     * @access   private
29
+     * @var      string    $plugin_name    The ID of this plugin.
30
+     */
31
+    private $plugin_name;
32 32
 
33
-	/**
34
-	 * The version of this plugin.
35
-	 *
36
-	 * @since    1.0.0
37
-	 * @access   private
38
-	 * @var      string    $version    The current version of this plugin.
39
-	 */
40
-	private $version;
33
+    /**
34
+     * The version of this plugin.
35
+     *
36
+     * @since    1.0.0
37
+     * @access   private
38
+     * @var      string    $version    The current version of this plugin.
39
+     */
40
+    private $version;
41 41
 
42
-	/**
43
-	 * Initialize the class and set its properties.
44
-	 *
45
-	 * @since    1.0.0
46
-	 * @param      string $plugin_name       The name of this plugin.
47
-	 * @param      string $version    The version of this plugin.
48
-	 */
49
-	public function __construct( $plugin_name, $version ) {
42
+    /**
43
+     * Initialize the class and set its properties.
44
+     *
45
+     * @since    1.0.0
46
+     * @param      string $plugin_name       The name of this plugin.
47
+     * @param      string $version    The version of this plugin.
48
+     */
49
+    public function __construct( $plugin_name, $version ) {
50 50
 
51
-		$this->plugin_name = $plugin_name;
52
-		$this->version     = $version;
53
-		$this->register_menus();
54
-	}
51
+        $this->plugin_name = $plugin_name;
52
+        $this->version     = $version;
53
+        $this->register_menus();
54
+    }
55 55
 
56
-	/**
57
-	 * Register the stylesheets for the admin area.
58
-	 *
59
-	 * @since    1.0.0
60
-	 */
61
-	public function enqueue_styles() {
56
+    /**
57
+     * Register the stylesheets for the admin area.
58
+     *
59
+     * @since    1.0.0
60
+     */
61
+    public function enqueue_styles() {
62 62
 
63
-		/**
64
-		 * This function is provided for demonstration purposes only.
65
-		 *
66
-		 * An instance of this class should be passed to the run() function
67
-		 * defined in WPB_Loader as all of the hooks are defined
68
-		 * in that particular class.
69
-		 *
70
-		 * The WPB_Loader will then create the relationship
71
-		 * between the defined hooks and the functions defined in this
72
-		 * class.
73
-		 */
63
+        /**
64
+         * This function is provided for demonstration purposes only.
65
+         *
66
+         * An instance of this class should be passed to the run() function
67
+         * defined in WPB_Loader as all of the hooks are defined
68
+         * in that particular class.
69
+         *
70
+         * The WPB_Loader will then create the relationship
71
+         * between the defined hooks and the functions defined in this
72
+         * class.
73
+         */
74 74
 
75
-		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wpb-admin.css', array(), $this->version, 'all' );
75
+        wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wpb-admin.css', array(), $this->version, 'all' );
76 76
 
77
-	}
77
+    }
78 78
 
79
-	/**
80
-	 * Register the JavaScript for the admin area.
81
-	 *
82
-	 * @since    1.0.0
83
-	 */
84
-	public function enqueue_scripts() {
79
+    /**
80
+     * Register the JavaScript for the admin area.
81
+     *
82
+     * @since    1.0.0
83
+     */
84
+    public function enqueue_scripts() {
85 85
 
86
-		/**
87
-		 * This function is provided for demonstration purposes only.
88
-		 *
89
-		 * An instance of this class should be passed to the run() function
90
-		 * defined in WPB_Loader as all of the hooks are defined
91
-		 * in that particular class.
92
-		 *
93
-		 * The WPB_Loader will then create the relationship
94
-		 * between the defined hooks and the functions defined in this
95
-		 * class.
96
-		 */
86
+        /**
87
+         * This function is provided for demonstration purposes only.
88
+         *
89
+         * An instance of this class should be passed to the run() function
90
+         * defined in WPB_Loader as all of the hooks are defined
91
+         * in that particular class.
92
+         *
93
+         * The WPB_Loader will then create the relationship
94
+         * between the defined hooks and the functions defined in this
95
+         * class.
96
+         */
97 97
 
98
-		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wpb-admin.js', array( 'jquery' ), $this->version, false );
98
+        wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wpb-admin.js', array( 'jquery' ), $this->version, false );
99 99
 
100
-	}
100
+    }
101 101
 
102
-	/**
103
-	 * Register all menus here.
104
-	 *
105
-	 * @since    1.0.0
106
-	 */
107
-	public function register_menus() {
108
-		// Registerv root menu.
109
-		$menu             = new WPB_Admin_Menu( $this->plugin_name );
110
-		$menu->page_title = 'WPB';
111
-		$menu->menu_title = 'WPB';
112
-		$menu->capability = 'manage_options';
113
-		$menu->slug       = 'wpb';
114
-		$menu->icon       = 'dashicons-text';
115
-		$menu->save();
116
-		// Register submenu for root menu.
117
-		$submenu              = new WPB_Admin_SubMenu( $this->plugin_name );
118
-		$submenu->parent_slug = $menu->slug;
119
-		$submenu->page_title  = 'Settings';
120
-		$submenu->menu_title  = 'Settings';
121
-		$submenu->capability  = 'manage_options';
122
-		$submenu->slug        = 'admin.php?page=' . $menu->slug . '#/settings';
123
-		$submenu->save();
124
-	}
102
+    /**
103
+     * Register all menus here.
104
+     *
105
+     * @since    1.0.0
106
+     */
107
+    public function register_menus() {
108
+        // Registerv root menu.
109
+        $menu             = new WPB_Admin_Menu( $this->plugin_name );
110
+        $menu->page_title = 'WPB';
111
+        $menu->menu_title = 'WPB';
112
+        $menu->capability = 'manage_options';
113
+        $menu->slug       = 'wpb';
114
+        $menu->icon       = 'dashicons-text';
115
+        $menu->save();
116
+        // Register submenu for root menu.
117
+        $submenu              = new WPB_Admin_SubMenu( $this->plugin_name );
118
+        $submenu->parent_slug = $menu->slug;
119
+        $submenu->page_title  = 'Settings';
120
+        $submenu->menu_title  = 'Settings';
121
+        $submenu->capability  = 'manage_options';
122
+        $submenu->slug        = 'admin.php?page=' . $menu->slug . '#/settings';
123
+        $submenu->save();
124
+    }
125 125
 
126 126
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	 * @param      string $plugin_name       The name of this plugin.
47 47
 	 * @param      string $version    The version of this plugin.
48 48
 	 */
49
-	public function __construct( $plugin_name, $version ) {
49
+	public function __construct($plugin_name, $version) {
50 50
 
51 51
 		$this->plugin_name = $plugin_name;
52 52
 		$this->version     = $version;
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 		 * class.
73 73
 		 */
74 74
 
75
-		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wpb-admin.css', array(), $this->version, 'all' );
75
+		wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__).'css/wpb-admin.css', array(), $this->version, 'all');
76 76
 
77 77
 	}
78 78
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 		 * class.
96 96
 		 */
97 97
 
98
-		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wpb-admin.js', array( 'jquery' ), $this->version, false );
98
+		wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__).'js/wpb-admin.js', array('jquery'), $this->version, false);
99 99
 
100 100
 	}
101 101
 
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	 */
107 107
 	public function register_menus() {
108 108
 		// Registerv root menu.
109
-		$menu             = new WPB_Admin_Menu( $this->plugin_name );
109
+		$menu             = new WPB_Admin_Menu($this->plugin_name);
110 110
 		$menu->page_title = 'WPB';
111 111
 		$menu->menu_title = 'WPB';
112 112
 		$menu->capability = 'manage_options';
@@ -114,12 +114,12 @@  discard block
 block discarded – undo
114 114
 		$menu->icon       = 'dashicons-text';
115 115
 		$menu->save();
116 116
 		// Register submenu for root menu.
117
-		$submenu              = new WPB_Admin_SubMenu( $this->plugin_name );
117
+		$submenu              = new WPB_Admin_SubMenu($this->plugin_name);
118 118
 		$submenu->parent_slug = $menu->slug;
119 119
 		$submenu->page_title  = 'Settings';
120 120
 		$submenu->menu_title  = 'Settings';
121 121
 		$submenu->capability  = 'manage_options';
122
-		$submenu->slug        = 'admin.php?page=' . $menu->slug . '#/settings';
122
+		$submenu->slug        = 'admin.php?page='.$menu->slug.'#/settings';
123 123
 		$submenu->save();
124 124
 	}
125 125
 
Please login to merge, or discard this patch.
admin/class-wpb-admin-menu.php 2 patches
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -21,160 +21,160 @@
 block discarded – undo
21 21
  */
22 22
 class WPB_Admin_Menu {
23 23
 
24
-	/**
25
-	 * The menu page title.
26
-	 *
27
-	 * @since    1.0.0
28
-	 * @access   public
29
-	 * @var      string    $page_title    The string used to set menu page title.
30
-	 */
31
-	public $page_title;
32
-
33
-	/**
34
-	 * The menu title.
35
-	 *
36
-	 * @since    1.0.0
37
-	 * @access   public
38
-	 * @var      string    $menu_title    The string used to set menu title.
39
-	 */
40
-	public $menu_title;
41
-
42
-	/**
43
-	 * The menu capability.
44
-	 *
45
-	 * @since    1.0.0
46
-	 * @access   public
47
-	 * @var      string    $capability    The string used to set menu capability.
48
-	 */
49
-	public $capability;
50
-
51
-	/**
52
-	 * The menu slug.
53
-	 *
54
-	 * @since    1.0.0
55
-	 * @access   public
56
-	 * @var      string    $slug    The string used to set menu slug.
57
-	 */
58
-	public $slug;
59
-
60
-	/**
61
-	 * The callback to render content.
62
-	 *
63
-	 * @since    1.0.0
64
-	 * @access   public
65
-	 * @var      callback    $callback    The callback used to render content.
66
-	 */
67
-	public $callback = null;
68
-
69
-	/**
70
-	 * The menu icon.
71
-	 *
72
-	 * @since    1.0.0
73
-	 * @access   public
74
-	 * @var      string    $icon    The string used to set menu icon.
75
-	 */
76
-	public $icon;
77
-
78
-	/**
79
-	 * The menu position.
80
-	 *
81
-	 * @since    1.0.0
82
-	 * @access   public
83
-	 * @var      int    $position    The string used to set menu position.
84
-	 */
85
-	public $position;
86
-
87
-	/**
88
-	 * The menu plugin name.
89
-	 *
90
-	 * @since    1.0.0
91
-	 * @access   private
92
-	 * @var      string    $plugin_name    The string used to uniquely identify this plugin.
93
-	 */
94
-	private $plugin_name;
95
-
96
-	/**
97
-	 * Boot Menu.
98
-	 *
99
-	 * @param  string $plugin_name The string used to uniquely identify this plugin.
100
-	 * @since    1.0.0
101
-	 * @access   public
102
-	 */
103
-	public function __construct( $plugin_name ) {
104
-		$this->plugin_name = $plugin_name;
105
-	}
106
-
107
-	/**
108
-	 * Create a new menu page.
109
-	 *
110
-	 * @since    1.0.0
111
-	 * @access   public
112
-	 */
113
-	public function save() {
114
-		add_action( 'admin_menu', array( $this, 'create_menu' ) );
115
-	}
116
-
117
-	/**
118
-	 * Create a new menu page.
119
-	 *
120
-	 * @since    1.0.0
121
-	 * @param    array $options Pass proprties as an array.
122
-	 * @access   public
123
-	 */
124
-	public function make( $options = array() ) {
125
-		foreach ( $options as $property => $value ) {
126
-			if ( property_exists( get_called_class(), $property ) ) {
127
-				$this->{$property} = $value;
128
-			}
129
-		}
130
-		add_action( 'admin_menu', array( $this, 'create_menu' ) );
131
-	}
132
-
133
-	/**
134
-	 * Register new menu page.
135
-	 *
136
-	 * @return void
137
-	 */
138
-	public function create_menu() {
139
-		$callback = $this->callback ?? array( $this, 'render_content' );
140
-		$hook     = add_menu_page(
141
-			$this->page_title,
142
-			$this->menu_title,
143
-			$this->capability,
144
-			$this->slug,
145
-			$callback,
146
-			$this->icon
147
-		);
148
-
149
-		add_action( 'load-' . $hook, array( $this, 'init_hooks' ) );
150
-	}
151
-
152
-	/**
153
-	 * Initialize hooks for the admin page.
154
-	 *
155
-	 * @return void
156
-	 */
157
-	public function init_hooks() {
158
-		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
159
-	}
160
-
161
-	/**
162
-	 * Load scripts and styles for the current menu page.
163
-	 *
164
-	 * @return void
165
-	 */
166
-	public function enqueue_scripts() {
167
-		wp_enqueue_style( $this->plugin_name . '-vendors' );
168
-		wp_enqueue_style( $this->plugin_name . '-admin' );
169
-		wp_enqueue_script( $this->plugin_name . '-admin' );
170
-	}
171
-
172
-	/**
173
-	 * Render app content.
174
-	 *
175
-	 * @return void
176
-	 */
177
-	public function render_content() {
178
-		echo '<div class="wrap"><div id="wpb-admin" base-url="' . esc_attr( get_site_url() ) . '" csrf-token="' . esc_attr( wpb_csrf_token() ) . '"></div></div>';
179
-	}
24
+    /**
25
+     * The menu page title.
26
+     *
27
+     * @since    1.0.0
28
+     * @access   public
29
+     * @var      string    $page_title    The string used to set menu page title.
30
+     */
31
+    public $page_title;
32
+
33
+    /**
34
+     * The menu title.
35
+     *
36
+     * @since    1.0.0
37
+     * @access   public
38
+     * @var      string    $menu_title    The string used to set menu title.
39
+     */
40
+    public $menu_title;
41
+
42
+    /**
43
+     * The menu capability.
44
+     *
45
+     * @since    1.0.0
46
+     * @access   public
47
+     * @var      string    $capability    The string used to set menu capability.
48
+     */
49
+    public $capability;
50
+
51
+    /**
52
+     * The menu slug.
53
+     *
54
+     * @since    1.0.0
55
+     * @access   public
56
+     * @var      string    $slug    The string used to set menu slug.
57
+     */
58
+    public $slug;
59
+
60
+    /**
61
+     * The callback to render content.
62
+     *
63
+     * @since    1.0.0
64
+     * @access   public
65
+     * @var      callback    $callback    The callback used to render content.
66
+     */
67
+    public $callback = null;
68
+
69
+    /**
70
+     * The menu icon.
71
+     *
72
+     * @since    1.0.0
73
+     * @access   public
74
+     * @var      string    $icon    The string used to set menu icon.
75
+     */
76
+    public $icon;
77
+
78
+    /**
79
+     * The menu position.
80
+     *
81
+     * @since    1.0.0
82
+     * @access   public
83
+     * @var      int    $position    The string used to set menu position.
84
+     */
85
+    public $position;
86
+
87
+    /**
88
+     * The menu plugin name.
89
+     *
90
+     * @since    1.0.0
91
+     * @access   private
92
+     * @var      string    $plugin_name    The string used to uniquely identify this plugin.
93
+     */
94
+    private $plugin_name;
95
+
96
+    /**
97
+     * Boot Menu.
98
+     *
99
+     * @param  string $plugin_name The string used to uniquely identify this plugin.
100
+     * @since    1.0.0
101
+     * @access   public
102
+     */
103
+    public function __construct( $plugin_name ) {
104
+        $this->plugin_name = $plugin_name;
105
+    }
106
+
107
+    /**
108
+     * Create a new menu page.
109
+     *
110
+     * @since    1.0.0
111
+     * @access   public
112
+     */
113
+    public function save() {
114
+        add_action( 'admin_menu', array( $this, 'create_menu' ) );
115
+    }
116
+
117
+    /**
118
+     * Create a new menu page.
119
+     *
120
+     * @since    1.0.0
121
+     * @param    array $options Pass proprties as an array.
122
+     * @access   public
123
+     */
124
+    public function make( $options = array() ) {
125
+        foreach ( $options as $property => $value ) {
126
+            if ( property_exists( get_called_class(), $property ) ) {
127
+                $this->{$property} = $value;
128
+            }
129
+        }
130
+        add_action( 'admin_menu', array( $this, 'create_menu' ) );
131
+    }
132
+
133
+    /**
134
+     * Register new menu page.
135
+     *
136
+     * @return void
137
+     */
138
+    public function create_menu() {
139
+        $callback = $this->callback ?? array( $this, 'render_content' );
140
+        $hook     = add_menu_page(
141
+            $this->page_title,
142
+            $this->menu_title,
143
+            $this->capability,
144
+            $this->slug,
145
+            $callback,
146
+            $this->icon
147
+        );
148
+
149
+        add_action( 'load-' . $hook, array( $this, 'init_hooks' ) );
150
+    }
151
+
152
+    /**
153
+     * Initialize hooks for the admin page.
154
+     *
155
+     * @return void
156
+     */
157
+    public function init_hooks() {
158
+        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
159
+    }
160
+
161
+    /**
162
+     * Load scripts and styles for the current menu page.
163
+     *
164
+     * @return void
165
+     */
166
+    public function enqueue_scripts() {
167
+        wp_enqueue_style( $this->plugin_name . '-vendors' );
168
+        wp_enqueue_style( $this->plugin_name . '-admin' );
169
+        wp_enqueue_script( $this->plugin_name . '-admin' );
170
+    }
171
+
172
+    /**
173
+     * Render app content.
174
+     *
175
+     * @return void
176
+     */
177
+    public function render_content() {
178
+        echo '<div class="wrap"><div id="wpb-admin" base-url="' . esc_attr( get_site_url() ) . '" csrf-token="' . esc_attr( wpb_csrf_token() ) . '"></div></div>';
179
+    }
180 180
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 	 * @since    1.0.0
101 101
 	 * @access   public
102 102
 	 */
103
-	public function __construct( $plugin_name ) {
103
+	public function __construct($plugin_name) {
104 104
 		$this->plugin_name = $plugin_name;
105 105
 	}
106 106
 
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 	 * @access   public
112 112
 	 */
113 113
 	public function save() {
114
-		add_action( 'admin_menu', array( $this, 'create_menu' ) );
114
+		add_action('admin_menu', array($this, 'create_menu'));
115 115
 	}
116 116
 
117 117
 	/**
@@ -121,13 +121,13 @@  discard block
 block discarded – undo
121 121
 	 * @param    array $options Pass proprties as an array.
122 122
 	 * @access   public
123 123
 	 */
124
-	public function make( $options = array() ) {
125
-		foreach ( $options as $property => $value ) {
126
-			if ( property_exists( get_called_class(), $property ) ) {
124
+	public function make($options = array()) {
125
+		foreach ($options as $property => $value) {
126
+			if (property_exists(get_called_class(), $property)) {
127 127
 				$this->{$property} = $value;
128 128
 			}
129 129
 		}
130
-		add_action( 'admin_menu', array( $this, 'create_menu' ) );
130
+		add_action('admin_menu', array($this, 'create_menu'));
131 131
 	}
132 132
 
133 133
 	/**
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 	 * @return void
137 137
 	 */
138 138
 	public function create_menu() {
139
-		$callback = $this->callback ?? array( $this, 'render_content' );
139
+		$callback = $this->callback ?? array($this, 'render_content');
140 140
 		$hook     = add_menu_page(
141 141
 			$this->page_title,
142 142
 			$this->menu_title,
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 			$this->icon
147 147
 		);
148 148
 
149
-		add_action( 'load-' . $hook, array( $this, 'init_hooks' ) );
149
+		add_action('load-'.$hook, array($this, 'init_hooks'));
150 150
 	}
151 151
 
152 152
 	/**
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	 * @return void
156 156
 	 */
157 157
 	public function init_hooks() {
158
-		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
158
+		add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
159 159
 	}
160 160
 
161 161
 	/**
@@ -164,9 +164,9 @@  discard block
 block discarded – undo
164 164
 	 * @return void
165 165
 	 */
166 166
 	public function enqueue_scripts() {
167
-		wp_enqueue_style( $this->plugin_name . '-vendors' );
168
-		wp_enqueue_style( $this->plugin_name . '-admin' );
169
-		wp_enqueue_script( $this->plugin_name . '-admin' );
167
+		wp_enqueue_style($this->plugin_name.'-vendors');
168
+		wp_enqueue_style($this->plugin_name.'-admin');
169
+		wp_enqueue_script($this->plugin_name.'-admin');
170 170
 	}
171 171
 
172 172
 	/**
@@ -175,6 +175,6 @@  discard block
 block discarded – undo
175 175
 	 * @return void
176 176
 	 */
177 177
 	public function render_content() {
178
-		echo '<div class="wrap"><div id="wpb-admin" base-url="' . esc_attr( get_site_url() ) . '" csrf-token="' . esc_attr( wpb_csrf_token() ) . '"></div></div>';
178
+		echo '<div class="wrap"><div id="wpb-admin" base-url="'.esc_attr(get_site_url()).'" csrf-token="'.esc_attr(wpb_csrf_token()).'"></div></div>';
179 179
 	}
180 180
 }
Please login to merge, or discard this patch.
bootstrap/app.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -16,11 +16,11 @@  discard block
 block discarded – undo
16 16
 use WPB\Application;
17 17
 
18 18
 $app = ( new Application(
19
-	array(
20
-		'paths' => array(
21
-			'root' => WPB_APP_ROOT,
22
-		),
23
-	)
19
+    array(
20
+        'paths' => array(
21
+            'root' => WPB_APP_ROOT,
22
+        ),
23
+    )
24 24
 ) );
25 25
 
26 26
 global $wpb_app;
@@ -28,27 +28,27 @@  discard block
 block discarded – undo
28 28
 $wpb_app = $container = $app->get_instance();
29 29
 
30 30
 $container->singleton(
31
-	Illuminate\Contracts\Http\Kernel::class,
32
-	\WPB\App\Http\Kernel::class
31
+    Illuminate\Contracts\Http\Kernel::class,
32
+    \WPB\App\Http\Kernel::class
33 33
 );
34 34
 $container->singleton(
35
-	\Illuminate\Contracts\Debug\ExceptionHandler::class,
36
-	\WPB\App\Exceptions\Handler::class
35
+    \Illuminate\Contracts\Debug\ExceptionHandler::class,
36
+    \WPB\App\Exceptions\Handler::class
37 37
 );
38 38
 
39 39
 if ( \WPB\Support\Facades\Route::exists( \Illuminate\Http\Request::capture() ) ) {
40
-	try {
40
+    try {
41 41
 
42
-		$kernel = $container->make( \Illuminate\Contracts\Http\Kernel::class );
42
+        $kernel = $container->make( \Illuminate\Contracts\Http\Kernel::class );
43 43
 
44
-		$response = $kernel->handle( \Illuminate\Http\Request::capture() );
44
+        $response = $kernel->handle( \Illuminate\Http\Request::capture() );
45 45
 
46
-		$response->send();
46
+        $response->send();
47 47
 
48
-	} catch ( \Exception $ex ) {
49
-		if ( ! \WPB\Support\Facades\Route::current() ) {
50
-			return true;
51
-		}
52
-		throw new \Exception( $ex, 1 );
53
-	}
48
+    } catch ( \Exception $ex ) {
49
+        if ( ! \WPB\Support\Facades\Route::current() ) {
50
+            return true;
51
+        }
52
+        throw new \Exception( $ex, 1 );
53
+    }
54 54
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -9,19 +9,19 @@  discard block
 block discarded – undo
9 9
  * @subpackage WPB/bootstrap
10 10
  */
11 11
 
12
-require_once ABSPATH . 'wp-includes/pluggable.php';
13
-require_once __DIR__ . '/../vendor/autoload.php';
14
-require_once __DIR__ . '/../src/helpers.php';
12
+require_once ABSPATH.'wp-includes/pluggable.php';
13
+require_once __DIR__.'/../vendor/autoload.php';
14
+require_once __DIR__.'/../src/helpers.php';
15 15
 
16 16
 use WPB\Application;
17 17
 
18
-$app = ( new Application(
18
+$app = (new Application(
19 19
 	array(
20 20
 		'paths' => array(
21 21
 			'root' => WPB_APP_ROOT,
22 22
 		),
23 23
 	)
24
-) );
24
+));
25 25
 
26 26
 global $wpb_app;
27 27
 
@@ -36,19 +36,19 @@  discard block
 block discarded – undo
36 36
 	\WPB\App\Exceptions\Handler::class
37 37
 );
38 38
 
39
-if ( \WPB\Support\Facades\Route::exists( \Illuminate\Http\Request::capture() ) ) {
39
+if (\WPB\Support\Facades\Route::exists(\Illuminate\Http\Request::capture())) {
40 40
 	try {
41 41
 
42
-		$kernel = $container->make( \Illuminate\Contracts\Http\Kernel::class );
42
+		$kernel = $container->make(\Illuminate\Contracts\Http\Kernel::class);
43 43
 
44
-		$response = $kernel->handle( \Illuminate\Http\Request::capture() );
44
+		$response = $kernel->handle(\Illuminate\Http\Request::capture());
45 45
 
46 46
 		$response->send();
47 47
 
48
-	} catch ( \Exception $ex ) {
49
-		if ( ! \WPB\Support\Facades\Route::current() ) {
48
+	} catch (\Exception $ex) {
49
+		if (!\WPB\Support\Facades\Route::current()) {
50 50
 			return true;
51 51
 		}
52
-		throw new \Exception( $ex, 1 );
52
+		throw new \Exception($ex, 1);
53 53
 	}
54 54
 }
Please login to merge, or discard this patch.
src/helpers.php 2 patches
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -31,60 +31,60 @@  discard block
 block discarded – undo
31 31
 use Illuminate\Contracts\Broadcasting\Factory as BroadcastFactory;
32 32
 
33 33
 if ( ! function_exists( 'wpb_csrf_token' ) ) {
34
-	/**
35
-	 * Generate wp nonce.
36
-	 *
37
-	 * @param string|null $action   This is the nonce action name.
38
-	 *
39
-	 * @return null|string
40
-	 */
41
-	function wpb_csrf_token( $action = 'wpb_nonce' ) {
42
-		return wp_create_nonce( $action );
43
-	}
34
+    /**
35
+     * Generate wp nonce.
36
+     *
37
+     * @param string|null $action   This is the nonce action name.
38
+     *
39
+     * @return null|string
40
+     */
41
+    function wpb_csrf_token( $action = 'wpb_nonce' ) {
42
+        return wp_create_nonce( $action );
43
+    }
44 44
 }
45 45
 
46 46
 if ( ! function_exists( 'wpb_config' ) ) {
47
-	/**
48
-	 * Get / set the specified configuration value.
49
-	 *
50
-	 * If an array is passed as the key, we will assume you want to set an array of values.
51
-	 *
52
-	 * @param array|string|null $key This is the key for config array.
53
-	 * @param mixed             $default This is the default config value.
54
-	 *
55
-	 * @return mixed|\Illuminate\Config\Repository
56
-	 */
57
-	function wpb_config( $key = null, $default = null ) {
58
-		if ( is_null( $key ) ) {
59
-			return app( 'config' );
60
-		}
61
-
62
-		if ( is_array( $key ) ) {
63
-			return app( 'config' )->set( $key );
64
-		}
65
-
66
-		return app( 'config' )->get( $key, $default );
67
-	}
47
+    /**
48
+     * Get / set the specified configuration value.
49
+     *
50
+     * If an array is passed as the key, we will assume you want to set an array of values.
51
+     *
52
+     * @param array|string|null $key This is the key for config array.
53
+     * @param mixed             $default This is the default config value.
54
+     *
55
+     * @return mixed|\Illuminate\Config\Repository
56
+     */
57
+    function wpb_config( $key = null, $default = null ) {
58
+        if ( is_null( $key ) ) {
59
+            return app( 'config' );
60
+        }
61
+
62
+        if ( is_array( $key ) ) {
63
+            return app( 'config' )->set( $key );
64
+        }
65
+
66
+        return app( 'config' )->get( $key, $default );
67
+    }
68 68
 }
69 69
 
70 70
 if ( ! function_exists( 'wpb_view' ) ) {
71
-	/**
72
-	 * Render blade view.
73
-	 *
74
-	 * @param string $view   This is the filename.
75
-	 * @param array  $data   This is the view data.
76
-	 * @param array  $merge_data   This is the merge data for view.
77
-	 *
78
-	 * @throws \Exception This will throw an exception if view class doesn't exists.
79
-	 * @return null|string
80
-	 */
81
-	function wpb_view( $view, $data = array(), $merge_data = array() ) {
82
-		if ( ! class_exists( \CodexShaper\Blade\View::class ) ) {
83
-			throw new \Exception( 'View not resolved. Please install View' );
84
-		}
85
-
86
-		return ( new \CodexShaper\Blade\View( array( __DIR__ . '/../resources/views' ), __DIR__ . '/../storage/cache' ) )->make( $view, $data = array(), $merge_data = array() );
87
-	}
71
+    /**
72
+     * Render blade view.
73
+     *
74
+     * @param string $view   This is the filename.
75
+     * @param array  $data   This is the view data.
76
+     * @param array  $merge_data   This is the merge data for view.
77
+     *
78
+     * @throws \Exception This will throw an exception if view class doesn't exists.
79
+     * @return null|string
80
+     */
81
+    function wpb_view( $view, $data = array(), $merge_data = array() ) {
82
+        if ( ! class_exists( \CodexShaper\Blade\View::class ) ) {
83
+            throw new \Exception( 'View not resolved. Please install View' );
84
+        }
85
+
86
+        return ( new \CodexShaper\Blade\View( array( __DIR__ . '/../resources/views' ), __DIR__ . '/../storage/cache' ) )->make( $view, $data = array(), $merge_data = array() );
87
+    }
88 88
 }
89 89
 
90 90
 if (! function_exists('wpb_abort')) {
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
      */
179 179
     function wpb_app($abstract = null, array $parameters = [])
180 180
     {
181
-    	global $wpb_app;
181
+        global $wpb_app;
182 182
 
183 183
         if (is_null($abstract)) {
184 184
             return $wpb_app;
Please login to merge, or discard this patch.
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 use Illuminate\Contracts\Validation\Factory as ValidationFactory;
31 31
 use Illuminate\Contracts\Broadcasting\Factory as BroadcastFactory;
32 32
 
33
-if ( ! function_exists( 'wpb_csrf_token' ) ) {
33
+if (!function_exists('wpb_csrf_token')) {
34 34
 	/**
35 35
 	 * Generate wp nonce.
36 36
 	 *
@@ -38,12 +38,12 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @return null|string
40 40
 	 */
41
-	function wpb_csrf_token( $action = 'wpb_nonce' ) {
42
-		return wp_create_nonce( $action );
41
+	function wpb_csrf_token($action = 'wpb_nonce') {
42
+		return wp_create_nonce($action);
43 43
 	}
44 44
 }
45 45
 
46
-if ( ! function_exists( 'wpb_config' ) ) {
46
+if (!function_exists('wpb_config')) {
47 47
 	/**
48 48
 	 * Get / set the specified configuration value.
49 49
 	 *
@@ -54,20 +54,20 @@  discard block
 block discarded – undo
54 54
 	 *
55 55
 	 * @return mixed|\Illuminate\Config\Repository
56 56
 	 */
57
-	function wpb_config( $key = null, $default = null ) {
58
-		if ( is_null( $key ) ) {
59
-			return app( 'config' );
57
+	function wpb_config($key = null, $default = null) {
58
+		if (is_null($key)) {
59
+			return app('config');
60 60
 		}
61 61
 
62
-		if ( is_array( $key ) ) {
63
-			return app( 'config' )->set( $key );
62
+		if (is_array($key)) {
63
+			return app('config')->set($key);
64 64
 		}
65 65
 
66
-		return app( 'config' )->get( $key, $default );
66
+		return app('config')->get($key, $default);
67 67
 	}
68 68
 }
69 69
 
70
-if ( ! function_exists( 'wpb_view' ) ) {
70
+if (!function_exists('wpb_view')) {
71 71
 	/**
72 72
 	 * Render blade view.
73 73
 	 *
@@ -78,16 +78,16 @@  discard block
 block discarded – undo
78 78
 	 * @throws \Exception This will throw an exception if view class doesn't exists.
79 79
 	 * @return null|string
80 80
 	 */
81
-	function wpb_view( $view, $data = array(), $merge_data = array() ) {
82
-		if ( ! class_exists( \CodexShaper\Blade\View::class ) ) {
83
-			throw new \Exception( 'View not resolved. Please install View' );
81
+	function wpb_view($view, $data = array(), $merge_data = array()) {
82
+		if (!class_exists(\CodexShaper\Blade\View::class)) {
83
+			throw new \Exception('View not resolved. Please install View');
84 84
 		}
85 85
 
86
-		return ( new \CodexShaper\Blade\View( array( __DIR__ . '/../resources/views' ), __DIR__ . '/../storage/cache' ) )->make( $view, $data = array(), $merge_data = array() );
86
+		return (new \CodexShaper\Blade\View(array(__DIR__.'/../resources/views'), __DIR__.'/../storage/cache'))->make($view, $data = array(), $merge_data = array());
87 87
 	}
88 88
 }
89 89
 
90
-if (! function_exists('wpb_abort')) {
90
+if (!function_exists('wpb_abort')) {
91 91
     /**
92 92
      * Throw an HttpException with the given data.
93 93
      *
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
     }
112 112
 }
113 113
 
114
-if (! function_exists('wpb_abort_if')) {
114
+if (!function_exists('wpb_abort_if')) {
115 115
     /**
116 116
      * Throw an HttpException with the given data if the given condition is true.
117 117
      *
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
     }
133 133
 }
134 134
 
135
-if (! function_exists('wpb_abort_unless')) {
135
+if (!function_exists('wpb_abort_unless')) {
136 136
     /**
137 137
      * Throw an HttpException with the given data unless the given condition is true.
138 138
      *
@@ -147,13 +147,13 @@  discard block
 block discarded – undo
147 147
      */
148 148
     function wpb_abort_unless($boolean, $code, $message = '', array $headers = [])
149 149
     {
150
-        if (! $boolean) {
150
+        if (!$boolean) {
151 151
             wpb_abort($code, $message, $headers);
152 152
         }
153 153
     }
154 154
 }
155 155
 
156
-if (! function_exists('wpb_action')) {
156
+if (!function_exists('wpb_action')) {
157 157
     /**
158 158
      * Generate the URL to a controller action.
159 159
      *
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
     }
169 169
 }
170 170
 
171
-if (! function_exists('wpb_app')) {
171
+if (!function_exists('wpb_app')) {
172 172
     /**
173 173
      * Get the available container instance.
174 174
      *
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
     }
189 189
 }
190 190
 
191
-if (! function_exists('wpb_app_path')) {
191
+if (!function_exists('wpb_app_path')) {
192 192
     /**
193 193
      * Get the path to the application folder.
194 194
      *
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
     }
202 202
 }
203 203
 
204
-if (! function_exists('wpb_asset')) {
204
+if (!function_exists('wpb_asset')) {
205 205
     /**
206 206
      * Generate an asset path for the application.
207 207
      *
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
     }
216 216
 }
217 217
 
218
-if (! function_exists('wpb_auth')) {
218
+if (!function_exists('wpb_auth')) {
219 219
     /**
220 220
      * Get the available auth instance.
221 221
      *
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
     }
233 233
 }
234 234
 
235
-if (! function_exists('wpb_back')) {
235
+if (!function_exists('wpb_back')) {
236 236
     /**
237 237
      * Create a new redirect response to the previous location.
238 238
      *
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
     }
248 248
 }
249 249
 
250
-if (! function_exists('wpb_base_path')) {
250
+if (!function_exists('wpb_base_path')) {
251 251
     /**
252 252
      * Get the path to the base of the install.
253 253
      *
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
     }
261 261
 }
262 262
 
263
-if (! function_exists('wpb_bcrypt')) {
263
+if (!function_exists('wpb_bcrypt')) {
264 264
     /**
265 265
      * Hash the given value against the bcrypt algorithm.
266 266
      *
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
     }
275 275
 }
276 276
 
277
-if (! function_exists('wpb_broadcast')) {
277
+if (!function_exists('wpb_broadcast')) {
278 278
     /**
279 279
      * Begin broadcasting an event.
280 280
      *
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
     }
288 288
 }
289 289
 
290
-if (! function_exists('wpb_cache')) {
290
+if (!function_exists('wpb_cache')) {
291 291
     /**
292 292
      * Get / set the specified cache value.
293 293
      *
@@ -310,13 +310,13 @@  discard block
 block discarded – undo
310 310
             return wpb_app('cache')->get($arguments[0], $arguments[1] ?? null);
311 311
         }
312 312
 
313
-        if (! is_array($arguments[0])) {
313
+        if (!is_array($arguments[0])) {
314 314
             throw new Exception(
315 315
                 'When setting a value in the cache, you must pass an array of key / value pairs.'
316 316
             );
317 317
         }
318 318
 
319
-        if (! isset($arguments[1])) {
319
+        if (!isset($arguments[1])) {
320 320
             throw new Exception(
321 321
                 'You must specify an expiration time when setting a value in the cache.'
322 322
             );
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
     }
327 327
 }
328 328
 
329
-if (! function_exists('wpb_config_path')) {
329
+if (!function_exists('wpb_config_path')) {
330 330
     /**
331 331
      * Get the configuration path.
332 332
      *
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
     }
340 340
 }
341 341
 
342
-if (! function_exists('wpb_cookie')) {
342
+if (!function_exists('wpb_cookie')) {
343 343
     /**
344 344
      * Create a new cookie instance.
345 345
      *
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
     }
367 367
 }
368 368
 
369
-if (! function_exists('wpb_csrf_field')) {
369
+if (!function_exists('wpb_csrf_field')) {
370 370
     /**
371 371
      * Generate a CSRF token form field.
372 372
      *
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
     }
379 379
 }
380 380
 
381
-if (! function_exists('wpb_database_path')) {
381
+if (!function_exists('wpb_database_path')) {
382 382
     /**
383 383
      * Get the database path.
384 384
      *
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
     }
392 392
 }
393 393
 
394
-if (! function_exists('wpb_decrypt')) {
394
+if (!function_exists('wpb_decrypt')) {
395 395
     /**
396 396
      * Decrypt the given value.
397 397
      *
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
     }
406 406
 }
407 407
 
408
-if (! function_exists('wpb_dispatch')) {
408
+if (!function_exists('wpb_dispatch')) {
409 409
     /**
410 410
      * Dispatch a job to its appropriate handler.
411 411
      *
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
     }
419 419
 }
420 420
 
421
-if (! function_exists('wpb_dispatch_now')) {
421
+if (!function_exists('wpb_dispatch_now')) {
422 422
     /**
423 423
      * Dispatch a command to its appropriate handler in the current process.
424 424
      *
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
     }
433 433
 }
434 434
 
435
-if (! function_exists('wpb_elixir')) {
435
+if (!function_exists('wpb_elixir')) {
436 436
     /**
437 437
      * Get the path to a versioned Elixir file.
438 438
      *
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
     }
473 473
 }
474 474
 
475
-if (! function_exists('wpb_encrypt')) {
475
+if (!function_exists('wpb_encrypt')) {
476 476
     /**
477 477
      * Encrypt the given value.
478 478
      *
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
     }
487 487
 }
488 488
 
489
-if (! function_exists('wpb_event')) {
489
+if (!function_exists('wpb_event')) {
490 490
     /**
491 491
      * Dispatch an event and call the listeners.
492 492
      *
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
     }
502 502
 }
503 503
 
504
-if (! function_exists('wpb_factory')) {
504
+if (!function_exists('wpb_factory')) {
505 505
     /**
506 506
      * Create a model factory builder for a given class, name, and amount.
507 507
      *
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
     }
525 525
 }
526 526
 
527
-if (! function_exists('wpb_info')) {
527
+if (!function_exists('wpb_info')) {
528 528
     /**
529 529
      * Write some information to the log.
530 530
      *
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
     }
539 539
 }
540 540
 
541
-if (! function_exists('wpb_logger')) {
541
+if (!function_exists('wpb_logger')) {
542 542
     /**
543 543
      * Log a debug message to the logs.
544 544
      *
@@ -556,7 +556,7 @@  discard block
 block discarded – undo
556 556
     }
557 557
 }
558 558
 
559
-if (! function_exists('wpb_logs')) {
559
+if (!function_exists('wpb_logs')) {
560 560
     /**
561 561
      * Get a log driver instance.
562 562
      *
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
     }
570 570
 }
571 571
 
572
-if (! function_exists('wpb_method_field')) {
572
+if (!function_exists('wpb_method_field')) {
573 573
     /**
574 574
      * Generate a form field to spoof the HTTP verb used by forms.
575 575
      *
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
     }
583 583
 }
584 584
 
585
-if (! function_exists('wpb_mix')) {
585
+if (!function_exists('wpb_mix')) {
586 586
     /**
587 587
      * Get the path to a versioned Mix file.
588 588
      *
@@ -596,11 +596,11 @@  discard block
 block discarded – undo
596 596
     {
597 597
         static $manifests = [];
598 598
 
599
-        if (! Str::startsWith($path, '/')) {
599
+        if (!Str::startsWith($path, '/')) {
600 600
             $path = "/{$path}";
601 601
         }
602 602
 
603
-        if ($manifestDirectory && ! Str::startsWith($manifestDirectory, '/')) {
603
+        if ($manifestDirectory && !Str::startsWith($manifestDirectory, '/')) {
604 604
             $manifestDirectory = "/{$manifestDirectory}";
605 605
         }
606 606
 
@@ -616,8 +616,8 @@  discard block
 block discarded – undo
616 616
 
617 617
         $manifestPath = wpb_public_path($manifestDirectory.'/mix-manifest.json');
618 618
 
619
-        if (! isset($manifests[$manifestPath])) {
620
-            if (! file_exists($manifestPath)) {
619
+        if (!isset($manifests[$manifestPath])) {
620
+            if (!file_exists($manifestPath)) {
621 621
                 throw new Exception('The Mix manifest does not exist.');
622 622
             }
623 623
 
@@ -626,10 +626,10 @@  discard block
 block discarded – undo
626 626
 
627 627
         $manifest = $manifests[$manifestPath];
628 628
 
629
-        if (! isset($manifest[$path])) {
629
+        if (!isset($manifest[$path])) {
630 630
             wpb_report(new Exception("Unable to locate Mix file: {$path}."));
631 631
 
632
-            if (! wpb_app('config')->get('app.debug')) {
632
+            if (!wpb_app('config')->get('app.debug')) {
633 633
                 return $path;
634 634
             }
635 635
         }
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
     }
639 639
 }
640 640
 
641
-if (! function_exists('wpb_now')) {
641
+if (!function_exists('wpb_now')) {
642 642
     /**
643 643
      * Create a new Carbon instance for the current time.
644 644
      *
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
     }
652 652
 }
653 653
 
654
-if (! function_exists('wpb_old')) {
654
+if (!function_exists('wpb_old')) {
655 655
     /**
656 656
      * Retrieve an old input item.
657 657
      *
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
     }
666 666
 }
667 667
 
668
-if (! function_exists('wpb_policy')) {
668
+if (!function_exists('wpb_policy')) {
669 669
     /**
670 670
      * Get a policy instance for a given class.
671 671
      *
@@ -680,7 +680,7 @@  discard block
 block discarded – undo
680 680
     }
681 681
 }
682 682
 
683
-if (! function_exists('wpb_public_path')) {
683
+if (!function_exists('wpb_public_path')) {
684 684
     /**
685 685
      * Get the path to the public folder.
686 686
      *
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
     }
694 694
 }
695 695
 
696
-if (! function_exists('wpb_redirect')) {
696
+if (!function_exists('wpb_redirect')) {
697 697
     /**
698 698
      * Get an instance of the redirector.
699 699
      *
@@ -713,7 +713,7 @@  discard block
 block discarded – undo
713 713
     }
714 714
 }
715 715
 
716
-if (! function_exists('wpb_report')) {
716
+if (!function_exists('wpb_report')) {
717 717
     /**
718 718
      * Report an exception.
719 719
      *
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
     function wpb_report($exception)
724 724
     {
725 725
         if ($exception instanceof Throwable &&
726
-            ! $exception instanceof Exception) {
726
+            !$exception instanceof Exception) {
727 727
             $exception = new FatalThrowableError($exception);
728 728
         }
729 729
 
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
     }
732 732
 }
733 733
 
734
-if (! function_exists('wpb_request')) {
734
+if (!function_exists('wpb_request')) {
735 735
     /**
736 736
      * Get an instance of the current request or an input item from the request.
737 737
      *
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
     }
756 756
 }
757 757
 
758
-if (! function_exists('wpb_rescue')) {
758
+if (!function_exists('wpb_rescue')) {
759 759
     /**
760 760
      * Catch a potential exception and return a default value.
761 761
      *
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
     }
776 776
 }
777 777
 
778
-if (! function_exists('wpb_resolve')) {
778
+if (!function_exists('wpb_resolve')) {
779 779
     /**
780 780
      * Resolve a service from the container.
781 781
      *
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
     }
789 789
 }
790 790
 
791
-if (! function_exists('wpb_resource_path')) {
791
+if (!function_exists('wpb_resource_path')) {
792 792
     /**
793 793
      * Get the path to the resources folder.
794 794
      *
@@ -801,7 +801,7 @@  discard block
 block discarded – undo
801 801
     }
802 802
 }
803 803
 
804
-if (! function_exists('wpb_response')) {
804
+if (!function_exists('wpb_response')) {
805 805
     /**
806 806
      * Return a new response from the application.
807 807
      *
@@ -822,7 +822,7 @@  discard block
 block discarded – undo
822 822
     }
823 823
 }
824 824
 
825
-if (! function_exists('wpb_route')) {
825
+if (!function_exists('wpb_route')) {
826 826
     /**
827 827
      * Generate the URL to a named route.
828 828
      *
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
     }
838 838
 }
839 839
 
840
-if (! function_exists('wpb_secure_asset')) {
840
+if (!function_exists('wpb_secure_asset')) {
841 841
     /**
842 842
      * Generate an asset path for the application.
843 843
      *
@@ -850,7 +850,7 @@  discard block
 block discarded – undo
850 850
     }
851 851
 }
852 852
 
853
-if (! function_exists('wpb_secure_url')) {
853
+if (!function_exists('wpb_secure_url')) {
854 854
     /**
855 855
      * Generate a HTTPS url for the application.
856 856
      *
@@ -864,7 +864,7 @@  discard block
 block discarded – undo
864 864
     }
865 865
 }
866 866
 
867
-if (! function_exists('wpb_session')) {
867
+if (!function_exists('wpb_session')) {
868 868
     /**
869 869
      * Get / set the specified session value.
870 870
      *
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
     }
889 889
 }
890 890
 
891
-if (! function_exists('wpb_storage_path')) {
891
+if (!function_exists('wpb_storage_path')) {
892 892
     /**
893 893
      * Get the path to the storage folder.
894 894
      *
@@ -901,7 +901,7 @@  discard block
 block discarded – undo
901 901
     }
902 902
 }
903 903
 
904
-if (! function_exists('wpb_today')) {
904
+if (!function_exists('wpb_today')) {
905 905
     /**
906 906
      * Create a new Carbon instance for the current date.
907 907
      *
@@ -914,7 +914,7 @@  discard block
 block discarded – undo
914 914
     }
915 915
 }
916 916
 
917
-if (! function_exists('wpb_trans')) {
917
+if (!function_exists('wpb_trans')) {
918 918
     /**
919 919
      * Translate the given message.
920 920
      *
@@ -933,7 +933,7 @@  discard block
 block discarded – undo
933 933
     }
934 934
 }
935 935
 
936
-if (! function_exists('wpb_trans_choice')) {
936
+if (!function_exists('wpb_trans_choice')) {
937 937
     /**
938 938
      * Translates the given message based on a count.
939 939
      *
@@ -949,7 +949,7 @@  discard block
 block discarded – undo
949 949
     }
950 950
 }
951 951
 
952
-if (! function_exists('__')) {
952
+if (!function_exists('__')) {
953 953
     /**
954 954
      * Translate the given message.
955 955
      *
@@ -964,7 +964,7 @@  discard block
 block discarded – undo
964 964
     }
965 965
 }
966 966
 
967
-if (! function_exists('wpb_url')) {
967
+if (!function_exists('wpb_url')) {
968 968
     /**
969 969
      * Generate a url for the application.
970 970
      *
@@ -983,7 +983,7 @@  discard block
 block discarded – undo
983 983
     }
984 984
 }
985 985
 
986
-if (! function_exists('wpb_validator')) {
986
+if (!function_exists('wpb_validator')) {
987 987
     /**
988 988
      * Create a new Validator instance.
989 989
      *
Please login to merge, or discard this patch.