@@ -24,108 +24,108 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class Post extends Model { |
| 26 | 26 | |
| 27 | - protected $primaryKey = 'ID'; |
|
| 27 | + protected $primaryKey = 'ID'; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * The post type scope. |
|
| 31 | - * |
|
| 32 | - * @since 1.0.0 |
|
| 33 | - * @access protected |
|
| 34 | - * @var string $plugin_name The post type scope. |
|
| 35 | - */ |
|
| 36 | - protected static $type_scope = 'post'; |
|
| 29 | + /** |
|
| 30 | + * The post type scope. |
|
| 31 | + * |
|
| 32 | + * @since 1.0.0 |
|
| 33 | + * @access protected |
|
| 34 | + * @var string $plugin_name The post type scope. |
|
| 35 | + */ |
|
| 36 | + protected static $type_scope = 'post'; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * The post status scope. |
|
| 40 | - * |
|
| 41 | - * @since 1.0.0 |
|
| 42 | - * @access protected |
|
| 43 | - * @var string $status_scope The post status scope. |
|
| 44 | - */ |
|
| 45 | - protected static $status_scope = 'publish'; |
|
| 38 | + /** |
|
| 39 | + * The post status scope. |
|
| 40 | + * |
|
| 41 | + * @since 1.0.0 |
|
| 42 | + * @access protected |
|
| 43 | + * @var string $status_scope The post status scope. |
|
| 44 | + */ |
|
| 45 | + protected static $status_scope = 'publish'; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * The unique identifier of this plugin. |
|
| 49 | - * |
|
| 50 | - * @since 1.0.0 |
|
| 51 | - * @access protected |
|
| 52 | - * @var string $author_scope The author scope.. |
|
| 53 | - */ |
|
| 54 | - protected static $author_scope = null; |
|
| 47 | + /** |
|
| 48 | + * The unique identifier of this plugin. |
|
| 49 | + * |
|
| 50 | + * @since 1.0.0 |
|
| 51 | + * @access protected |
|
| 52 | + * @var string $author_scope The author scope.. |
|
| 53 | + */ |
|
| 54 | + protected static $author_scope = null; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * The constant used to modify default created at fields. |
|
| 58 | - * |
|
| 59 | - * @since 1.0.0 |
|
| 60 | - * @access protected |
|
| 61 | - * @var string CREATED_AT The constant used to modify default created at fields. |
|
| 62 | - */ |
|
| 63 | - const CREATED_AT = 'post_date'; |
|
| 56 | + /** |
|
| 57 | + * The constant used to modify default created at fields. |
|
| 58 | + * |
|
| 59 | + * @since 1.0.0 |
|
| 60 | + * @access protected |
|
| 61 | + * @var string CREATED_AT The constant used to modify default created at fields. |
|
| 62 | + */ |
|
| 63 | + const CREATED_AT = 'post_date'; |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * The constant used to modify default updated at fields. |
|
| 67 | - * |
|
| 68 | - * @since 1.0.0 |
|
| 69 | - * @access protected |
|
| 70 | - * @var string UPDATED_AT The constant used to modify default updated at fields. |
|
| 71 | - */ |
|
| 72 | - const UPDATED_AT = 'post_modified'; |
|
| 65 | + /** |
|
| 66 | + * The constant used to modify default updated at fields. |
|
| 67 | + * |
|
| 68 | + * @since 1.0.0 |
|
| 69 | + * @access protected |
|
| 70 | + * @var string UPDATED_AT The constant used to modify default updated at fields. |
|
| 71 | + */ |
|
| 72 | + const UPDATED_AT = 'post_modified'; |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Boot the model. |
|
| 76 | - * |
|
| 77 | - * @since 1.0.0 |
|
| 78 | - * @access protected |
|
| 79 | - * |
|
| 80 | - * @return void |
|
| 81 | - */ |
|
| 82 | - protected static function boot() { |
|
| 83 | - parent::boot(); |
|
| 84 | - static::addGlobalScope( |
|
| 85 | - 'type', |
|
| 86 | - function ( Builder $builder ) { |
|
| 87 | - $builder->where( 'post_type', '=', static::$type_scope ); |
|
| 88 | - } |
|
| 89 | - ); |
|
| 74 | + /** |
|
| 75 | + * Boot the model. |
|
| 76 | + * |
|
| 77 | + * @since 1.0.0 |
|
| 78 | + * @access protected |
|
| 79 | + * |
|
| 80 | + * @return void |
|
| 81 | + */ |
|
| 82 | + protected static function boot() { |
|
| 83 | + parent::boot(); |
|
| 84 | + static::addGlobalScope( |
|
| 85 | + 'type', |
|
| 86 | + function ( Builder $builder ) { |
|
| 87 | + $builder->where( 'post_type', '=', static::$type_scope ); |
|
| 88 | + } |
|
| 89 | + ); |
|
| 90 | 90 | |
| 91 | - } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Filter by post type. |
|
| 95 | - * |
|
| 96 | - * @param \Illuminate\Database\Eloquent\Builder $builder The eloquent builder. |
|
| 97 | - * @param string $type The post type scope. |
|
| 98 | - * |
|
| 99 | - * @return mixed |
|
| 100 | - */ |
|
| 101 | - public function scopeType( Builder $builder, $type ) { |
|
| 102 | - self::$type_scope = $type; |
|
| 103 | - return $builder->where( 'post_type', '=', $type ); |
|
| 104 | - } |
|
| 93 | + /** |
|
| 94 | + * Filter by post type. |
|
| 95 | + * |
|
| 96 | + * @param \Illuminate\Database\Eloquent\Builder $builder The eloquent builder. |
|
| 97 | + * @param string $type The post type scope. |
|
| 98 | + * |
|
| 99 | + * @return mixed |
|
| 100 | + */ |
|
| 101 | + public function scopeType( Builder $builder, $type ) { |
|
| 102 | + self::$type_scope = $type; |
|
| 103 | + return $builder->where( 'post_type', '=', $type ); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Filter by post status |
|
| 108 | - * |
|
| 109 | - * @param \Illuminate\Database\Eloquent\Builder $builder The eloquent builder. |
|
| 110 | - * @param string $status The post status scope. |
|
| 111 | - * |
|
| 112 | - * @return mixed |
|
| 113 | - */ |
|
| 114 | - public function scopeStatus( Builder $builder, $status ) { |
|
| 115 | - return $builder->where( 'post_status', '=', $status ); |
|
| 116 | - } |
|
| 106 | + /** |
|
| 107 | + * Filter by post status |
|
| 108 | + * |
|
| 109 | + * @param \Illuminate\Database\Eloquent\Builder $builder The eloquent builder. |
|
| 110 | + * @param string $status The post status scope. |
|
| 111 | + * |
|
| 112 | + * @return mixed |
|
| 113 | + */ |
|
| 114 | + public function scopeStatus( Builder $builder, $status ) { |
|
| 115 | + return $builder->where( 'post_status', '=', $status ); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * Filter by post author |
|
| 120 | - * |
|
| 121 | - * @param \Illuminate\Database\Eloquent\Builder $builder The eloquent builder. |
|
| 122 | - * @param string|null $author The post status scope. |
|
| 123 | - * |
|
| 124 | - * @return mixed |
|
| 125 | - */ |
|
| 126 | - public function scopeAuthor( Builder $builder, $author ) { |
|
| 127 | - if ( $author ) { |
|
| 128 | - return $builder->where( 'post_author', '=', $author ); |
|
| 129 | - } |
|
| 130 | - } |
|
| 118 | + /** |
|
| 119 | + * Filter by post author |
|
| 120 | + * |
|
| 121 | + * @param \Illuminate\Database\Eloquent\Builder $builder The eloquent builder. |
|
| 122 | + * @param string|null $author The post status scope. |
|
| 123 | + * |
|
| 124 | + * @return mixed |
|
| 125 | + */ |
|
| 126 | + public function scopeAuthor( Builder $builder, $author ) { |
|
| 127 | + if ( $author ) { |
|
| 128 | + return $builder->where( 'post_author', '=', $author ); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | 131 | } |
@@ -83,8 +83,8 @@ discard block |
||
| 83 | 83 | parent::boot(); |
| 84 | 84 | static::addGlobalScope( |
| 85 | 85 | 'type', |
| 86 | - function ( Builder $builder ) { |
|
| 87 | - $builder->where( 'post_type', '=', static::$type_scope ); |
|
| 86 | + function(Builder $builder) { |
|
| 87 | + $builder->where('post_type', '=', static::$type_scope); |
|
| 88 | 88 | } |
| 89 | 89 | ); |
| 90 | 90 | |
@@ -98,9 +98,9 @@ discard block |
||
| 98 | 98 | * |
| 99 | 99 | * @return mixed |
| 100 | 100 | */ |
| 101 | - public function scopeType( Builder $builder, $type ) { |
|
| 101 | + public function scopeType(Builder $builder, $type) { |
|
| 102 | 102 | self::$type_scope = $type; |
| 103 | - return $builder->where( 'post_type', '=', $type ); |
|
| 103 | + return $builder->where('post_type', '=', $type); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -111,8 +111,8 @@ discard block |
||
| 111 | 111 | * |
| 112 | 112 | * @return mixed |
| 113 | 113 | */ |
| 114 | - public function scopeStatus( Builder $builder, $status ) { |
|
| 115 | - return $builder->where( 'post_status', '=', $status ); |
|
| 114 | + public function scopeStatus(Builder $builder, $status) { |
|
| 115 | + return $builder->where('post_status', '=', $status); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -123,9 +123,9 @@ discard block |
||
| 123 | 123 | * |
| 124 | 124 | * @return mixed |
| 125 | 125 | */ |
| 126 | - public function scopeAuthor( Builder $builder, $author ) { |
|
| 127 | - if ( $author ) { |
|
| 128 | - return $builder->where( 'post_author', '=', $author ); |
|
| 126 | + public function scopeAuthor(Builder $builder, $author) { |
|
| 127 | + if ($author) { |
|
| 128 | + return $builder->where('post_author', '=', $author); |
|
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | } |
@@ -29,65 +29,65 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class AuthMiddleware { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Handle an incoming request. |
|
| 34 | - * |
|
| 35 | - * @param \Illuminate\Http\Request $request The app http request. |
|
| 36 | - * @param \Closure $next The next closure. |
|
| 37 | - * @param array ...$guards The requested guards. |
|
| 38 | - * |
|
| 39 | - * @throws \Exception Throw the exception. |
|
| 40 | - * |
|
| 41 | - * @return mixed |
|
| 42 | - */ |
|
| 43 | - public function handle( Request $request, Closure $next, ...$guards ) { |
|
| 44 | - foreach ( $guards as $guard ) { |
|
| 45 | - if ( $guard == 'api' ) { |
|
| 46 | - if ( ! Schema::hasTable( 'oauth_access_tokens' ) || |
|
| 47 | - ! Schema::hasTable( 'oauth_refresh_tokens' ) || |
|
| 48 | - ! Schema::hasTable( 'oauth_personal_access_clients' ) || |
|
| 49 | - ! Schema::hasTable( 'oauth_clients' ) || |
|
| 50 | - ! Schema::hasTable( 'oauth_auth_codes' ) |
|
| 51 | - ) { |
|
| 52 | - throw new \Exception( 'Please install OAuth2 Server Plugin (plugin link) or Implement OAuth2 Server from this link (https://github.com/Codexshaper/oauth2)', 1 ); |
|
| 53 | - } |
|
| 32 | + /** |
|
| 33 | + * Handle an incoming request. |
|
| 34 | + * |
|
| 35 | + * @param \Illuminate\Http\Request $request The app http request. |
|
| 36 | + * @param \Closure $next The next closure. |
|
| 37 | + * @param array ...$guards The requested guards. |
|
| 38 | + * |
|
| 39 | + * @throws \Exception Throw the exception. |
|
| 40 | + * |
|
| 41 | + * @return mixed |
|
| 42 | + */ |
|
| 43 | + public function handle( Request $request, Closure $next, ...$guards ) { |
|
| 44 | + foreach ( $guards as $guard ) { |
|
| 45 | + if ( $guard == 'api' ) { |
|
| 46 | + if ( ! Schema::hasTable( 'oauth_access_tokens' ) || |
|
| 47 | + ! Schema::hasTable( 'oauth_refresh_tokens' ) || |
|
| 48 | + ! Schema::hasTable( 'oauth_personal_access_clients' ) || |
|
| 49 | + ! Schema::hasTable( 'oauth_clients' ) || |
|
| 50 | + ! Schema::hasTable( 'oauth_auth_codes' ) |
|
| 51 | + ) { |
|
| 52 | + throw new \Exception( 'Please install OAuth2 Server Plugin (plugin link) or Implement OAuth2 Server from this link (https://github.com/Codexshaper/oauth2)', 1 ); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - $manager = new Manager(); |
|
| 56 | - $resource_server = $manager->getResourceServer(); |
|
| 57 | - $psr_request = ServerRequest::getPsrServerRequest(); |
|
| 55 | + $manager = new Manager(); |
|
| 56 | + $resource_server = $manager->getResourceServer(); |
|
| 57 | + $psr_request = ServerRequest::getPsrServerRequest(); |
|
| 58 | 58 | |
| 59 | - try { |
|
| 60 | - $psr = $resource_server->validateAuthenticatedRequest( $psr_request ); |
|
| 61 | - $user_id = $manager->validateUserForRequest( $psr ); |
|
| 59 | + try { |
|
| 60 | + $psr = $resource_server->validateAuthenticatedRequest( $psr_request ); |
|
| 61 | + $user_id = $manager->validateUserForRequest( $psr ); |
|
| 62 | 62 | |
| 63 | - if ( $user_id ) { |
|
| 64 | - $user = User::find( $user_id ); |
|
| 63 | + if ( $user_id ) { |
|
| 64 | + $user = User::find( $user_id ); |
|
| 65 | 65 | |
| 66 | - $request->merge( array( 'user' => $user ) ); |
|
| 67 | - $request->merge( array( 'scopes' => $psr->getAttribute( 'oauth_scopes' ) ) ); |
|
| 66 | + $request->merge( array( 'user' => $user ) ); |
|
| 67 | + $request->merge( array( 'scopes' => $psr->getAttribute( 'oauth_scopes' ) ) ); |
|
| 68 | 68 | |
| 69 | - $request->setUserResolver( |
|
| 70 | - function () use ( $user ) { |
|
| 71 | - return $user; |
|
| 72 | - } |
|
| 73 | - ); |
|
| 69 | + $request->setUserResolver( |
|
| 70 | + function () use ( $user ) { |
|
| 71 | + return $user; |
|
| 72 | + } |
|
| 73 | + ); |
|
| 74 | 74 | |
| 75 | - return $next( $request ); |
|
| 76 | - } |
|
| 77 | - } catch ( OAuthServerException $e ) { |
|
| 78 | - throw new \Exception( $e->getMessage() ); |
|
| 75 | + return $next( $request ); |
|
| 76 | + } |
|
| 77 | + } catch ( OAuthServerException $e ) { |
|
| 78 | + throw new \Exception( $e->getMessage() ); |
|
| 79 | 79 | |
| 80 | - } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - return $next( $request ); |
|
| 83 | - } |
|
| 84 | - } |
|
| 82 | + return $next( $request ); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - if ( \is_user_logged_in() ) { |
|
| 87 | - return $next( $request ); |
|
| 88 | - } |
|
| 86 | + if ( \is_user_logged_in() ) { |
|
| 87 | + return $next( $request ); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - header( 'Location: ' . \get_site_url() . '/wp-admin' ); |
|
| 91 | - die(); |
|
| 92 | - } |
|
| 90 | + header( 'Location: ' . \get_site_url() . '/wp-admin' ); |
|
| 91 | + die(); |
|
| 92 | + } |
|
| 93 | 93 | } |
@@ -40,16 +40,16 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @return mixed |
| 42 | 42 | */ |
| 43 | - public function handle( Request $request, Closure $next, ...$guards ) { |
|
| 44 | - foreach ( $guards as $guard ) { |
|
| 45 | - if ( $guard == 'api' ) { |
|
| 46 | - if ( ! Schema::hasTable( 'oauth_access_tokens' ) || |
|
| 47 | - ! Schema::hasTable( 'oauth_refresh_tokens' ) || |
|
| 48 | - ! Schema::hasTable( 'oauth_personal_access_clients' ) || |
|
| 49 | - ! Schema::hasTable( 'oauth_clients' ) || |
|
| 50 | - ! Schema::hasTable( 'oauth_auth_codes' ) |
|
| 43 | + public function handle(Request $request, Closure $next, ...$guards) { |
|
| 44 | + foreach ($guards as $guard) { |
|
| 45 | + if ($guard == 'api') { |
|
| 46 | + if (!Schema::hasTable('oauth_access_tokens') || |
|
| 47 | + !Schema::hasTable('oauth_refresh_tokens') || |
|
| 48 | + !Schema::hasTable('oauth_personal_access_clients') || |
|
| 49 | + !Schema::hasTable('oauth_clients') || |
|
| 50 | + !Schema::hasTable('oauth_auth_codes') |
|
| 51 | 51 | ) { |
| 52 | - throw new \Exception( 'Please install OAuth2 Server Plugin (plugin link) or Implement OAuth2 Server from this link (https://github.com/Codexshaper/oauth2)', 1 ); |
|
| 52 | + throw new \Exception('Please install OAuth2 Server Plugin (plugin link) or Implement OAuth2 Server from this link (https://github.com/Codexshaper/oauth2)', 1); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | $manager = new Manager(); |
@@ -57,37 +57,37 @@ discard block |
||
| 57 | 57 | $psr_request = ServerRequest::getPsrServerRequest(); |
| 58 | 58 | |
| 59 | 59 | try { |
| 60 | - $psr = $resource_server->validateAuthenticatedRequest( $psr_request ); |
|
| 61 | - $user_id = $manager->validateUserForRequest( $psr ); |
|
| 60 | + $psr = $resource_server->validateAuthenticatedRequest($psr_request); |
|
| 61 | + $user_id = $manager->validateUserForRequest($psr); |
|
| 62 | 62 | |
| 63 | - if ( $user_id ) { |
|
| 64 | - $user = User::find( $user_id ); |
|
| 63 | + if ($user_id) { |
|
| 64 | + $user = User::find($user_id); |
|
| 65 | 65 | |
| 66 | - $request->merge( array( 'user' => $user ) ); |
|
| 67 | - $request->merge( array( 'scopes' => $psr->getAttribute( 'oauth_scopes' ) ) ); |
|
| 66 | + $request->merge(array('user' => $user)); |
|
| 67 | + $request->merge(array('scopes' => $psr->getAttribute('oauth_scopes'))); |
|
| 68 | 68 | |
| 69 | 69 | $request->setUserResolver( |
| 70 | - function () use ( $user ) { |
|
| 70 | + function() use ($user) { |
|
| 71 | 71 | return $user; |
| 72 | 72 | } |
| 73 | 73 | ); |
| 74 | 74 | |
| 75 | - return $next( $request ); |
|
| 75 | + return $next($request); |
|
| 76 | 76 | } |
| 77 | - } catch ( OAuthServerException $e ) { |
|
| 78 | - throw new \Exception( $e->getMessage() ); |
|
| 77 | + } catch (OAuthServerException $e) { |
|
| 78 | + throw new \Exception($e->getMessage()); |
|
| 79 | 79 | |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - return $next( $request ); |
|
| 82 | + return $next($request); |
|
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - if ( \is_user_logged_in() ) { |
|
| 87 | - return $next( $request ); |
|
| 86 | + if (\is_user_logged_in()) { |
|
| 87 | + return $next($request); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - header( 'Location: ' . \get_site_url() . '/wp-admin' ); |
|
| 90 | + header('Location: '.\get_site_url().'/wp-admin'); |
|
| 91 | 91 | die(); |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -24,29 +24,29 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class VerifyCsrfToken { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Handle an incoming request. |
|
| 29 | - * |
|
| 30 | - * @param \Illuminate\Http\Request $request The app http request. |
|
| 31 | - * @param \Closure $next The next closure. |
|
| 32 | - * |
|
| 33 | - * @throws \Exception Throw the exception. |
|
| 34 | - * |
|
| 35 | - * @return mixed |
|
| 36 | - */ |
|
| 37 | - public function handle( Request $request, Closure $next ) { |
|
| 38 | - $token = $request->input( '_token' ) ?? $request->header( 'X-CSRF-TOKEN' ); |
|
| 39 | - $action = $request->wpb_nonce ?? 'wpb_nonce'; |
|
| 40 | - |
|
| 41 | - if ( ! wp_verify_nonce( $token, $action ) ) { |
|
| 42 | - if ( $request->ajax() ) { |
|
| 43 | - return wp_send_json( array( 'message' => 'CSRF Token mitchmatch' ), 403 ); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - throw new \Exception( 'CSRF Token mismatch' ); |
|
| 47 | - |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - return $next( $request ); |
|
| 51 | - } |
|
| 27 | + /** |
|
| 28 | + * Handle an incoming request. |
|
| 29 | + * |
|
| 30 | + * @param \Illuminate\Http\Request $request The app http request. |
|
| 31 | + * @param \Closure $next The next closure. |
|
| 32 | + * |
|
| 33 | + * @throws \Exception Throw the exception. |
|
| 34 | + * |
|
| 35 | + * @return mixed |
|
| 36 | + */ |
|
| 37 | + public function handle( Request $request, Closure $next ) { |
|
| 38 | + $token = $request->input( '_token' ) ?? $request->header( 'X-CSRF-TOKEN' ); |
|
| 39 | + $action = $request->wpb_nonce ?? 'wpb_nonce'; |
|
| 40 | + |
|
| 41 | + if ( ! wp_verify_nonce( $token, $action ) ) { |
|
| 42 | + if ( $request->ajax() ) { |
|
| 43 | + return wp_send_json( array( 'message' => 'CSRF Token mitchmatch' ), 403 ); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + throw new \Exception( 'CSRF Token mismatch' ); |
|
| 47 | + |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + return $next( $request ); |
|
| 51 | + } |
|
| 52 | 52 | } |
@@ -34,19 +34,19 @@ |
||
| 34 | 34 | * |
| 35 | 35 | * @return mixed |
| 36 | 36 | */ |
| 37 | - public function handle( Request $request, Closure $next ) { |
|
| 38 | - $token = $request->input( '_token' ) ?? $request->header( 'X-CSRF-TOKEN' ); |
|
| 37 | + public function handle(Request $request, Closure $next) { |
|
| 38 | + $token = $request->input('_token') ?? $request->header('X-CSRF-TOKEN'); |
|
| 39 | 39 | $action = $request->wpb_nonce ?? 'wpb_nonce'; |
| 40 | 40 | |
| 41 | - if ( ! wp_verify_nonce( $token, $action ) ) { |
|
| 42 | - if ( $request->ajax() ) { |
|
| 43 | - return wp_send_json( array( 'message' => 'CSRF Token mitchmatch' ), 403 ); |
|
| 41 | + if (!wp_verify_nonce($token, $action)) { |
|
| 42 | + if ($request->ajax()) { |
|
| 43 | + return wp_send_json(array('message' => 'CSRF Token mitchmatch'), 403); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - throw new \Exception( 'CSRF Token mismatch' ); |
|
| 46 | + throw new \Exception('CSRF Token mismatch'); |
|
| 47 | 47 | |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - return $next( $request ); |
|
| 50 | + return $next($request); |
|
| 51 | 51 | } |
| 52 | 52 | } |
@@ -29,24 +29,24 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class Scope { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Handle an incoming request. |
|
| 34 | - * |
|
| 35 | - * @param \Illuminate\Http\Request $request The app http request. |
|
| 36 | - * @param \Closure $next The next closure. |
|
| 37 | - * @param array ...$scopes The requested guards. |
|
| 38 | - * |
|
| 39 | - * @throws \Exception Throw the exception. |
|
| 40 | - * |
|
| 41 | - * @return mixed |
|
| 42 | - */ |
|
| 43 | - public function handle( Request $request, Closure $next, ...$scopes ) { |
|
| 44 | - foreach ( $scopes as $scope ) { |
|
| 45 | - if ( ! in_array( $scope, $request->scopes ) ) { |
|
| 46 | - wp_send_json( array( 'msg' => "You don't have enough permission" ), 400 ); |
|
| 47 | - } |
|
| 48 | - } |
|
| 32 | + /** |
|
| 33 | + * Handle an incoming request. |
|
| 34 | + * |
|
| 35 | + * @param \Illuminate\Http\Request $request The app http request. |
|
| 36 | + * @param \Closure $next The next closure. |
|
| 37 | + * @param array ...$scopes The requested guards. |
|
| 38 | + * |
|
| 39 | + * @throws \Exception Throw the exception. |
|
| 40 | + * |
|
| 41 | + * @return mixed |
|
| 42 | + */ |
|
| 43 | + public function handle( Request $request, Closure $next, ...$scopes ) { |
|
| 44 | + foreach ( $scopes as $scope ) { |
|
| 45 | + if ( ! in_array( $scope, $request->scopes ) ) { |
|
| 46 | + wp_send_json( array( 'msg' => "You don't have enough permission" ), 400 ); |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return $next( $request ); |
|
| 51 | - } |
|
| 50 | + return $next( $request ); |
|
| 51 | + } |
|
| 52 | 52 | } |
@@ -40,13 +40,13 @@ |
||
| 40 | 40 | * |
| 41 | 41 | * @return mixed |
| 42 | 42 | */ |
| 43 | - public function handle( Request $request, Closure $next, ...$scopes ) { |
|
| 44 | - foreach ( $scopes as $scope ) { |
|
| 45 | - if ( ! in_array( $scope, $request->scopes ) ) { |
|
| 46 | - wp_send_json( array( 'msg' => "You don't have enough permission" ), 400 ); |
|
| 43 | + public function handle(Request $request, Closure $next, ...$scopes) { |
|
| 44 | + foreach ($scopes as $scope) { |
|
| 45 | + if (!in_array($scope, $request->scopes)) { |
|
| 46 | + wp_send_json(array('msg' => "You don't have enough permission"), 400); |
|
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - return $next( $request ); |
|
| 50 | + return $next($request); |
|
| 51 | 51 | } |
| 52 | 52 | } |
@@ -23,39 +23,39 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class Kernel extends HttpKernel { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * The application's global HTTP middleware stack. |
|
| 28 | - * |
|
| 29 | - * These middleware are run during every request to your application. |
|
| 30 | - * |
|
| 31 | - * @var array |
|
| 32 | - */ |
|
| 33 | - protected $middleware = array(); |
|
| 26 | + /** |
|
| 27 | + * The application's global HTTP middleware stack. |
|
| 28 | + * |
|
| 29 | + * These middleware are run during every request to your application. |
|
| 30 | + * |
|
| 31 | + * @var array |
|
| 32 | + */ |
|
| 33 | + protected $middleware = array(); |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * The application's route middleware groups. |
|
| 37 | - * |
|
| 38 | - * @var array |
|
| 39 | - */ |
|
| 40 | - protected $middleware_groups = array( |
|
| 41 | - 'web' => array( |
|
| 42 | - \WPB\App\Http\Middleware\VerifyCsrfToken::class, |
|
| 43 | - ), |
|
| 35 | + /** |
|
| 36 | + * The application's route middleware groups. |
|
| 37 | + * |
|
| 38 | + * @var array |
|
| 39 | + */ |
|
| 40 | + protected $middleware_groups = array( |
|
| 41 | + 'web' => array( |
|
| 42 | + \WPB\App\Http\Middleware\VerifyCsrfToken::class, |
|
| 43 | + ), |
|
| 44 | 44 | |
| 45 | - 'api' => array( |
|
| 46 | - 'throttle:60,1', |
|
| 47 | - ), |
|
| 48 | - ); |
|
| 45 | + 'api' => array( |
|
| 46 | + 'throttle:60,1', |
|
| 47 | + ), |
|
| 48 | + ); |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * The application's route middleware. |
|
| 52 | - * |
|
| 53 | - * These middleware may be assigned to groups or used individually. |
|
| 54 | - * |
|
| 55 | - * @var array |
|
| 56 | - */ |
|
| 57 | - protected $route_middleware = array( |
|
| 58 | - 'auth' => \WPB\App\Http\Middleware\AuthMiddleware::class, |
|
| 59 | - 'scope' => \WPB\App\Http\Middleware\Scope::class, |
|
| 60 | - ); |
|
| 50 | + /** |
|
| 51 | + * The application's route middleware. |
|
| 52 | + * |
|
| 53 | + * These middleware may be assigned to groups or used individually. |
|
| 54 | + * |
|
| 55 | + * @var array |
|
| 56 | + */ |
|
| 57 | + protected $route_middleware = array( |
|
| 58 | + 'auth' => \WPB\App\Http\Middleware\AuthMiddleware::class, |
|
| 59 | + 'scope' => \WPB\App\Http\Middleware\Scope::class, |
|
| 60 | + ); |
|
| 61 | 61 | } |
@@ -23,41 +23,41 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class User extends Model { |
| 25 | 25 | |
| 26 | - protected $primaryKey = 'ID'; |
|
| 26 | + protected $primaryKey = 'ID'; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * The fillable fields for mass assignment. |
|
| 30 | - * |
|
| 31 | - * @since 1.0.0 |
|
| 32 | - * @access protected |
|
| 33 | - * @var array $fillable The fillable fields. |
|
| 34 | - */ |
|
| 35 | - protected $fillable = array( |
|
| 36 | - 'name', |
|
| 37 | - 'email', |
|
| 38 | - 'password', |
|
| 39 | - ); |
|
| 28 | + /** |
|
| 29 | + * The fillable fields for mass assignment. |
|
| 30 | + * |
|
| 31 | + * @since 1.0.0 |
|
| 32 | + * @access protected |
|
| 33 | + * @var array $fillable The fillable fields. |
|
| 34 | + */ |
|
| 35 | + protected $fillable = array( |
|
| 36 | + 'name', |
|
| 37 | + 'email', |
|
| 38 | + 'password', |
|
| 39 | + ); |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * The hidden fields. |
|
| 43 | - * |
|
| 44 | - * @since 1.0.0 |
|
| 45 | - * @access protected |
|
| 46 | - * @var array $hidden The hidden fields. |
|
| 47 | - */ |
|
| 48 | - protected $hidden = array( |
|
| 49 | - 'password', |
|
| 50 | - 'remember_token', |
|
| 51 | - ); |
|
| 41 | + /** |
|
| 42 | + * The hidden fields. |
|
| 43 | + * |
|
| 44 | + * @since 1.0.0 |
|
| 45 | + * @access protected |
|
| 46 | + * @var array $hidden The hidden fields. |
|
| 47 | + */ |
|
| 48 | + protected $hidden = array( |
|
| 49 | + 'password', |
|
| 50 | + 'remember_token', |
|
| 51 | + ); |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * The field cast. |
|
| 55 | - * |
|
| 56 | - * @since 1.0.0 |
|
| 57 | - * @access protected |
|
| 58 | - * @var array $casts The field cast. |
|
| 59 | - */ |
|
| 60 | - protected $casts = array( |
|
| 61 | - 'email_verified_at' => 'datetime', |
|
| 62 | - ); |
|
| 53 | + /** |
|
| 54 | + * The field cast. |
|
| 55 | + * |
|
| 56 | + * @since 1.0.0 |
|
| 57 | + * @access protected |
|
| 58 | + * @var array $casts The field cast. |
|
| 59 | + */ |
|
| 60 | + protected $casts = array( |
|
| 61 | + 'email_verified_at' => 'datetime', |
|
| 62 | + ); |
|
| 63 | 63 | } |
@@ -9,43 +9,43 @@ |
||
| 9 | 9 | * @subpackage WPB/app/Commands |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * Register all actions and filters for the plugin. |
|
| 14 | - * |
|
| 15 | - * Maintain a list of all hooks that are registered throughout |
|
| 16 | - * the plugin, and register them with the WordPress API. Call the |
|
| 17 | - * run function to execute the list of actions and filters. |
|
| 18 | - * |
|
| 19 | - * @package WPB |
|
| 20 | - * @subpackage WPB/app/Commands |
|
| 21 | - * @author Md Abu Ahsan basir <[email protected]> |
|
| 22 | - */ |
|
| 12 | + /** |
|
| 13 | + * Register all actions and filters for the plugin. |
|
| 14 | + * |
|
| 15 | + * Maintain a list of all hooks that are registered throughout |
|
| 16 | + * the plugin, and register them with the WordPress API. Call the |
|
| 17 | + * run function to execute the list of actions and filters. |
|
| 18 | + * |
|
| 19 | + * @package WPB |
|
| 20 | + * @subpackage WPB/app/Commands |
|
| 21 | + * @author Md Abu Ahsan basir <[email protected]> |
|
| 22 | + */ |
|
| 23 | 23 | class InstallComposer { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Install composer factory. |
|
| 27 | - * |
|
| 28 | - * @since 1.0.0 |
|
| 29 | - */ |
|
| 30 | - public function __construct() { |
|
| 31 | - if ( ! file_exists( __DIR__ . '/../vendor/autoload.php' ) ) { |
|
| 25 | + /** |
|
| 26 | + * Install composer factory. |
|
| 27 | + * |
|
| 28 | + * @since 1.0.0 |
|
| 29 | + */ |
|
| 30 | + public function __construct() { |
|
| 31 | + if ( ! file_exists( __DIR__ . '/../vendor/autoload.php' ) ) { |
|
| 32 | 32 | |
| 33 | - require_once __DIR__ . '/../vendor/autoload.php'; |
|
| 33 | + require_once __DIR__ . '/../vendor/autoload.php'; |
|
| 34 | 34 | |
| 35 | - $composer = 'composer'; |
|
| 35 | + $composer = 'composer'; |
|
| 36 | 36 | |
| 37 | - try { |
|
| 38 | - $process = \Symfony\Component\Process\Process::fromShellCommandline( $composer . ' install' ); |
|
| 39 | - $process->setEnv( |
|
| 40 | - array( |
|
| 41 | - 'COMPOSER_HOME' => __DIR__ . '/../vendor/bin/composer', |
|
| 42 | - ) |
|
| 43 | - ); |
|
| 44 | - $process->setTimeout( null ); // Setting timeout to null to prevent installation from stopping at a certain point in time. |
|
| 45 | - $process->setWorkingDirectory( __DIR__ )->mustRun(); |
|
| 46 | - } catch ( \Exception $ex ) { |
|
| 47 | - echo $ex->getMessage(); |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - } |
|
| 37 | + try { |
|
| 38 | + $process = \Symfony\Component\Process\Process::fromShellCommandline( $composer . ' install' ); |
|
| 39 | + $process->setEnv( |
|
| 40 | + array( |
|
| 41 | + 'COMPOSER_HOME' => __DIR__ . '/../vendor/bin/composer', |
|
| 42 | + ) |
|
| 43 | + ); |
|
| 44 | + $process->setTimeout( null ); // Setting timeout to null to prevent installation from stopping at a certain point in time. |
|
| 45 | + $process->setWorkingDirectory( __DIR__ )->mustRun(); |
|
| 46 | + } catch ( \Exception $ex ) { |
|
| 47 | + echo $ex->getMessage(); |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -28,22 +28,22 @@ |
||
| 28 | 28 | * @since 1.0.0 |
| 29 | 29 | */ |
| 30 | 30 | public function __construct() { |
| 31 | - if ( ! file_exists( __DIR__ . '/../vendor/autoload.php' ) ) { |
|
| 31 | + if (!file_exists(__DIR__.'/../vendor/autoload.php')) { |
|
| 32 | 32 | |
| 33 | - require_once __DIR__ . '/../vendor/autoload.php'; |
|
| 33 | + require_once __DIR__.'/../vendor/autoload.php'; |
|
| 34 | 34 | |
| 35 | 35 | $composer = 'composer'; |
| 36 | 36 | |
| 37 | 37 | try { |
| 38 | - $process = \Symfony\Component\Process\Process::fromShellCommandline( $composer . ' install' ); |
|
| 38 | + $process = \Symfony\Component\Process\Process::fromShellCommandline($composer.' install'); |
|
| 39 | 39 | $process->setEnv( |
| 40 | 40 | array( |
| 41 | - 'COMPOSER_HOME' => __DIR__ . '/../vendor/bin/composer', |
|
| 41 | + 'COMPOSER_HOME' => __DIR__.'/../vendor/bin/composer', |
|
| 42 | 42 | ) |
| 43 | 43 | ); |
| 44 | - $process->setTimeout( null ); // Setting timeout to null to prevent installation from stopping at a certain point in time. |
|
| 45 | - $process->setWorkingDirectory( __DIR__ )->mustRun(); |
|
| 46 | - } catch ( \Exception $ex ) { |
|
| 44 | + $process->setTimeout(null); // Setting timeout to null to prevent installation from stopping at a certain point in time. |
|
| 45 | + $process->setWorkingDirectory(__DIR__)->mustRun(); |
|
| 46 | + } catch (\Exception $ex) { |
|
| 47 | 47 | echo $ex->getMessage(); |
| 48 | 48 | } |
| 49 | 49 | } |
@@ -24,45 +24,45 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class Handler extends ExceptionHandler { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * A list of the exception types that are not reported. |
|
| 29 | - * |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $dont_report = array(); |
|
| 27 | + /** |
|
| 28 | + * A list of the exception types that are not reported. |
|
| 29 | + * |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $dont_report = array(); |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * A list of the inputs that are never flashed for validation exceptions. |
|
| 36 | - * |
|
| 37 | - * @var array |
|
| 38 | - */ |
|
| 39 | - protected $dont_flash = array( |
|
| 40 | - 'password', |
|
| 41 | - 'password_confirmation', |
|
| 42 | - ); |
|
| 34 | + /** |
|
| 35 | + * A list of the inputs that are never flashed for validation exceptions. |
|
| 36 | + * |
|
| 37 | + * @var array |
|
| 38 | + */ |
|
| 39 | + protected $dont_flash = array( |
|
| 40 | + 'password', |
|
| 41 | + 'password_confirmation', |
|
| 42 | + ); |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Report or log an exception. |
|
| 46 | - * |
|
| 47 | - * @param \Throwable $exception The throwable exception. |
|
| 48 | - * @return void |
|
| 49 | - * |
|
| 50 | - * @throws \Exception Throw the exception. |
|
| 51 | - */ |
|
| 52 | - public function report( Throwable $exception ) { |
|
| 53 | - parent::report( $exception ); |
|
| 54 | - } |
|
| 44 | + /** |
|
| 45 | + * Report or log an exception. |
|
| 46 | + * |
|
| 47 | + * @param \Throwable $exception The throwable exception. |
|
| 48 | + * @return void |
|
| 49 | + * |
|
| 50 | + * @throws \Exception Throw the exception. |
|
| 51 | + */ |
|
| 52 | + public function report( Throwable $exception ) { |
|
| 53 | + parent::report( $exception ); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Render an exception into an HTTP response. |
|
| 58 | - * |
|
| 59 | - * @param \Illuminate\Http\Request $request The app http request. |
|
| 60 | - * @param \Throwable $exception The throwable exception. |
|
| 61 | - * @return \Symfony\Component\HttpFoundation\Response |
|
| 62 | - * |
|
| 63 | - * @throws \Throwable Throw the nexception. |
|
| 64 | - */ |
|
| 65 | - public function render( $request, Throwable $exception ) { |
|
| 66 | - return parent::render( $request, $exception ); |
|
| 67 | - } |
|
| 56 | + /** |
|
| 57 | + * Render an exception into an HTTP response. |
|
| 58 | + * |
|
| 59 | + * @param \Illuminate\Http\Request $request The app http request. |
|
| 60 | + * @param \Throwable $exception The throwable exception. |
|
| 61 | + * @return \Symfony\Component\HttpFoundation\Response |
|
| 62 | + * |
|
| 63 | + * @throws \Throwable Throw the nexception. |
|
| 64 | + */ |
|
| 65 | + public function render( $request, Throwable $exception ) { |
|
| 66 | + return parent::render( $request, $exception ); |
|
| 67 | + } |
|
| 68 | 68 | } |
@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | * |
| 50 | 50 | * @throws \Exception Throw the exception. |
| 51 | 51 | */ |
| 52 | - public function report( Throwable $exception ) { |
|
| 53 | - parent::report( $exception ); |
|
| 52 | + public function report(Throwable $exception) { |
|
| 53 | + parent::report($exception); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * |
| 63 | 63 | * @throws \Throwable Throw the nexception. |
| 64 | 64 | */ |
| 65 | - public function render( $request, Throwable $exception ) { |
|
| 66 | - return parent::render( $request, $exception ); |
|
| 65 | + public function render($request, Throwable $exception) { |
|
| 66 | + return parent::render($request, $exception); |
|
| 67 | 67 | } |
| 68 | 68 | } |
@@ -31,411 +31,411 @@ |
||
| 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 | - throw new \Exception( $e, 1 ); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - $this->app['events']->dispatch( |
|
| 120 | - new RequestHandled( $request, $response ) |
|
| 121 | - ); |
|
| 122 | - |
|
| 123 | - return $response; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Send the given request through the middleware / router. |
|
| 128 | - * |
|
| 129 | - * @param \Illuminate\Http\Request $request The app http request. |
|
| 130 | - * |
|
| 131 | - * @return \Illuminate\Http\Response |
|
| 132 | - */ |
|
| 133 | - protected function send_request_through_router( $request ) { |
|
| 134 | - $this->app->instance( 'request', $request ); |
|
| 135 | - |
|
| 136 | - Facade::clearResolvedInstance( 'request' ); |
|
| 137 | - |
|
| 138 | - $this->bootstrap(); |
|
| 139 | - |
|
| 140 | - return ( new Pipeline( $this->app ) ) |
|
| 141 | - ->send( $request ) |
|
| 142 | - ->through( $this->middleware ) |
|
| 143 | - ->then( $this->dispatch_to_router() ); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Bootstrap the application for HTTP requests. |
|
| 148 | - * |
|
| 149 | - * @return void |
|
| 150 | - */ |
|
| 151 | - public function bootstrap() {} |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Get the route dispatcher callback. |
|
| 155 | - * |
|
| 156 | - * @return \Closure |
|
| 157 | - */ |
|
| 158 | - protected function dispatch_to_router() { |
|
| 159 | - return function ( $request ) { |
|
| 160 | - $this->app->instance( 'request', $request ); |
|
| 161 | - |
|
| 162 | - return $this->router->dispatch( $request ); |
|
| 163 | - }; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Call the terminate method on any terminable middleware. |
|
| 168 | - * |
|
| 169 | - * @param \Illuminate\Http\Request $request The app http request. |
|
| 170 | - * @param \Illuminate\Http\Response $response The app http response. |
|
| 171 | - * |
|
| 172 | - * @return void |
|
| 173 | - */ |
|
| 174 | - public function terminate( $request, $response ) { |
|
| 175 | - $this->terminate_middleware( $request, $response ); |
|
| 176 | - |
|
| 177 | - $this->app->terminate(); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Call the terminate method on any terminable middleware. |
|
| 182 | - * |
|
| 183 | - * @param \Illuminate\Http\Request $request The app http request. |
|
| 184 | - * @param \Illuminate\Http\Response $response The app http response. |
|
| 185 | - * |
|
| 186 | - * @return void |
|
| 187 | - */ |
|
| 188 | - protected function terminate_middleware( $request, $response ) { |
|
| 189 | - $middlewares = $this->app->shouldSkipMiddleware() ? array() : array_merge( |
|
| 190 | - $this->gather_route_middleware( $request ), |
|
| 191 | - $this->middleware |
|
| 192 | - ); |
|
| 193 | - |
|
| 194 | - foreach ( $middlewares as $middleware ) { |
|
| 195 | - if ( ! is_string( $middleware ) ) { |
|
| 196 | - continue; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - list( $name ) = $this->parse_middleware( $middleware ); |
|
| 200 | - |
|
| 201 | - $instance = $this->app->make( $name ); |
|
| 202 | - |
|
| 203 | - if ( method_exists( $instance, 'terminate' ) ) { |
|
| 204 | - $instance->terminate( $request, $response ); |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Gather the route middleware for the given request. |
|
| 211 | - * |
|
| 212 | - * @param \Illuminate\Http\Request $request The app http request. |
|
| 213 | - * |
|
| 214 | - * @return array |
|
| 215 | - */ |
|
| 216 | - protected function gather_route_middleware( $request ) { |
|
| 217 | - $route = $request->route(); |
|
| 218 | - if ( $route ) { |
|
| 219 | - return $this->router->gatherRouteMiddleware( $route ); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - return array(); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * Parse a middleware string to get the name and parameters. |
|
| 227 | - * |
|
| 228 | - * @param string $middleware The app middleware. |
|
| 229 | - * |
|
| 230 | - * @return array |
|
| 231 | - */ |
|
| 232 | - protected function parse_middleware( $middleware ) { |
|
| 233 | - |
|
| 234 | - list( $name, $parameters ) = array_pad( explode( ':', $middleware, 2 ), 2, array() ); |
|
| 235 | - |
|
| 236 | - if ( is_string( $parameters ) ) { |
|
| 237 | - $parameters = explode( ',', $parameters ); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - return array( $name, $parameters ); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Determine if the kernel has a given middleware. |
|
| 245 | - * |
|
| 246 | - * @param string $middleware The app middleware. |
|
| 247 | - * |
|
| 248 | - * @return bool |
|
| 249 | - */ |
|
| 250 | - public function has_middleware( $middleware ) { |
|
| 251 | - return in_array( $middleware, $this->middleware ); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Add a new middleware to beginning of the stack if it does not already exist. |
|
| 256 | - * |
|
| 257 | - * @param string $middleware The app middleware. |
|
| 258 | - * |
|
| 259 | - * @return $this |
|
| 260 | - */ |
|
| 261 | - public function prepend_middleware( $middleware ) { |
|
| 262 | - if ( array_search( $middleware, $this->middleware ) === false ) { |
|
| 263 | - array_unshift( $this->middleware, $middleware ); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - return $this; |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * Add a new middleware to end of the stack if it does not already exist. |
|
| 271 | - * |
|
| 272 | - * @param string $middleware The app middleware. |
|
| 273 | - * |
|
| 274 | - * @return $this |
|
| 275 | - */ |
|
| 276 | - public function push_middleware( $middleware ) { |
|
| 277 | - if ( array_search( $middleware, $this->middleware ) === false ) { |
|
| 278 | - $this->middleware[] = $middleware; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - return $this; |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * Prepend the given middleware to the given middleware group. |
|
| 286 | - * |
|
| 287 | - * @param string $group The app group. |
|
| 288 | - * @param string $middleware The app middleware. |
|
| 289 | - * |
|
| 290 | - * @throws \InvalidArgumentException The invalid argument exception. |
|
| 291 | - * |
|
| 292 | - * @return $this |
|
| 293 | - */ |
|
| 294 | - public function prepend_middleware_to_group( $group, $middleware ) { |
|
| 295 | - if ( ! isset( $this->middleware_groups[ $group ] ) ) { |
|
| 296 | - throw new InvalidArgumentException( "The [{$group}] middleware group has not been defined." ); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - if ( array_search( $middleware, $this->middleware_groups[ $group ] ) === false ) { |
|
| 300 | - array_unshift( $this->middleware_groups[ $group ], $middleware ); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - $this->sync_middleware_to_router(); |
|
| 304 | - |
|
| 305 | - return $this; |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * Append the given middleware to the given middleware group. |
|
| 310 | - * |
|
| 311 | - * @param string $group The app group. |
|
| 312 | - * @param string $middleware The app middleware. |
|
| 313 | - * |
|
| 314 | - * @throws \InvalidArgumentException The invalid argument exception. |
|
| 315 | - * |
|
| 316 | - * @return $this |
|
| 317 | - */ |
|
| 318 | - public function append_middleware_to_group( $group, $middleware ) { |
|
| 319 | - if ( ! isset( $this->middleware_groups[ $group ] ) ) { |
|
| 320 | - throw new InvalidArgumentException( "The [{$group}] middleware group has not been defined." ); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - if ( array_search( $middleware, $this->middleware_groups[ $group ] ) === false ) { |
|
| 324 | - $this->middleware_groups[ $group ][] = $middleware; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - $this->sync_middleware_to_router(); |
|
| 328 | - |
|
| 329 | - return $this; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * Prepend the given middleware to the middleware priority list. |
|
| 334 | - * |
|
| 335 | - * @param string $middleware The app middleware. |
|
| 336 | - * |
|
| 337 | - * @return $this |
|
| 338 | - */ |
|
| 339 | - public function prepend_to_middleware_priority( $middleware ) { |
|
| 340 | - if ( ! in_array( $middleware, $this->middleware_priority ) ) { |
|
| 341 | - array_unshift( $this->middleware_priority, $middleware ); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - $this->sync_middleware_to_router(); |
|
| 345 | - |
|
| 346 | - return $this; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * Append the given middleware to the middleware priority list. |
|
| 351 | - * |
|
| 352 | - * @param string $middleware The app middleware. |
|
| 353 | - * |
|
| 354 | - * @return $this |
|
| 355 | - */ |
|
| 356 | - public function append_to_middleware_priority( $middleware ) { |
|
| 357 | - if ( ! in_array( $middleware, $this->middleware_priority ) ) { |
|
| 358 | - $this->middleware_priority[] = $middleware; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - $this->sync_middleware_to_router(); |
|
| 362 | - |
|
| 363 | - return $this; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * Sync the current state of the middleware to the router. |
|
| 368 | - * |
|
| 369 | - * @return void |
|
| 370 | - */ |
|
| 371 | - protected function sync_middleware_to_router() { |
|
| 372 | - $this->router->middlewarePriority = $this->middleware_priority; |
|
| 373 | - |
|
| 374 | - foreach ( $this->middleware_groups as $key => $middleware ) { |
|
| 375 | - $this->router->middlewareGroup( $key, $middleware ); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - foreach ( $this->route_middleware as $key => $middleware ) { |
|
| 379 | - $this->router->aliasMiddleware( $key, $middleware ); |
|
| 380 | - } |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * Get the bootstrap classes for the application. |
|
| 385 | - * |
|
| 386 | - * @return array |
|
| 387 | - */ |
|
| 388 | - protected function bootstrappers() { |
|
| 389 | - return $this->bootstrappers; |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Report the exception to the exception handler. |
|
| 394 | - * |
|
| 395 | - * @param \Throwable $e The throwable exception. |
|
| 396 | - * |
|
| 397 | - * @return void |
|
| 398 | - */ |
|
| 399 | - protected function report_exception( Throwable $e ) { |
|
| 400 | - $this->app[ ExceptionHandler::class ]->report( $e ); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * Render the exception to a response. |
|
| 405 | - * |
|
| 406 | - * @param \Illuminate\Http\Request $request The app http request. |
|
| 407 | - * @param \Throwable $e The throwable exception. |
|
| 408 | - * |
|
| 409 | - * @return \Symfony\Component\HttpFoundation\Response |
|
| 410 | - */ |
|
| 411 | - protected function render_exception( $request, Throwable $e ) { |
|
| 412 | - return $this->app[ ExceptionHandler::class ]->render( $request, $e ); |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * Get the application's route middleware groups. |
|
| 417 | - * |
|
| 418 | - * @return array |
|
| 419 | - */ |
|
| 420 | - public function get_middleware_groups() { |
|
| 421 | - return $this->middleware_groups; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Get the application's route middleware. |
|
| 426 | - * |
|
| 427 | - * @return array |
|
| 428 | - */ |
|
| 429 | - public function get_route_middleware() { |
|
| 430 | - return $this->route_middleware; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * Get the Laravel application instance. |
|
| 435 | - * |
|
| 436 | - * @return \Illuminate\Contracts\Foundation\Application |
|
| 437 | - */ |
|
| 438 | - public function get_application() { |
|
| 439 | - return $this->app; |
|
| 440 | - } |
|
| 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 | + throw new \Exception( $e, 1 ); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + $this->app['events']->dispatch( |
|
| 120 | + new RequestHandled( $request, $response ) |
|
| 121 | + ); |
|
| 122 | + |
|
| 123 | + return $response; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Send the given request through the middleware / router. |
|
| 128 | + * |
|
| 129 | + * @param \Illuminate\Http\Request $request The app http request. |
|
| 130 | + * |
|
| 131 | + * @return \Illuminate\Http\Response |
|
| 132 | + */ |
|
| 133 | + protected function send_request_through_router( $request ) { |
|
| 134 | + $this->app->instance( 'request', $request ); |
|
| 135 | + |
|
| 136 | + Facade::clearResolvedInstance( 'request' ); |
|
| 137 | + |
|
| 138 | + $this->bootstrap(); |
|
| 139 | + |
|
| 140 | + return ( new Pipeline( $this->app ) ) |
|
| 141 | + ->send( $request ) |
|
| 142 | + ->through( $this->middleware ) |
|
| 143 | + ->then( $this->dispatch_to_router() ); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Bootstrap the application for HTTP requests. |
|
| 148 | + * |
|
| 149 | + * @return void |
|
| 150 | + */ |
|
| 151 | + public function bootstrap() {} |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Get the route dispatcher callback. |
|
| 155 | + * |
|
| 156 | + * @return \Closure |
|
| 157 | + */ |
|
| 158 | + protected function dispatch_to_router() { |
|
| 159 | + return function ( $request ) { |
|
| 160 | + $this->app->instance( 'request', $request ); |
|
| 161 | + |
|
| 162 | + return $this->router->dispatch( $request ); |
|
| 163 | + }; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Call the terminate method on any terminable middleware. |
|
| 168 | + * |
|
| 169 | + * @param \Illuminate\Http\Request $request The app http request. |
|
| 170 | + * @param \Illuminate\Http\Response $response The app http response. |
|
| 171 | + * |
|
| 172 | + * @return void |
|
| 173 | + */ |
|
| 174 | + public function terminate( $request, $response ) { |
|
| 175 | + $this->terminate_middleware( $request, $response ); |
|
| 176 | + |
|
| 177 | + $this->app->terminate(); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Call the terminate method on any terminable middleware. |
|
| 182 | + * |
|
| 183 | + * @param \Illuminate\Http\Request $request The app http request. |
|
| 184 | + * @param \Illuminate\Http\Response $response The app http response. |
|
| 185 | + * |
|
| 186 | + * @return void |
|
| 187 | + */ |
|
| 188 | + protected function terminate_middleware( $request, $response ) { |
|
| 189 | + $middlewares = $this->app->shouldSkipMiddleware() ? array() : array_merge( |
|
| 190 | + $this->gather_route_middleware( $request ), |
|
| 191 | + $this->middleware |
|
| 192 | + ); |
|
| 193 | + |
|
| 194 | + foreach ( $middlewares as $middleware ) { |
|
| 195 | + if ( ! is_string( $middleware ) ) { |
|
| 196 | + continue; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + list( $name ) = $this->parse_middleware( $middleware ); |
|
| 200 | + |
|
| 201 | + $instance = $this->app->make( $name ); |
|
| 202 | + |
|
| 203 | + if ( method_exists( $instance, 'terminate' ) ) { |
|
| 204 | + $instance->terminate( $request, $response ); |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Gather the route middleware for the given request. |
|
| 211 | + * |
|
| 212 | + * @param \Illuminate\Http\Request $request The app http request. |
|
| 213 | + * |
|
| 214 | + * @return array |
|
| 215 | + */ |
|
| 216 | + protected function gather_route_middleware( $request ) { |
|
| 217 | + $route = $request->route(); |
|
| 218 | + if ( $route ) { |
|
| 219 | + return $this->router->gatherRouteMiddleware( $route ); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + return array(); |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * Parse a middleware string to get the name and parameters. |
|
| 227 | + * |
|
| 228 | + * @param string $middleware The app middleware. |
|
| 229 | + * |
|
| 230 | + * @return array |
|
| 231 | + */ |
|
| 232 | + protected function parse_middleware( $middleware ) { |
|
| 233 | + |
|
| 234 | + list( $name, $parameters ) = array_pad( explode( ':', $middleware, 2 ), 2, array() ); |
|
| 235 | + |
|
| 236 | + if ( is_string( $parameters ) ) { |
|
| 237 | + $parameters = explode( ',', $parameters ); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + return array( $name, $parameters ); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Determine if the kernel has a given middleware. |
|
| 245 | + * |
|
| 246 | + * @param string $middleware The app middleware. |
|
| 247 | + * |
|
| 248 | + * @return bool |
|
| 249 | + */ |
|
| 250 | + public function has_middleware( $middleware ) { |
|
| 251 | + return in_array( $middleware, $this->middleware ); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Add a new middleware to beginning of the stack if it does not already exist. |
|
| 256 | + * |
|
| 257 | + * @param string $middleware The app middleware. |
|
| 258 | + * |
|
| 259 | + * @return $this |
|
| 260 | + */ |
|
| 261 | + public function prepend_middleware( $middleware ) { |
|
| 262 | + if ( array_search( $middleware, $this->middleware ) === false ) { |
|
| 263 | + array_unshift( $this->middleware, $middleware ); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + return $this; |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * Add a new middleware to end of the stack if it does not already exist. |
|
| 271 | + * |
|
| 272 | + * @param string $middleware The app middleware. |
|
| 273 | + * |
|
| 274 | + * @return $this |
|
| 275 | + */ |
|
| 276 | + public function push_middleware( $middleware ) { |
|
| 277 | + if ( array_search( $middleware, $this->middleware ) === false ) { |
|
| 278 | + $this->middleware[] = $middleware; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + return $this; |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * Prepend the given middleware to the given middleware group. |
|
| 286 | + * |
|
| 287 | + * @param string $group The app group. |
|
| 288 | + * @param string $middleware The app middleware. |
|
| 289 | + * |
|
| 290 | + * @throws \InvalidArgumentException The invalid argument exception. |
|
| 291 | + * |
|
| 292 | + * @return $this |
|
| 293 | + */ |
|
| 294 | + public function prepend_middleware_to_group( $group, $middleware ) { |
|
| 295 | + if ( ! isset( $this->middleware_groups[ $group ] ) ) { |
|
| 296 | + throw new InvalidArgumentException( "The [{$group}] middleware group has not been defined." ); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + if ( array_search( $middleware, $this->middleware_groups[ $group ] ) === false ) { |
|
| 300 | + array_unshift( $this->middleware_groups[ $group ], $middleware ); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + $this->sync_middleware_to_router(); |
|
| 304 | + |
|
| 305 | + return $this; |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * Append the given middleware to the given middleware group. |
|
| 310 | + * |
|
| 311 | + * @param string $group The app group. |
|
| 312 | + * @param string $middleware The app middleware. |
|
| 313 | + * |
|
| 314 | + * @throws \InvalidArgumentException The invalid argument exception. |
|
| 315 | + * |
|
| 316 | + * @return $this |
|
| 317 | + */ |
|
| 318 | + public function append_middleware_to_group( $group, $middleware ) { |
|
| 319 | + if ( ! isset( $this->middleware_groups[ $group ] ) ) { |
|
| 320 | + throw new InvalidArgumentException( "The [{$group}] middleware group has not been defined." ); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + if ( array_search( $middleware, $this->middleware_groups[ $group ] ) === false ) { |
|
| 324 | + $this->middleware_groups[ $group ][] = $middleware; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + $this->sync_middleware_to_router(); |
|
| 328 | + |
|
| 329 | + return $this; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * Prepend the given middleware to the middleware priority list. |
|
| 334 | + * |
|
| 335 | + * @param string $middleware The app middleware. |
|
| 336 | + * |
|
| 337 | + * @return $this |
|
| 338 | + */ |
|
| 339 | + public function prepend_to_middleware_priority( $middleware ) { |
|
| 340 | + if ( ! in_array( $middleware, $this->middleware_priority ) ) { |
|
| 341 | + array_unshift( $this->middleware_priority, $middleware ); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + $this->sync_middleware_to_router(); |
|
| 345 | + |
|
| 346 | + return $this; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * Append the given middleware to the middleware priority list. |
|
| 351 | + * |
|
| 352 | + * @param string $middleware The app middleware. |
|
| 353 | + * |
|
| 354 | + * @return $this |
|
| 355 | + */ |
|
| 356 | + public function append_to_middleware_priority( $middleware ) { |
|
| 357 | + if ( ! in_array( $middleware, $this->middleware_priority ) ) { |
|
| 358 | + $this->middleware_priority[] = $middleware; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + $this->sync_middleware_to_router(); |
|
| 362 | + |
|
| 363 | + return $this; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * Sync the current state of the middleware to the router. |
|
| 368 | + * |
|
| 369 | + * @return void |
|
| 370 | + */ |
|
| 371 | + protected function sync_middleware_to_router() { |
|
| 372 | + $this->router->middlewarePriority = $this->middleware_priority; |
|
| 373 | + |
|
| 374 | + foreach ( $this->middleware_groups as $key => $middleware ) { |
|
| 375 | + $this->router->middlewareGroup( $key, $middleware ); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + foreach ( $this->route_middleware as $key => $middleware ) { |
|
| 379 | + $this->router->aliasMiddleware( $key, $middleware ); |
|
| 380 | + } |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * Get the bootstrap classes for the application. |
|
| 385 | + * |
|
| 386 | + * @return array |
|
| 387 | + */ |
|
| 388 | + protected function bootstrappers() { |
|
| 389 | + return $this->bootstrappers; |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Report the exception to the exception handler. |
|
| 394 | + * |
|
| 395 | + * @param \Throwable $e The throwable exception. |
|
| 396 | + * |
|
| 397 | + * @return void |
|
| 398 | + */ |
|
| 399 | + protected function report_exception( Throwable $e ) { |
|
| 400 | + $this->app[ ExceptionHandler::class ]->report( $e ); |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * Render the exception to a response. |
|
| 405 | + * |
|
| 406 | + * @param \Illuminate\Http\Request $request The app http request. |
|
| 407 | + * @param \Throwable $e The throwable exception. |
|
| 408 | + * |
|
| 409 | + * @return \Symfony\Component\HttpFoundation\Response |
|
| 410 | + */ |
|
| 411 | + protected function render_exception( $request, Throwable $e ) { |
|
| 412 | + return $this->app[ ExceptionHandler::class ]->render( $request, $e ); |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * Get the application's route middleware groups. |
|
| 417 | + * |
|
| 418 | + * @return array |
|
| 419 | + */ |
|
| 420 | + public function get_middleware_groups() { |
|
| 421 | + return $this->middleware_groups; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Get the application's route middleware. |
|
| 426 | + * |
|
| 427 | + * @return array |
|
| 428 | + */ |
|
| 429 | + public function get_route_middleware() { |
|
| 430 | + return $this->route_middleware; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * Get the Laravel application instance. |
|
| 435 | + * |
|
| 436 | + * @return \Illuminate\Contracts\Foundation\Application |
|
| 437 | + */ |
|
| 438 | + public function get_application() { |
|
| 439 | + return $this->app; |
|
| 440 | + } |
|
| 441 | 441 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 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,18 +106,18 @@ discard block |
||
| 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 ); |
|
| 116 | - throw new \Exception( $e, 1 ); |
|
| 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 | + throw new \Exception($e, 1); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | $this->app['events']->dispatch( |
| 120 | - new RequestHandled( $request, $response ) |
|
| 120 | + new RequestHandled($request, $response) |
|
| 121 | 121 | ); |
| 122 | 122 | |
| 123 | 123 | return $response; |
@@ -130,17 +130,17 @@ discard block |
||
| 130 | 130 | * |
| 131 | 131 | * @return \Illuminate\Http\Response |
| 132 | 132 | */ |
| 133 | - protected function send_request_through_router( $request ) { |
|
| 134 | - $this->app->instance( 'request', $request ); |
|
| 133 | + protected function send_request_through_router($request) { |
|
| 134 | + $this->app->instance('request', $request); |
|
| 135 | 135 | |
| 136 | - Facade::clearResolvedInstance( 'request' ); |
|
| 136 | + Facade::clearResolvedInstance('request'); |
|
| 137 | 137 | |
| 138 | 138 | $this->bootstrap(); |
| 139 | 139 | |
| 140 | - return ( new Pipeline( $this->app ) ) |
|
| 141 | - ->send( $request ) |
|
| 142 | - ->through( $this->middleware ) |
|
| 143 | - ->then( $this->dispatch_to_router() ); |
|
| 140 | + return (new Pipeline($this->app)) |
|
| 141 | + ->send($request) |
|
| 142 | + ->through($this->middleware) |
|
| 143 | + ->then($this->dispatch_to_router()); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -156,10 +156,10 @@ discard block |
||
| 156 | 156 | * @return \Closure |
| 157 | 157 | */ |
| 158 | 158 | protected function dispatch_to_router() { |
| 159 | - return function ( $request ) { |
|
| 160 | - $this->app->instance( 'request', $request ); |
|
| 159 | + return function($request) { |
|
| 160 | + $this->app->instance('request', $request); |
|
| 161 | 161 | |
| 162 | - return $this->router->dispatch( $request ); |
|
| 162 | + return $this->router->dispatch($request); |
|
| 163 | 163 | }; |
| 164 | 164 | } |
| 165 | 165 | |
@@ -171,8 +171,8 @@ discard block |
||
| 171 | 171 | * |
| 172 | 172 | * @return void |
| 173 | 173 | */ |
| 174 | - public function terminate( $request, $response ) { |
|
| 175 | - $this->terminate_middleware( $request, $response ); |
|
| 174 | + public function terminate($request, $response) { |
|
| 175 | + $this->terminate_middleware($request, $response); |
|
| 176 | 176 | |
| 177 | 177 | $this->app->terminate(); |
| 178 | 178 | } |
@@ -185,23 +185,23 @@ discard block |
||
| 185 | 185 | * |
| 186 | 186 | * @return void |
| 187 | 187 | */ |
| 188 | - protected function terminate_middleware( $request, $response ) { |
|
| 188 | + protected function terminate_middleware($request, $response) { |
|
| 189 | 189 | $middlewares = $this->app->shouldSkipMiddleware() ? array() : array_merge( |
| 190 | - $this->gather_route_middleware( $request ), |
|
| 190 | + $this->gather_route_middleware($request), |
|
| 191 | 191 | $this->middleware |
| 192 | 192 | ); |
| 193 | 193 | |
| 194 | - foreach ( $middlewares as $middleware ) { |
|
| 195 | - if ( ! is_string( $middleware ) ) { |
|
| 194 | + foreach ($middlewares as $middleware) { |
|
| 195 | + if (!is_string($middleware)) { |
|
| 196 | 196 | continue; |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - list( $name ) = $this->parse_middleware( $middleware ); |
|
| 199 | + list($name) = $this->parse_middleware($middleware); |
|
| 200 | 200 | |
| 201 | - $instance = $this->app->make( $name ); |
|
| 201 | + $instance = $this->app->make($name); |
|
| 202 | 202 | |
| 203 | - if ( method_exists( $instance, 'terminate' ) ) { |
|
| 204 | - $instance->terminate( $request, $response ); |
|
| 203 | + if (method_exists($instance, 'terminate')) { |
|
| 204 | + $instance->terminate($request, $response); |
|
| 205 | 205 | } |
| 206 | 206 | } |
| 207 | 207 | } |
@@ -213,10 +213,10 @@ discard block |
||
| 213 | 213 | * |
| 214 | 214 | * @return array |
| 215 | 215 | */ |
| 216 | - protected function gather_route_middleware( $request ) { |
|
| 216 | + protected function gather_route_middleware($request) { |
|
| 217 | 217 | $route = $request->route(); |
| 218 | - if ( $route ) { |
|
| 219 | - return $this->router->gatherRouteMiddleware( $route ); |
|
| 218 | + if ($route) { |
|
| 219 | + return $this->router->gatherRouteMiddleware($route); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | return array(); |
@@ -229,15 +229,15 @@ discard block |
||
| 229 | 229 | * |
| 230 | 230 | * @return array |
| 231 | 231 | */ |
| 232 | - protected function parse_middleware( $middleware ) { |
|
| 232 | + protected function parse_middleware($middleware) { |
|
| 233 | 233 | |
| 234 | - list( $name, $parameters ) = array_pad( explode( ':', $middleware, 2 ), 2, array() ); |
|
| 234 | + list($name, $parameters) = array_pad(explode(':', $middleware, 2), 2, array()); |
|
| 235 | 235 | |
| 236 | - if ( is_string( $parameters ) ) { |
|
| 237 | - $parameters = explode( ',', $parameters ); |
|
| 236 | + if (is_string($parameters)) { |
|
| 237 | + $parameters = explode(',', $parameters); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - return array( $name, $parameters ); |
|
| 240 | + return array($name, $parameters); |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | /** |
@@ -247,8 +247,8 @@ discard block |
||
| 247 | 247 | * |
| 248 | 248 | * @return bool |
| 249 | 249 | */ |
| 250 | - public function has_middleware( $middleware ) { |
|
| 251 | - return in_array( $middleware, $this->middleware ); |
|
| 250 | + public function has_middleware($middleware) { |
|
| 251 | + return in_array($middleware, $this->middleware); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /** |
@@ -258,9 +258,9 @@ discard block |
||
| 258 | 258 | * |
| 259 | 259 | * @return $this |
| 260 | 260 | */ |
| 261 | - public function prepend_middleware( $middleware ) { |
|
| 262 | - if ( array_search( $middleware, $this->middleware ) === false ) { |
|
| 263 | - array_unshift( $this->middleware, $middleware ); |
|
| 261 | + public function prepend_middleware($middleware) { |
|
| 262 | + if (array_search($middleware, $this->middleware) === false) { |
|
| 263 | + array_unshift($this->middleware, $middleware); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | return $this; |
@@ -273,8 +273,8 @@ discard block |
||
| 273 | 273 | * |
| 274 | 274 | * @return $this |
| 275 | 275 | */ |
| 276 | - public function push_middleware( $middleware ) { |
|
| 277 | - if ( array_search( $middleware, $this->middleware ) === false ) { |
|
| 276 | + public function push_middleware($middleware) { |
|
| 277 | + if (array_search($middleware, $this->middleware) === false) { |
|
| 278 | 278 | $this->middleware[] = $middleware; |
| 279 | 279 | } |
| 280 | 280 | |
@@ -291,13 +291,13 @@ discard block |
||
| 291 | 291 | * |
| 292 | 292 | * @return $this |
| 293 | 293 | */ |
| 294 | - public function prepend_middleware_to_group( $group, $middleware ) { |
|
| 295 | - if ( ! isset( $this->middleware_groups[ $group ] ) ) { |
|
| 296 | - throw new InvalidArgumentException( "The [{$group}] middleware group has not been defined." ); |
|
| 294 | + public function prepend_middleware_to_group($group, $middleware) { |
|
| 295 | + if (!isset($this->middleware_groups[$group])) { |
|
| 296 | + throw new InvalidArgumentException("The [{$group}] middleware group has not been defined."); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - if ( array_search( $middleware, $this->middleware_groups[ $group ] ) === false ) { |
|
| 300 | - array_unshift( $this->middleware_groups[ $group ], $middleware ); |
|
| 299 | + if (array_search($middleware, $this->middleware_groups[$group]) === false) { |
|
| 300 | + array_unshift($this->middleware_groups[$group], $middleware); |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | $this->sync_middleware_to_router(); |
@@ -315,13 +315,13 @@ discard block |
||
| 315 | 315 | * |
| 316 | 316 | * @return $this |
| 317 | 317 | */ |
| 318 | - public function append_middleware_to_group( $group, $middleware ) { |
|
| 319 | - if ( ! isset( $this->middleware_groups[ $group ] ) ) { |
|
| 320 | - throw new InvalidArgumentException( "The [{$group}] middleware group has not been defined." ); |
|
| 318 | + public function append_middleware_to_group($group, $middleware) { |
|
| 319 | + if (!isset($this->middleware_groups[$group])) { |
|
| 320 | + throw new InvalidArgumentException("The [{$group}] middleware group has not been defined."); |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | - if ( array_search( $middleware, $this->middleware_groups[ $group ] ) === false ) { |
|
| 324 | - $this->middleware_groups[ $group ][] = $middleware; |
|
| 323 | + if (array_search($middleware, $this->middleware_groups[$group]) === false) { |
|
| 324 | + $this->middleware_groups[$group][] = $middleware; |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | $this->sync_middleware_to_router(); |
@@ -336,9 +336,9 @@ discard block |
||
| 336 | 336 | * |
| 337 | 337 | * @return $this |
| 338 | 338 | */ |
| 339 | - public function prepend_to_middleware_priority( $middleware ) { |
|
| 340 | - if ( ! in_array( $middleware, $this->middleware_priority ) ) { |
|
| 341 | - array_unshift( $this->middleware_priority, $middleware ); |
|
| 339 | + public function prepend_to_middleware_priority($middleware) { |
|
| 340 | + if (!in_array($middleware, $this->middleware_priority)) { |
|
| 341 | + array_unshift($this->middleware_priority, $middleware); |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | $this->sync_middleware_to_router(); |
@@ -353,8 +353,8 @@ discard block |
||
| 353 | 353 | * |
| 354 | 354 | * @return $this |
| 355 | 355 | */ |
| 356 | - public function append_to_middleware_priority( $middleware ) { |
|
| 357 | - if ( ! in_array( $middleware, $this->middleware_priority ) ) { |
|
| 356 | + public function append_to_middleware_priority($middleware) { |
|
| 357 | + if (!in_array($middleware, $this->middleware_priority)) { |
|
| 358 | 358 | $this->middleware_priority[] = $middleware; |
| 359 | 359 | } |
| 360 | 360 | |
@@ -371,12 +371,12 @@ discard block |
||
| 371 | 371 | protected function sync_middleware_to_router() { |
| 372 | 372 | $this->router->middlewarePriority = $this->middleware_priority; |
| 373 | 373 | |
| 374 | - foreach ( $this->middleware_groups as $key => $middleware ) { |
|
| 375 | - $this->router->middlewareGroup( $key, $middleware ); |
|
| 374 | + foreach ($this->middleware_groups as $key => $middleware) { |
|
| 375 | + $this->router->middlewareGroup($key, $middleware); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | - foreach ( $this->route_middleware as $key => $middleware ) { |
|
| 379 | - $this->router->aliasMiddleware( $key, $middleware ); |
|
| 378 | + foreach ($this->route_middleware as $key => $middleware) { |
|
| 379 | + $this->router->aliasMiddleware($key, $middleware); |
|
| 380 | 380 | } |
| 381 | 381 | } |
| 382 | 382 | |
@@ -396,8 +396,8 @@ discard block |
||
| 396 | 396 | * |
| 397 | 397 | * @return void |
| 398 | 398 | */ |
| 399 | - protected function report_exception( Throwable $e ) { |
|
| 400 | - $this->app[ ExceptionHandler::class ]->report( $e ); |
|
| 399 | + protected function report_exception(Throwable $e) { |
|
| 400 | + $this->app[ExceptionHandler::class]->report($e); |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | /** |
@@ -408,8 +408,8 @@ discard block |
||
| 408 | 408 | * |
| 409 | 409 | * @return \Symfony\Component\HttpFoundation\Response |
| 410 | 410 | */ |
| 411 | - protected function render_exception( $request, Throwable $e ) { |
|
| 412 | - return $this->app[ ExceptionHandler::class ]->render( $request, $e ); |
|
| 411 | + protected function render_exception($request, Throwable $e) { |
|
| 412 | + return $this->app[ExceptionHandler::class]->render($request, $e); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | /** |