@@ -21,34 +21,34 @@ |
||
21 | 21 | */ |
22 | 22 | interface Kernel { |
23 | 23 | |
24 | - /** |
|
25 | - * Bootstrap the application for HTTP requests. |
|
26 | - * |
|
27 | - * @return void |
|
28 | - */ |
|
29 | - public function bootstrap(); |
|
24 | + /** |
|
25 | + * Bootstrap the application for HTTP requests. |
|
26 | + * |
|
27 | + * @return void |
|
28 | + */ |
|
29 | + public function bootstrap(); |
|
30 | 30 | |
31 | - /** |
|
32 | - * Handle an incoming HTTP request. |
|
33 | - * |
|
34 | - * @param \Symfony\Component\HttpFoundation\Request $request The app http request. |
|
35 | - * @return \Symfony\Component\HttpFoundation\Response |
|
36 | - */ |
|
37 | - public function handle( $request); |
|
31 | + /** |
|
32 | + * Handle an incoming HTTP request. |
|
33 | + * |
|
34 | + * @param \Symfony\Component\HttpFoundation\Request $request The app http request. |
|
35 | + * @return \Symfony\Component\HttpFoundation\Response |
|
36 | + */ |
|
37 | + public function handle( $request); |
|
38 | 38 | |
39 | - /** |
|
40 | - * Perform any final actions for the request lifecycle. |
|
41 | - * |
|
42 | - * @param \Symfony\Component\HttpFoundation\Request $request The app http request. |
|
43 | - * @param \Symfony\Component\HttpFoundation\Response $response The app http response. |
|
44 | - * @return void |
|
45 | - */ |
|
46 | - public function terminate( $request, $response); |
|
39 | + /** |
|
40 | + * Perform any final actions for the request lifecycle. |
|
41 | + * |
|
42 | + * @param \Symfony\Component\HttpFoundation\Request $request The app http request. |
|
43 | + * @param \Symfony\Component\HttpFoundation\Response $response The app http response. |
|
44 | + * @return void |
|
45 | + */ |
|
46 | + public function terminate( $request, $response); |
|
47 | 47 | |
48 | - /** |
|
49 | - * Get the Laravel application instance. |
|
50 | - * |
|
51 | - * @return \Illuminate\Contracts\Foundation\Application |
|
52 | - */ |
|
53 | - public function get_application(); |
|
48 | + /** |
|
49 | + * Get the Laravel application instance. |
|
50 | + * |
|
51 | + * @return \Illuminate\Contracts\Foundation\Application |
|
52 | + */ |
|
53 | + public function get_application(); |
|
54 | 54 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @param \Symfony\Component\HttpFoundation\Request $request The app http request. |
35 | 35 | * @return \Symfony\Component\HttpFoundation\Response |
36 | 36 | */ |
37 | - public function handle( $request); |
|
37 | + public function handle($request); |
|
38 | 38 | |
39 | 39 | /** |
40 | 40 | * Perform any final actions for the request lifecycle. |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @param \Symfony\Component\HttpFoundation\Response $response The app http response. |
44 | 44 | * @return void |
45 | 45 | */ |
46 | - public function terminate( $request, $response); |
|
46 | + public function terminate($request, $response); |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * Get the Laravel application instance. |
@@ -24,41 +24,41 @@ |
||
24 | 24 | */ |
25 | 25 | interface ExceptionHandler { |
26 | 26 | |
27 | - /** |
|
28 | - * Report or log an exception. |
|
29 | - * |
|
30 | - * @param \Throwable $e The throwable exception. |
|
31 | - * @return void |
|
32 | - * |
|
33 | - * @throws \Exception Throw the exception. |
|
34 | - */ |
|
35 | - public function report( Throwable $e); |
|
27 | + /** |
|
28 | + * Report or log an exception. |
|
29 | + * |
|
30 | + * @param \Throwable $e The throwable exception. |
|
31 | + * @return void |
|
32 | + * |
|
33 | + * @throws \Exception Throw the exception. |
|
34 | + */ |
|
35 | + public function report( Throwable $e); |
|
36 | 36 | |
37 | - /** |
|
38 | - * Determine if the exception should be reported. |
|
39 | - * |
|
40 | - * @param \Throwable $e The throwable exception. |
|
41 | - * @return bool |
|
42 | - */ |
|
43 | - public function should_report( Throwable $e); |
|
37 | + /** |
|
38 | + * Determine if the exception should be reported. |
|
39 | + * |
|
40 | + * @param \Throwable $e The throwable exception. |
|
41 | + * @return bool |
|
42 | + */ |
|
43 | + public function should_report( Throwable $e); |
|
44 | 44 | |
45 | - /** |
|
46 | - * Render an exception into an HTTP response. |
|
47 | - * |
|
48 | - * @param \Illuminate\Http\Request $request The app request. |
|
49 | - * @param \Throwable $e The throwable exception. |
|
50 | - * @return \Symfony\Component\HttpFoundation\Response |
|
51 | - * |
|
52 | - * @throws \Throwable Throw the error. |
|
53 | - */ |
|
54 | - public function render( $request, Throwable $e); |
|
45 | + /** |
|
46 | + * Render an exception into an HTTP response. |
|
47 | + * |
|
48 | + * @param \Illuminate\Http\Request $request The app request. |
|
49 | + * @param \Throwable $e The throwable exception. |
|
50 | + * @return \Symfony\Component\HttpFoundation\Response |
|
51 | + * |
|
52 | + * @throws \Throwable Throw the error. |
|
53 | + */ |
|
54 | + public function render( $request, Throwable $e); |
|
55 | 55 | |
56 | - /** |
|
57 | - * Render an exception to the console. |
|
58 | - * |
|
59 | - * @param \Symfony\Component\Console\Output\OutputInterface $output Symfony output. |
|
60 | - * @param \Throwable $e The throwable exception. |
|
61 | - * @return void |
|
62 | - */ |
|
63 | - public function render_for_console( $output, Throwable $e); |
|
56 | + /** |
|
57 | + * Render an exception to the console. |
|
58 | + * |
|
59 | + * @param \Symfony\Component\Console\Output\OutputInterface $output Symfony output. |
|
60 | + * @param \Throwable $e The throwable exception. |
|
61 | + * @return void |
|
62 | + */ |
|
63 | + public function render_for_console( $output, Throwable $e); |
|
64 | 64 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @throws \Exception Throw the exception. |
34 | 34 | */ |
35 | - public function report( Throwable $e); |
|
35 | + public function report(Throwable $e); |
|
36 | 36 | |
37 | 37 | /** |
38 | 38 | * Determine if the exception should be reported. |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * @param \Throwable $e The throwable exception. |
41 | 41 | * @return bool |
42 | 42 | */ |
43 | - public function should_report( Throwable $e); |
|
43 | + public function should_report(Throwable $e); |
|
44 | 44 | |
45 | 45 | /** |
46 | 46 | * Render an exception into an HTTP response. |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @throws \Throwable Throw the error. |
53 | 53 | */ |
54 | - public function render( $request, Throwable $e); |
|
54 | + public function render($request, Throwable $e); |
|
55 | 55 | |
56 | 56 | /** |
57 | 57 | * Render an exception to the console. |
@@ -60,5 +60,5 @@ discard block |
||
60 | 60 | * @param \Throwable $e The throwable exception. |
61 | 61 | * @return void |
62 | 62 | */ |
63 | - public function render_for_console( $output, Throwable $e); |
|
63 | + public function render_for_console($output, Throwable $e); |
|
64 | 64 | } |
@@ -30,253 +30,253 @@ |
||
30 | 30 | */ |
31 | 31 | class Application { |
32 | 32 | |
33 | - /** |
|
34 | - * The app container. |
|
35 | - * |
|
36 | - * @since 1.0.0 |
|
37 | - * @access protected |
|
38 | - * @var \Illuminate\Contracts\Container\Container $app The app container. |
|
39 | - */ |
|
40 | - protected $app = null; |
|
41 | - |
|
42 | - /** |
|
43 | - * The config. |
|
44 | - * |
|
45 | - * @since 1.0.0 |
|
46 | - * @access protected |
|
47 | - * @var \WPB\Support\Facades\Config $config The config. |
|
48 | - */ |
|
49 | - protected $config; |
|
50 | - |
|
51 | - /** |
|
52 | - * The database manager. |
|
53 | - * |
|
54 | - * @since 1.0.0 |
|
55 | - * @access protected |
|
56 | - * @var \CodexShaper\Database\Database $db The database manager. |
|
57 | - */ |
|
58 | - protected $db; |
|
59 | - |
|
60 | - /** |
|
61 | - * The default options. |
|
62 | - * |
|
63 | - * @since 1.0.0 |
|
64 | - * @access protected |
|
65 | - * @var array $options The default options. |
|
66 | - */ |
|
67 | - protected $options; |
|
68 | - |
|
69 | - /** |
|
70 | - * This string unique root path. |
|
71 | - * |
|
72 | - * @since 1.0.0 |
|
73 | - * @access protected |
|
74 | - * @var string $root This string unique root path. |
|
75 | - */ |
|
76 | - protected $root; |
|
77 | - |
|
78 | - /** |
|
79 | - * The application factory. |
|
80 | - * |
|
81 | - * @since 1.0.0 |
|
82 | - * @param array $options The site options. |
|
83 | - * @param \Illuminate\Contracts\Container\Container as ContainerInterface $container The app container. |
|
84 | - * |
|
85 | - * @return void |
|
86 | - */ |
|
87 | - public function __construct( $options = array(), ContainerInterface $container = null ) { |
|
88 | - $this->options = $options; |
|
89 | - |
|
90 | - $this->app = $container; |
|
91 | - |
|
92 | - if ( is_null( $this->app ) ) { |
|
93 | - $this->app = new Container(); |
|
94 | - Facade::setFacadeApplication( $this->app ); |
|
95 | - $this->app->instance( ContainerInterface::class, $this->app ); |
|
96 | - } |
|
97 | - |
|
98 | - $this->app['app'] = $this->app; |
|
99 | - |
|
100 | - $this->root = __DIR__ . '/../../../../'; |
|
101 | - |
|
102 | - if ( ! empty( $this->options ) && isset( $this->options['paths']['root'] ) ) { |
|
103 | - $this->root = rtrim( $this->options['paths']['root'], '/' ) . '/'; |
|
104 | - } |
|
105 | - |
|
106 | - if ( ! isset( $this->app['root'] ) ) { |
|
107 | - $this->app['root'] = $this->root; |
|
108 | - } |
|
109 | - |
|
110 | - $this->config = new Config( $this->options ); |
|
111 | - |
|
112 | - $this->setup_env(); |
|
113 | - $this->register_config(); |
|
114 | - $this->setup_database(); |
|
115 | - $this->register_providers(); |
|
116 | - $this->register_request(); |
|
117 | - $this->register_router(); |
|
118 | - $this->load_routes( $this->app['router'] ); |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Get the app container. |
|
123 | - * |
|
124 | - * @since 1.0.0 |
|
125 | - * |
|
126 | - * @return \Illuminate\Container\Container |
|
127 | - */ |
|
128 | - public function get_instance() { |
|
129 | - if ( ! $this->app ) { |
|
130 | - new self(); |
|
131 | - } |
|
132 | - |
|
133 | - return $this->app; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Setup the env. |
|
138 | - * |
|
139 | - * @since 1.0.0 |
|
140 | - * |
|
141 | - * @return void |
|
142 | - */ |
|
143 | - protected function setup_env() { |
|
144 | - $this->app['env'] = $this->config->get( 'app.env' ); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Register config. |
|
149 | - * |
|
150 | - * @since 1.0.0 |
|
151 | - * |
|
152 | - * @return void |
|
153 | - */ |
|
154 | - protected function register_config() { |
|
155 | - $this->app->bind( |
|
156 | - 'config', |
|
157 | - function () { |
|
158 | - return array( |
|
159 | - 'app' => $this->config->get( 'app' ), |
|
160 | - 'view.paths' => $this->config->get( 'view.paths' ), |
|
161 | - 'view.compiled' => $this->config->get( 'view.compiled' ), |
|
162 | - ); |
|
163 | - }, |
|
164 | - true |
|
165 | - ); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Setup the database. |
|
170 | - * |
|
171 | - * @since 1.0.0 |
|
172 | - * |
|
173 | - * @return void |
|
174 | - */ |
|
175 | - protected function setup_database() { |
|
176 | - global $wpdb; |
|
177 | - |
|
178 | - $this->db = new Database( |
|
179 | - array( |
|
180 | - 'driver' => 'mysql', |
|
181 | - 'host' => $wpdb->dbhost, |
|
182 | - 'database' => $wpdb->dbname, |
|
183 | - 'username' => $wpdb->dbuser, |
|
184 | - 'password' => $wpdb->dbpassword, |
|
185 | - 'prefix' => $wpdb->prefix, |
|
186 | - 'charset' => $wpdb->charset, |
|
187 | - 'collation' => $wpdb->collate, |
|
188 | - ) |
|
189 | - ); |
|
190 | - |
|
191 | - $this->db->run(); |
|
192 | - |
|
193 | - $this->app->singleton( |
|
194 | - 'db', |
|
195 | - function () { |
|
196 | - return $this->db; |
|
197 | - } |
|
198 | - ); |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * Register providers. |
|
203 | - * |
|
204 | - * @since 1.0.0 |
|
205 | - * |
|
206 | - * @return void |
|
207 | - */ |
|
208 | - protected function register_providers() { |
|
209 | - $providers = $this->config->get( 'app.providers' ); |
|
210 | - |
|
211 | - if ( $providers && count( $providers ) > 0 ) { |
|
212 | - foreach ( $providers as $provider ) { |
|
213 | - with( new $provider( $this->app ) )->register(); |
|
214 | - } |
|
215 | - } |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Register request. |
|
220 | - * |
|
221 | - * @since 1.0.0 |
|
222 | - * |
|
223 | - * @return void |
|
224 | - */ |
|
225 | - protected function register_request() { |
|
226 | - $this->app->bind( |
|
227 | - Request::class, |
|
228 | - function ( $app ) { |
|
229 | - $request = Request::capture(); |
|
230 | - $wp_user = wp_get_current_user(); |
|
231 | - if ( $wp_user ) { |
|
232 | - $user = User::find( $wp_user->ID ); |
|
233 | - $request->merge( array( 'user' => $user ) ); |
|
234 | - $request->setUserResolver( |
|
235 | - function () use ( $user ) { |
|
236 | - return $user; |
|
237 | - } |
|
238 | - ); |
|
239 | - } |
|
240 | - |
|
241 | - return $request; |
|
242 | - } |
|
243 | - ); |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * Register router. |
|
248 | - * |
|
249 | - * @since 1.0.0 |
|
250 | - * |
|
251 | - * @return void |
|
252 | - */ |
|
253 | - protected function register_router() { |
|
254 | - $this->app->instance( \Illuminate\Routing\Router::class, $this->app['router'] ); |
|
255 | - $this->app->instance( \WPB\Router::class, $this->app['router'] ); |
|
256 | - $this->app->alias( 'Route', \WPB\Support\Facades\Route::class ); |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Get the config value. |
|
261 | - * |
|
262 | - * @since 1.0.0 |
|
263 | - * @param \Illuminate\Routing\Router $router The app router. |
|
264 | - * @param string $dir The custom routes directory. |
|
265 | - * |
|
266 | - * @return void |
|
267 | - */ |
|
268 | - public function load_routes( $router, $dir = null ) { |
|
269 | - if ( ! $dir ) { |
|
270 | - $dir = __DIR__ . '/../routes/'; |
|
271 | - } |
|
272 | - |
|
273 | - require $dir . 'web.php'; |
|
274 | - |
|
275 | - $router->group( |
|
276 | - array( 'prefix' => 'api' ), |
|
277 | - function () use ( $dir, $router ) { |
|
278 | - require $dir . 'api.php'; |
|
279 | - } |
|
280 | - ); |
|
281 | - } |
|
33 | + /** |
|
34 | + * The app container. |
|
35 | + * |
|
36 | + * @since 1.0.0 |
|
37 | + * @access protected |
|
38 | + * @var \Illuminate\Contracts\Container\Container $app The app container. |
|
39 | + */ |
|
40 | + protected $app = null; |
|
41 | + |
|
42 | + /** |
|
43 | + * The config. |
|
44 | + * |
|
45 | + * @since 1.0.0 |
|
46 | + * @access protected |
|
47 | + * @var \WPB\Support\Facades\Config $config The config. |
|
48 | + */ |
|
49 | + protected $config; |
|
50 | + |
|
51 | + /** |
|
52 | + * The database manager. |
|
53 | + * |
|
54 | + * @since 1.0.0 |
|
55 | + * @access protected |
|
56 | + * @var \CodexShaper\Database\Database $db The database manager. |
|
57 | + */ |
|
58 | + protected $db; |
|
59 | + |
|
60 | + /** |
|
61 | + * The default options. |
|
62 | + * |
|
63 | + * @since 1.0.0 |
|
64 | + * @access protected |
|
65 | + * @var array $options The default options. |
|
66 | + */ |
|
67 | + protected $options; |
|
68 | + |
|
69 | + /** |
|
70 | + * This string unique root path. |
|
71 | + * |
|
72 | + * @since 1.0.0 |
|
73 | + * @access protected |
|
74 | + * @var string $root This string unique root path. |
|
75 | + */ |
|
76 | + protected $root; |
|
77 | + |
|
78 | + /** |
|
79 | + * The application factory. |
|
80 | + * |
|
81 | + * @since 1.0.0 |
|
82 | + * @param array $options The site options. |
|
83 | + * @param \Illuminate\Contracts\Container\Container as ContainerInterface $container The app container. |
|
84 | + * |
|
85 | + * @return void |
|
86 | + */ |
|
87 | + public function __construct( $options = array(), ContainerInterface $container = null ) { |
|
88 | + $this->options = $options; |
|
89 | + |
|
90 | + $this->app = $container; |
|
91 | + |
|
92 | + if ( is_null( $this->app ) ) { |
|
93 | + $this->app = new Container(); |
|
94 | + Facade::setFacadeApplication( $this->app ); |
|
95 | + $this->app->instance( ContainerInterface::class, $this->app ); |
|
96 | + } |
|
97 | + |
|
98 | + $this->app['app'] = $this->app; |
|
99 | + |
|
100 | + $this->root = __DIR__ . '/../../../../'; |
|
101 | + |
|
102 | + if ( ! empty( $this->options ) && isset( $this->options['paths']['root'] ) ) { |
|
103 | + $this->root = rtrim( $this->options['paths']['root'], '/' ) . '/'; |
|
104 | + } |
|
105 | + |
|
106 | + if ( ! isset( $this->app['root'] ) ) { |
|
107 | + $this->app['root'] = $this->root; |
|
108 | + } |
|
109 | + |
|
110 | + $this->config = new Config( $this->options ); |
|
111 | + |
|
112 | + $this->setup_env(); |
|
113 | + $this->register_config(); |
|
114 | + $this->setup_database(); |
|
115 | + $this->register_providers(); |
|
116 | + $this->register_request(); |
|
117 | + $this->register_router(); |
|
118 | + $this->load_routes( $this->app['router'] ); |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Get the app container. |
|
123 | + * |
|
124 | + * @since 1.0.0 |
|
125 | + * |
|
126 | + * @return \Illuminate\Container\Container |
|
127 | + */ |
|
128 | + public function get_instance() { |
|
129 | + if ( ! $this->app ) { |
|
130 | + new self(); |
|
131 | + } |
|
132 | + |
|
133 | + return $this->app; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Setup the env. |
|
138 | + * |
|
139 | + * @since 1.0.0 |
|
140 | + * |
|
141 | + * @return void |
|
142 | + */ |
|
143 | + protected function setup_env() { |
|
144 | + $this->app['env'] = $this->config->get( 'app.env' ); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Register config. |
|
149 | + * |
|
150 | + * @since 1.0.0 |
|
151 | + * |
|
152 | + * @return void |
|
153 | + */ |
|
154 | + protected function register_config() { |
|
155 | + $this->app->bind( |
|
156 | + 'config', |
|
157 | + function () { |
|
158 | + return array( |
|
159 | + 'app' => $this->config->get( 'app' ), |
|
160 | + 'view.paths' => $this->config->get( 'view.paths' ), |
|
161 | + 'view.compiled' => $this->config->get( 'view.compiled' ), |
|
162 | + ); |
|
163 | + }, |
|
164 | + true |
|
165 | + ); |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Setup the database. |
|
170 | + * |
|
171 | + * @since 1.0.0 |
|
172 | + * |
|
173 | + * @return void |
|
174 | + */ |
|
175 | + protected function setup_database() { |
|
176 | + global $wpdb; |
|
177 | + |
|
178 | + $this->db = new Database( |
|
179 | + array( |
|
180 | + 'driver' => 'mysql', |
|
181 | + 'host' => $wpdb->dbhost, |
|
182 | + 'database' => $wpdb->dbname, |
|
183 | + 'username' => $wpdb->dbuser, |
|
184 | + 'password' => $wpdb->dbpassword, |
|
185 | + 'prefix' => $wpdb->prefix, |
|
186 | + 'charset' => $wpdb->charset, |
|
187 | + 'collation' => $wpdb->collate, |
|
188 | + ) |
|
189 | + ); |
|
190 | + |
|
191 | + $this->db->run(); |
|
192 | + |
|
193 | + $this->app->singleton( |
|
194 | + 'db', |
|
195 | + function () { |
|
196 | + return $this->db; |
|
197 | + } |
|
198 | + ); |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * Register providers. |
|
203 | + * |
|
204 | + * @since 1.0.0 |
|
205 | + * |
|
206 | + * @return void |
|
207 | + */ |
|
208 | + protected function register_providers() { |
|
209 | + $providers = $this->config->get( 'app.providers' ); |
|
210 | + |
|
211 | + if ( $providers && count( $providers ) > 0 ) { |
|
212 | + foreach ( $providers as $provider ) { |
|
213 | + with( new $provider( $this->app ) )->register(); |
|
214 | + } |
|
215 | + } |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Register request. |
|
220 | + * |
|
221 | + * @since 1.0.0 |
|
222 | + * |
|
223 | + * @return void |
|
224 | + */ |
|
225 | + protected function register_request() { |
|
226 | + $this->app->bind( |
|
227 | + Request::class, |
|
228 | + function ( $app ) { |
|
229 | + $request = Request::capture(); |
|
230 | + $wp_user = wp_get_current_user(); |
|
231 | + if ( $wp_user ) { |
|
232 | + $user = User::find( $wp_user->ID ); |
|
233 | + $request->merge( array( 'user' => $user ) ); |
|
234 | + $request->setUserResolver( |
|
235 | + function () use ( $user ) { |
|
236 | + return $user; |
|
237 | + } |
|
238 | + ); |
|
239 | + } |
|
240 | + |
|
241 | + return $request; |
|
242 | + } |
|
243 | + ); |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * Register router. |
|
248 | + * |
|
249 | + * @since 1.0.0 |
|
250 | + * |
|
251 | + * @return void |
|
252 | + */ |
|
253 | + protected function register_router() { |
|
254 | + $this->app->instance( \Illuminate\Routing\Router::class, $this->app['router'] ); |
|
255 | + $this->app->instance( \WPB\Router::class, $this->app['router'] ); |
|
256 | + $this->app->alias( 'Route', \WPB\Support\Facades\Route::class ); |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Get the config value. |
|
261 | + * |
|
262 | + * @since 1.0.0 |
|
263 | + * @param \Illuminate\Routing\Router $router The app router. |
|
264 | + * @param string $dir The custom routes directory. |
|
265 | + * |
|
266 | + * @return void |
|
267 | + */ |
|
268 | + public function load_routes( $router, $dir = null ) { |
|
269 | + if ( ! $dir ) { |
|
270 | + $dir = __DIR__ . '/../routes/'; |
|
271 | + } |
|
272 | + |
|
273 | + require $dir . 'web.php'; |
|
274 | + |
|
275 | + $router->group( |
|
276 | + array( 'prefix' => 'api' ), |
|
277 | + function () use ( $dir, $router ) { |
|
278 | + require $dir . 'api.php'; |
|
279 | + } |
|
280 | + ); |
|
281 | + } |
|
282 | 282 | } |
@@ -84,30 +84,30 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @return void |
86 | 86 | */ |
87 | - public function __construct( $options = array(), ContainerInterface $container = null ) { |
|
87 | + public function __construct($options = array(), ContainerInterface $container = null) { |
|
88 | 88 | $this->options = $options; |
89 | 89 | |
90 | 90 | $this->app = $container; |
91 | 91 | |
92 | - if ( is_null( $this->app ) ) { |
|
92 | + if (is_null($this->app)) { |
|
93 | 93 | $this->app = new Container(); |
94 | - Facade::setFacadeApplication( $this->app ); |
|
95 | - $this->app->instance( ContainerInterface::class, $this->app ); |
|
94 | + Facade::setFacadeApplication($this->app); |
|
95 | + $this->app->instance(ContainerInterface::class, $this->app); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | $this->app['app'] = $this->app; |
99 | 99 | |
100 | - $this->root = __DIR__ . '/../../../../'; |
|
100 | + $this->root = __DIR__.'/../../../../'; |
|
101 | 101 | |
102 | - if ( ! empty( $this->options ) && isset( $this->options['paths']['root'] ) ) { |
|
103 | - $this->root = rtrim( $this->options['paths']['root'], '/' ) . '/'; |
|
102 | + if (!empty($this->options) && isset($this->options['paths']['root'])) { |
|
103 | + $this->root = rtrim($this->options['paths']['root'], '/').'/'; |
|
104 | 104 | } |
105 | 105 | |
106 | - if ( ! isset( $this->app['root'] ) ) { |
|
106 | + if (!isset($this->app['root'])) { |
|
107 | 107 | $this->app['root'] = $this->root; |
108 | 108 | } |
109 | 109 | |
110 | - $this->config = new Config( $this->options ); |
|
110 | + $this->config = new Config($this->options); |
|
111 | 111 | |
112 | 112 | $this->setup_env(); |
113 | 113 | $this->register_config(); |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | $this->register_providers(); |
116 | 116 | $this->register_request(); |
117 | 117 | $this->register_router(); |
118 | - $this->load_routes( $this->app['router'] ); |
|
118 | + $this->load_routes($this->app['router']); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @return \Illuminate\Container\Container |
127 | 127 | */ |
128 | 128 | public function get_instance() { |
129 | - if ( ! $this->app ) { |
|
129 | + if (!$this->app) { |
|
130 | 130 | new self(); |
131 | 131 | } |
132 | 132 | |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | * @return void |
142 | 142 | */ |
143 | 143 | protected function setup_env() { |
144 | - $this->app['env'] = $this->config->get( 'app.env' ); |
|
144 | + $this->app['env'] = $this->config->get('app.env'); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | protected function register_config() { |
155 | 155 | $this->app->bind( |
156 | 156 | 'config', |
157 | - function () { |
|
157 | + function() { |
|
158 | 158 | return array( |
159 | - 'app' => $this->config->get( 'app' ), |
|
160 | - 'view.paths' => $this->config->get( 'view.paths' ), |
|
161 | - 'view.compiled' => $this->config->get( 'view.compiled' ), |
|
159 | + 'app' => $this->config->get('app'), |
|
160 | + 'view.paths' => $this->config->get('view.paths'), |
|
161 | + 'view.compiled' => $this->config->get('view.compiled'), |
|
162 | 162 | ); |
163 | 163 | }, |
164 | 164 | true |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | |
193 | 193 | $this->app->singleton( |
194 | 194 | 'db', |
195 | - function () { |
|
195 | + function() { |
|
196 | 196 | return $this->db; |
197 | 197 | } |
198 | 198 | ); |
@@ -206,11 +206,11 @@ discard block |
||
206 | 206 | * @return void |
207 | 207 | */ |
208 | 208 | protected function register_providers() { |
209 | - $providers = $this->config->get( 'app.providers' ); |
|
209 | + $providers = $this->config->get('app.providers'); |
|
210 | 210 | |
211 | - if ( $providers && count( $providers ) > 0 ) { |
|
212 | - foreach ( $providers as $provider ) { |
|
213 | - with( new $provider( $this->app ) )->register(); |
|
211 | + if ($providers && count($providers) > 0) { |
|
212 | + foreach ($providers as $provider) { |
|
213 | + with(new $provider($this->app))->register(); |
|
214 | 214 | } |
215 | 215 | } |
216 | 216 | } |
@@ -225,14 +225,14 @@ discard block |
||
225 | 225 | protected function register_request() { |
226 | 226 | $this->app->bind( |
227 | 227 | Request::class, |
228 | - function ( $app ) { |
|
228 | + function($app) { |
|
229 | 229 | $request = Request::capture(); |
230 | 230 | $wp_user = wp_get_current_user(); |
231 | - if ( $wp_user ) { |
|
232 | - $user = User::find( $wp_user->ID ); |
|
233 | - $request->merge( array( 'user' => $user ) ); |
|
231 | + if ($wp_user) { |
|
232 | + $user = User::find($wp_user->ID); |
|
233 | + $request->merge(array('user' => $user)); |
|
234 | 234 | $request->setUserResolver( |
235 | - function () use ( $user ) { |
|
235 | + function() use ($user) { |
|
236 | 236 | return $user; |
237 | 237 | } |
238 | 238 | ); |
@@ -251,9 +251,9 @@ discard block |
||
251 | 251 | * @return void |
252 | 252 | */ |
253 | 253 | protected function register_router() { |
254 | - $this->app->instance( \Illuminate\Routing\Router::class, $this->app['router'] ); |
|
255 | - $this->app->instance( \WPB\Router::class, $this->app['router'] ); |
|
256 | - $this->app->alias( 'Route', \WPB\Support\Facades\Route::class ); |
|
254 | + $this->app->instance(\Illuminate\Routing\Router::class, $this->app['router']); |
|
255 | + $this->app->instance(\WPB\Router::class, $this->app['router']); |
|
256 | + $this->app->alias('Route', \WPB\Support\Facades\Route::class); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
@@ -265,17 +265,17 @@ discard block |
||
265 | 265 | * |
266 | 266 | * @return void |
267 | 267 | */ |
268 | - public function load_routes( $router, $dir = null ) { |
|
269 | - if ( ! $dir ) { |
|
270 | - $dir = __DIR__ . '/../routes/'; |
|
268 | + public function load_routes($router, $dir = null) { |
|
269 | + if (!$dir) { |
|
270 | + $dir = __DIR__.'/../routes/'; |
|
271 | 271 | } |
272 | 272 | |
273 | - require $dir . 'web.php'; |
|
273 | + require $dir.'web.php'; |
|
274 | 274 | |
275 | 275 | $router->group( |
276 | - array( 'prefix' => 'api' ), |
|
277 | - function () use ( $dir, $router ) { |
|
278 | - require $dir . 'api.php'; |
|
276 | + array('prefix' => 'api'), |
|
277 | + function() use ($dir, $router) { |
|
278 | + require $dir.'api.php'; |
|
279 | 279 | } |
280 | 280 | ); |
281 | 281 | } |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | * @param \Composer\Script\Event $event The composer event. |
34 | 34 | * @return void |
35 | 35 | */ |
36 | - public static function post_install( Event $event ) { |
|
37 | - require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
36 | + public static function post_install(Event $event) { |
|
37 | + require_once $event->getComposer()->getConfig()->get('vendor-dir').'/autoload.php'; |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | * @param \Composer\Script\Event $event The composer event. |
44 | 44 | * @return void |
45 | 45 | */ |
46 | - public static function post_update( Event $event ) { |
|
47 | - require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
46 | + public static function post_update(Event $event) { |
|
47 | + require_once $event->getComposer()->getConfig()->get('vendor-dir').'/autoload.php'; |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -53,20 +53,20 @@ discard block |
||
53 | 53 | * @param \Composer\Script\Event $event The composer event. |
54 | 54 | * @return void |
55 | 55 | */ |
56 | - public static function post_autoload_dump( Event $event ) { |
|
57 | - require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
56 | + public static function post_autoload_dump(Event $event) { |
|
57 | + require_once $event->getComposer()->getConfig()->get('vendor-dir').'/autoload.php'; |
|
58 | 58 | |
59 | - $dir = $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/../'; |
|
60 | - $root = dirname( $event->getComposer()->getConfig()->get( 'vendor-dir' ) ); |
|
59 | + $dir = $event->getComposer()->getConfig()->get('vendor-dir').'/../'; |
|
60 | + $root = dirname($event->getComposer()->getConfig()->get('vendor-dir')); |
|
61 | 61 | |
62 | - $vendor_name = strtolower( basename( $root ) ); |
|
63 | - $partials = explode( '-', $vendor_name ); |
|
62 | + $vendor_name = strtolower(basename($root)); |
|
63 | + $partials = explode('-', $vendor_name); |
|
64 | 64 | $camel_case_partials = array(); |
65 | - foreach ( $partials as $partial ) { |
|
66 | - $camel_case_partials[] = ucfirst( strtolower( $partial ) ); |
|
65 | + foreach ($partials as $partial) { |
|
66 | + $camel_case_partials[] = ucfirst(strtolower($partial)); |
|
67 | 67 | } |
68 | - $camel_case = implode( '_', $camel_case_partials ); |
|
69 | - $snake_case = implode( '_', $partials ); |
|
68 | + $camel_case = implode('_', $camel_case_partials); |
|
69 | + $snake_case = implode('_', $partials); |
|
70 | 70 | |
71 | 71 | $files = array( |
72 | 72 | '/admin/class-wpb-admin.php', |
@@ -116,39 +116,39 @@ discard block |
||
116 | 116 | '/wpb.php', |
117 | 117 | ); |
118 | 118 | |
119 | - foreach ( $files as $file ) { |
|
120 | - $file = $root . $file; |
|
121 | - if ( file_exists( $file ) ) { |
|
119 | + foreach ($files as $file) { |
|
120 | + $file = $root.$file; |
|
121 | + if (file_exists($file)) { |
|
122 | 122 | |
123 | 123 | $filesystem = new Filesystem(); |
124 | 124 | |
125 | - $contents = $filesystem->get( $file ); |
|
126 | - $contents = str_replace( 'wpb_', $snake_case . '_', $contents ); |
|
127 | - $contents = str_replace( 'wpb', $vendor_name, $contents ); |
|
128 | - $contents = str_replace( 'WPB_APP_ROOT', strtoupper( $camel_case ) . '_APP_ROOT', $contents ); |
|
129 | - $contents = str_replace( 'WPB_FILE', strtoupper( $camel_case ) . '_FILE', $contents ); |
|
130 | - $contents = str_replace( 'WPB_PATH', strtoupper( $camel_case ) . '_PATH', $contents ); |
|
131 | - $contents = str_replace( 'WPB_INCLUDES', strtoupper( $camel_case ) . '_INCLUDES', $contents ); |
|
132 | - $contents = str_replace( 'WPB_URL', strtoupper( $camel_case ) . '_URL', $contents ); |
|
133 | - $contents = str_replace( 'WPB_ASSETS', strtoupper( $camel_case ) . '_ASSETS', $contents ); |
|
134 | - $contents = str_replace( 'WPB_VERSION', strtoupper( $camel_case ) . '_VERSION', $contents ); |
|
135 | - $contents = str_replace( 'WPB', $camel_case, $contents ); |
|
125 | + $contents = $filesystem->get($file); |
|
126 | + $contents = str_replace('wpb_', $snake_case.'_', $contents); |
|
127 | + $contents = str_replace('wpb', $vendor_name, $contents); |
|
128 | + $contents = str_replace('WPB_APP_ROOT', strtoupper($camel_case).'_APP_ROOT', $contents); |
|
129 | + $contents = str_replace('WPB_FILE', strtoupper($camel_case).'_FILE', $contents); |
|
130 | + $contents = str_replace('WPB_PATH', strtoupper($camel_case).'_PATH', $contents); |
|
131 | + $contents = str_replace('WPB_INCLUDES', strtoupper($camel_case).'_INCLUDES', $contents); |
|
132 | + $contents = str_replace('WPB_URL', strtoupper($camel_case).'_URL', $contents); |
|
133 | + $contents = str_replace('WPB_ASSETS', strtoupper($camel_case).'_ASSETS', $contents); |
|
134 | + $contents = str_replace('WPB_VERSION', strtoupper($camel_case).'_VERSION', $contents); |
|
135 | + $contents = str_replace('WPB', $camel_case, $contents); |
|
136 | 136 | $filesystem->put( |
137 | 137 | $file, |
138 | 138 | $contents |
139 | 139 | ); |
140 | 140 | |
141 | - $dir = dirname( $file ); |
|
142 | - $file_name = basename( $file ); |
|
143 | - $new_file_name = str_replace( 'wpb', $vendor_name, $file_name ); |
|
141 | + $dir = dirname($file); |
|
142 | + $file_name = basename($file); |
|
143 | + $new_file_name = str_replace('wpb', $vendor_name, $file_name); |
|
144 | 144 | |
145 | - if ( $file_name !== $new_file_name ) { |
|
146 | - rename( $file, $dir . '/' . $new_file_name ); |
|
145 | + if ($file_name !== $new_file_name) { |
|
146 | + rename($file, $dir.'/'.$new_file_name); |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
151 | - static::update_composer( $filesystem, $root, $camel_case ); |
|
151 | + static::update_composer($filesystem, $root, $camel_case); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
@@ -163,11 +163,11 @@ discard block |
||
163 | 163 | * |
164 | 164 | * @return void |
165 | 165 | */ |
166 | - protected static function update_bootstrap( $filesystem, $root, $camel_case ) { |
|
167 | - $file = $root . '/bootstrap/app.php'; |
|
168 | - if ( file_exists( $file ) ) { |
|
169 | - $contents = $filesystem->get( $file ); |
|
170 | - $contents = str_replace( 'WPB_APP_ROOT', strtoupper( $camel_case ) . '_APP_ROOT', $contents ); |
|
166 | + protected static function update_bootstrap($filesystem, $root, $camel_case) { |
|
167 | + $file = $root.'/bootstrap/app.php'; |
|
168 | + if (file_exists($file)) { |
|
169 | + $contents = $filesystem->get($file); |
|
170 | + $contents = str_replace('WPB_APP_ROOT', strtoupper($camel_case).'_APP_ROOT', $contents); |
|
171 | 171 | $filesystem->put( |
172 | 172 | $file, |
173 | 173 | $contents |
@@ -185,11 +185,11 @@ discard block |
||
185 | 185 | * |
186 | 186 | * @return void |
187 | 187 | */ |
188 | - protected static function update_composer( $filesystem, $root, $camel_case ) { |
|
189 | - $file = $root . '/composer.json'; |
|
190 | - if ( file_exists( $file ) ) { |
|
191 | - $contents = $filesystem->get( $file ); |
|
192 | - $contents = str_replace( 'WPB', $camel_case, $contents ); |
|
188 | + protected static function update_composer($filesystem, $root, $camel_case) { |
|
189 | + $file = $root.'/composer.json'; |
|
190 | + if (file_exists($file)) { |
|
191 | + $contents = $filesystem->get($file); |
|
192 | + $contents = str_replace('WPB', $camel_case, $contents); |
|
193 | 193 | $filesystem->put( |
194 | 194 | $file, |
195 | 195 | $contents |
@@ -27,176 +27,176 @@ |
||
27 | 27 | */ |
28 | 28 | class ComposerScripts { |
29 | 29 | |
30 | - /** |
|
31 | - * Handle the post-install Composer event. |
|
32 | - * |
|
33 | - * @param \Composer\Script\Event $event The composer event. |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public static function post_install( Event $event ) { |
|
37 | - require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Handle the post-update Composer event. |
|
42 | - * |
|
43 | - * @param \Composer\Script\Event $event The composer event. |
|
44 | - * @return void |
|
45 | - */ |
|
46 | - public static function post_update( Event $event ) { |
|
47 | - require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Handle the post-autoload-dump Composer event. |
|
52 | - * |
|
53 | - * @param \Composer\Script\Event $event The composer event. |
|
54 | - * @return void |
|
55 | - */ |
|
56 | - public static function post_autoload_dump( Event $event ) { |
|
57 | - require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
58 | - |
|
59 | - $dir = $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/../'; |
|
60 | - $root = dirname( $event->getComposer()->getConfig()->get( 'vendor-dir' ) ); |
|
61 | - |
|
62 | - $vendor_name = strtolower( basename( $root ) ); |
|
63 | - $partials = explode( '-', $vendor_name ); |
|
64 | - $camel_case_partials = array(); |
|
65 | - foreach ( $partials as $partial ) { |
|
66 | - $camel_case_partials[] = ucfirst( strtolower( $partial ) ); |
|
67 | - } |
|
68 | - $camel_case = implode( '_', $camel_case_partials ); |
|
69 | - $snake_case = implode( '_', $partials ); |
|
70 | - |
|
71 | - $files = array( |
|
72 | - '/admin/class-wpb-admin.php', |
|
73 | - '/admin/class-wpb-admin-menu.php', |
|
74 | - '/admin/class-wpb-admin-submenu.php', |
|
75 | - '/admin/partials/wpb-admin-display.php', |
|
76 | - '/admin/css/wpb-admin.css', |
|
77 | - '/admin/js/wpb-admin.js', |
|
78 | - '/app/Exceptions/Handler.php', |
|
79 | - '/app/Http/Controllers/ProductController.php', |
|
80 | - '/app/Http/Middleware/AuthMiddleware.php', |
|
81 | - '/app/Http/Middleware/VerifyCsrfToken.php', |
|
82 | - '/app/Http/Kernel.php', |
|
83 | - '/app/User.php', |
|
84 | - '/app/Post.php', |
|
85 | - '/bootstrap/app.php', |
|
86 | - '/config/app.php', |
|
87 | - '/config/database.php', |
|
88 | - '/config/view.php', |
|
89 | - '/database/migrations/class-create-customers-table.php', |
|
90 | - '/database/seeds/class-customers-table.php', |
|
91 | - '/includes/class-wpb-activator.php', |
|
92 | - '/includes/class-wpb-deactivator.php', |
|
93 | - '/includes/class-wpb-i18n.php', |
|
94 | - '/includes/class-wpb-loader.php', |
|
95 | - '/includes/class-wpb.php', |
|
96 | - '/public/class-wpb-public.php', |
|
97 | - '/public/partials/wpb-public-display.php', |
|
98 | - '/public/css/wpb-public.css', |
|
99 | - '/public/js/wpb-public.js', |
|
100 | - '/resources/js/admin/main.js', |
|
101 | - '/resources/js/frontend/main.js', |
|
102 | - '/resources/js/spa/main.js', |
|
103 | - '/routes/web.php', |
|
104 | - '/routes/api.php', |
|
105 | - '/src/Contracts/Http/Kernel.php', |
|
106 | - '/src/Contracts/ExceptionHandler.php', |
|
107 | - '/src/Database/Eloquent/Scopes/PostAuthorScope.php', |
|
108 | - '/src/Database/Eloquent/Scopes/PostStatusScope.php', |
|
109 | - '/src/Database/Eloquent/Scopes/PostTypeScope.php', |
|
110 | - '/src/Database/DB.php', |
|
111 | - '/src/Exceptions/Handler.php', |
|
112 | - '/src/Http/Events/RequestHandler.php', |
|
113 | - '/src/Http/Kernel.php', |
|
114 | - '/src/helpers.php', |
|
115 | - '/src/Support/Facades/Config.php', |
|
116 | - '/src/Support/Facades/Route.php', |
|
117 | - '/src/Application.php', |
|
118 | - '/tests/Application.php', |
|
119 | - '/wpb.php', |
|
120 | - ); |
|
121 | - |
|
122 | - foreach ( $files as $file ) { |
|
123 | - $file = $root . $file; |
|
124 | - if ( file_exists( $file ) ) { |
|
125 | - |
|
126 | - $filesystem = new Filesystem(); |
|
127 | - |
|
128 | - $contents = $filesystem->get( $file ); |
|
129 | - $contents = str_replace( 'wpb_', $snake_case . '_', $contents ); |
|
130 | - $contents = str_replace( 'wpb', $vendor_name, $contents ); |
|
131 | - $contents = str_replace( 'WPB_APP_ROOT', strtoupper( $camel_case ) . '_APP_ROOT', $contents ); |
|
132 | - $contents = str_replace( 'WPB_FILE', strtoupper( $camel_case ) . '_FILE', $contents ); |
|
133 | - $contents = str_replace( 'WPB_PATH', strtoupper( $camel_case ) . '_PATH', $contents ); |
|
134 | - $contents = str_replace( 'WPB_INCLUDES', strtoupper( $camel_case ) . '_INCLUDES', $contents ); |
|
135 | - $contents = str_replace( 'WPB_URL', strtoupper( $camel_case ) . '_URL', $contents ); |
|
136 | - $contents = str_replace( 'WPB_ASSETS', strtoupper( $camel_case ) . '_ASSETS', $contents ); |
|
137 | - $contents = str_replace( 'WPB_VERSION', strtoupper( $camel_case ) . '_VERSION', $contents ); |
|
138 | - $contents = str_replace( 'WPB', $camel_case, $contents ); |
|
139 | - $filesystem->put( |
|
140 | - $file, |
|
141 | - $contents |
|
142 | - ); |
|
143 | - |
|
144 | - $dir = dirname( $file ); |
|
145 | - $file_name = basename( $file ); |
|
146 | - $new_file_name = str_replace( 'wpb', $vendor_name, $file_name ); |
|
147 | - |
|
148 | - if ( $file_name !== $new_file_name ) { |
|
149 | - rename( $file, $dir . '/' . $new_file_name ); |
|
150 | - } |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - static::update_composer( $filesystem, $root, $camel_case ); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Replace bootstrap file. |
|
159 | - * |
|
160 | - * @since 1.0.0 |
|
161 | - * @access public |
|
162 | - * |
|
163 | - * @param Illuminate\Filesystem\Filesystem $filesystem The illuminate filesystem. |
|
164 | - * @param string $root The string is unique root path for each plugin. |
|
165 | - * @param string $camel_case This string is camel case of project name. |
|
166 | - * |
|
167 | - * @return void |
|
168 | - */ |
|
169 | - protected static function update_bootstrap( $filesystem, $root, $camel_case ) { |
|
170 | - $file = $root . '/bootstrap/app.php'; |
|
171 | - if ( file_exists( $file ) ) { |
|
172 | - $contents = $filesystem->get( $file ); |
|
173 | - $contents = str_replace( 'WPB_APP_ROOT', strtoupper( $camel_case ) . '_APP_ROOT', $contents ); |
|
174 | - $filesystem->put( |
|
175 | - $file, |
|
176 | - $contents |
|
177 | - ); |
|
178 | - |
|
179 | - } |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * Update composer. |
|
184 | - * |
|
185 | - * @param Illuminate\Filesystem\Filesystem $filesystem The illuminate filesystem. |
|
186 | - * @param string $root The app root. |
|
187 | - * @param string $camel_case The composer event. |
|
188 | - * |
|
189 | - * @return void |
|
190 | - */ |
|
191 | - protected static function update_composer( $filesystem, $root, $camel_case ) { |
|
192 | - $file = $root . '/composer.json'; |
|
193 | - if ( file_exists( $file ) ) { |
|
194 | - $contents = $filesystem->get( $file ); |
|
195 | - $contents = str_replace( 'WPB', $camel_case, $contents ); |
|
196 | - $filesystem->put( |
|
197 | - $file, |
|
198 | - $contents |
|
199 | - ); |
|
200 | - } |
|
201 | - } |
|
30 | + /** |
|
31 | + * Handle the post-install Composer event. |
|
32 | + * |
|
33 | + * @param \Composer\Script\Event $event The composer event. |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public static function post_install( Event $event ) { |
|
37 | + require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * Handle the post-update Composer event. |
|
42 | + * |
|
43 | + * @param \Composer\Script\Event $event The composer event. |
|
44 | + * @return void |
|
45 | + */ |
|
46 | + public static function post_update( Event $event ) { |
|
47 | + require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Handle the post-autoload-dump Composer event. |
|
52 | + * |
|
53 | + * @param \Composer\Script\Event $event The composer event. |
|
54 | + * @return void |
|
55 | + */ |
|
56 | + public static function post_autoload_dump( Event $event ) { |
|
57 | + require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
58 | + |
|
59 | + $dir = $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/../'; |
|
60 | + $root = dirname( $event->getComposer()->getConfig()->get( 'vendor-dir' ) ); |
|
61 | + |
|
62 | + $vendor_name = strtolower( basename( $root ) ); |
|
63 | + $partials = explode( '-', $vendor_name ); |
|
64 | + $camel_case_partials = array(); |
|
65 | + foreach ( $partials as $partial ) { |
|
66 | + $camel_case_partials[] = ucfirst( strtolower( $partial ) ); |
|
67 | + } |
|
68 | + $camel_case = implode( '_', $camel_case_partials ); |
|
69 | + $snake_case = implode( '_', $partials ); |
|
70 | + |
|
71 | + $files = array( |
|
72 | + '/admin/class-wpb-admin.php', |
|
73 | + '/admin/class-wpb-admin-menu.php', |
|
74 | + '/admin/class-wpb-admin-submenu.php', |
|
75 | + '/admin/partials/wpb-admin-display.php', |
|
76 | + '/admin/css/wpb-admin.css', |
|
77 | + '/admin/js/wpb-admin.js', |
|
78 | + '/app/Exceptions/Handler.php', |
|
79 | + '/app/Http/Controllers/ProductController.php', |
|
80 | + '/app/Http/Middleware/AuthMiddleware.php', |
|
81 | + '/app/Http/Middleware/VerifyCsrfToken.php', |
|
82 | + '/app/Http/Kernel.php', |
|
83 | + '/app/User.php', |
|
84 | + '/app/Post.php', |
|
85 | + '/bootstrap/app.php', |
|
86 | + '/config/app.php', |
|
87 | + '/config/database.php', |
|
88 | + '/config/view.php', |
|
89 | + '/database/migrations/class-create-customers-table.php', |
|
90 | + '/database/seeds/class-customers-table.php', |
|
91 | + '/includes/class-wpb-activator.php', |
|
92 | + '/includes/class-wpb-deactivator.php', |
|
93 | + '/includes/class-wpb-i18n.php', |
|
94 | + '/includes/class-wpb-loader.php', |
|
95 | + '/includes/class-wpb.php', |
|
96 | + '/public/class-wpb-public.php', |
|
97 | + '/public/partials/wpb-public-display.php', |
|
98 | + '/public/css/wpb-public.css', |
|
99 | + '/public/js/wpb-public.js', |
|
100 | + '/resources/js/admin/main.js', |
|
101 | + '/resources/js/frontend/main.js', |
|
102 | + '/resources/js/spa/main.js', |
|
103 | + '/routes/web.php', |
|
104 | + '/routes/api.php', |
|
105 | + '/src/Contracts/Http/Kernel.php', |
|
106 | + '/src/Contracts/ExceptionHandler.php', |
|
107 | + '/src/Database/Eloquent/Scopes/PostAuthorScope.php', |
|
108 | + '/src/Database/Eloquent/Scopes/PostStatusScope.php', |
|
109 | + '/src/Database/Eloquent/Scopes/PostTypeScope.php', |
|
110 | + '/src/Database/DB.php', |
|
111 | + '/src/Exceptions/Handler.php', |
|
112 | + '/src/Http/Events/RequestHandler.php', |
|
113 | + '/src/Http/Kernel.php', |
|
114 | + '/src/helpers.php', |
|
115 | + '/src/Support/Facades/Config.php', |
|
116 | + '/src/Support/Facades/Route.php', |
|
117 | + '/src/Application.php', |
|
118 | + '/tests/Application.php', |
|
119 | + '/wpb.php', |
|
120 | + ); |
|
121 | + |
|
122 | + foreach ( $files as $file ) { |
|
123 | + $file = $root . $file; |
|
124 | + if ( file_exists( $file ) ) { |
|
125 | + |
|
126 | + $filesystem = new Filesystem(); |
|
127 | + |
|
128 | + $contents = $filesystem->get( $file ); |
|
129 | + $contents = str_replace( 'wpb_', $snake_case . '_', $contents ); |
|
130 | + $contents = str_replace( 'wpb', $vendor_name, $contents ); |
|
131 | + $contents = str_replace( 'WPB_APP_ROOT', strtoupper( $camel_case ) . '_APP_ROOT', $contents ); |
|
132 | + $contents = str_replace( 'WPB_FILE', strtoupper( $camel_case ) . '_FILE', $contents ); |
|
133 | + $contents = str_replace( 'WPB_PATH', strtoupper( $camel_case ) . '_PATH', $contents ); |
|
134 | + $contents = str_replace( 'WPB_INCLUDES', strtoupper( $camel_case ) . '_INCLUDES', $contents ); |
|
135 | + $contents = str_replace( 'WPB_URL', strtoupper( $camel_case ) . '_URL', $contents ); |
|
136 | + $contents = str_replace( 'WPB_ASSETS', strtoupper( $camel_case ) . '_ASSETS', $contents ); |
|
137 | + $contents = str_replace( 'WPB_VERSION', strtoupper( $camel_case ) . '_VERSION', $contents ); |
|
138 | + $contents = str_replace( 'WPB', $camel_case, $contents ); |
|
139 | + $filesystem->put( |
|
140 | + $file, |
|
141 | + $contents |
|
142 | + ); |
|
143 | + |
|
144 | + $dir = dirname( $file ); |
|
145 | + $file_name = basename( $file ); |
|
146 | + $new_file_name = str_replace( 'wpb', $vendor_name, $file_name ); |
|
147 | + |
|
148 | + if ( $file_name !== $new_file_name ) { |
|
149 | + rename( $file, $dir . '/' . $new_file_name ); |
|
150 | + } |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + static::update_composer( $filesystem, $root, $camel_case ); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Replace bootstrap file. |
|
159 | + * |
|
160 | + * @since 1.0.0 |
|
161 | + * @access public |
|
162 | + * |
|
163 | + * @param Illuminate\Filesystem\Filesystem $filesystem The illuminate filesystem. |
|
164 | + * @param string $root The string is unique root path for each plugin. |
|
165 | + * @param string $camel_case This string is camel case of project name. |
|
166 | + * |
|
167 | + * @return void |
|
168 | + */ |
|
169 | + protected static function update_bootstrap( $filesystem, $root, $camel_case ) { |
|
170 | + $file = $root . '/bootstrap/app.php'; |
|
171 | + if ( file_exists( $file ) ) { |
|
172 | + $contents = $filesystem->get( $file ); |
|
173 | + $contents = str_replace( 'WPB_APP_ROOT', strtoupper( $camel_case ) . '_APP_ROOT', $contents ); |
|
174 | + $filesystem->put( |
|
175 | + $file, |
|
176 | + $contents |
|
177 | + ); |
|
178 | + |
|
179 | + } |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * Update composer. |
|
184 | + * |
|
185 | + * @param Illuminate\Filesystem\Filesystem $filesystem The illuminate filesystem. |
|
186 | + * @param string $root The app root. |
|
187 | + * @param string $camel_case The composer event. |
|
188 | + * |
|
189 | + * @return void |
|
190 | + */ |
|
191 | + protected static function update_composer( $filesystem, $root, $camel_case ) { |
|
192 | + $file = $root . '/composer.json'; |
|
193 | + if ( file_exists( $file ) ) { |
|
194 | + $contents = $filesystem->get( $file ); |
|
195 | + $contents = str_replace( 'WPB', $camel_case, $contents ); |
|
196 | + $filesystem->put( |
|
197 | + $file, |
|
198 | + $contents |
|
199 | + ); |
|
200 | + } |
|
201 | + } |
|
202 | 202 | } |
@@ -21,62 +21,62 @@ |
||
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 | } |
@@ -38,16 +38,16 @@ discard block |
||
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 |
||
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 |
@@ -23,12 +23,12 @@ |
||
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 | } |
@@ -12,77 +12,77 @@ |
||
12 | 12 | use Illuminate\Container\Container; |
13 | 13 | |
14 | 14 | if ( ! function_exists( 'wpb_csrf_token' ) ) { |
15 | - /** |
|
16 | - * Generate wp nonce. |
|
17 | - * |
|
18 | - * @param string|null $action This is the nonce action name. |
|
19 | - * |
|
20 | - * @return null|string |
|
21 | - */ |
|
22 | - function wpb_csrf_token( $action = 'wpb_nonce' ) { |
|
23 | - return wp_create_nonce( $action ); |
|
24 | - } |
|
15 | + /** |
|
16 | + * Generate wp nonce. |
|
17 | + * |
|
18 | + * @param string|null $action This is the nonce action name. |
|
19 | + * |
|
20 | + * @return null|string |
|
21 | + */ |
|
22 | + function wpb_csrf_token( $action = 'wpb_nonce' ) { |
|
23 | + return wp_create_nonce( $action ); |
|
24 | + } |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | if ( ! function_exists( 'wpb_app' ) ) { |
28 | - /** |
|
29 | - * Get the available container instance. |
|
30 | - * |
|
31 | - * @param string|null $abstract The abstruct. |
|
32 | - * @param array $parameters The parameters. |
|
33 | - * |
|
34 | - * @return mixed|\Illuminate\Contracts\Foundation\Application |
|
35 | - */ |
|
36 | - function wpb_app( $abstract = null, array $parameters = array() ) { |
|
37 | - $app = new Application(); |
|
38 | - if ( is_null( $abstract ) && $container != null ) { |
|
39 | - return $container; |
|
40 | - } |
|
28 | + /** |
|
29 | + * Get the available container instance. |
|
30 | + * |
|
31 | + * @param string|null $abstract The abstruct. |
|
32 | + * @param array $parameters The parameters. |
|
33 | + * |
|
34 | + * @return mixed|\Illuminate\Contracts\Foundation\Application |
|
35 | + */ |
|
36 | + function wpb_app( $abstract = null, array $parameters = array() ) { |
|
37 | + $app = new Application(); |
|
38 | + if ( is_null( $abstract ) && $container != null ) { |
|
39 | + return $container; |
|
40 | + } |
|
41 | 41 | |
42 | - return Container::getInstance()->make( $abstract, $parameters ); |
|
43 | - } |
|
42 | + return Container::getInstance()->make( $abstract, $parameters ); |
|
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 | - } |
|
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 | 61 | |
62 | - if ( is_array( $key ) ) { |
|
63 | - return app( 'config' )->set( $key ); |
|
64 | - } |
|
62 | + if ( is_array( $key ) ) { |
|
63 | + return app( 'config' )->set( $key ); |
|
64 | + } |
|
65 | 65 | |
66 | - return app( 'config' )->get( $key, $default ); |
|
67 | - } |
|
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 | - } |
|
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 | 85 | |
86 | - return ( new \CodexShaper\Blade\View( array( __DIR__ . '/../resources/views' ), __DIR__ . '/../storage/cache' ) )->make( $view, $data = array(), $merge_data = array() ); |
|
87 | - } |
|
86 | + return ( new \CodexShaper\Blade\View( array( __DIR__ . '/../resources/views' ), __DIR__ . '/../storage/cache' ) )->make( $view, $data = array(), $merge_data = array() ); |
|
87 | + } |
|
88 | 88 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | use WPB\Application; |
12 | 12 | use Illuminate\Container\Container; |
13 | 13 | |
14 | -if ( ! function_exists( 'wpb_csrf_token' ) ) { |
|
14 | +if (!function_exists('wpb_csrf_token')) { |
|
15 | 15 | /** |
16 | 16 | * Generate wp nonce. |
17 | 17 | * |
@@ -19,12 +19,12 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @return null|string |
21 | 21 | */ |
22 | - function wpb_csrf_token( $action = 'wpb_nonce' ) { |
|
23 | - return wp_create_nonce( $action ); |
|
22 | + function wpb_csrf_token($action = 'wpb_nonce') { |
|
23 | + return wp_create_nonce($action); |
|
24 | 24 | } |
25 | 25 | } |
26 | 26 | |
27 | -if ( ! function_exists( 'wpb_app' ) ) { |
|
27 | +if (!function_exists('wpb_app')) { |
|
28 | 28 | /** |
29 | 29 | * Get the available container instance. |
30 | 30 | * |
@@ -33,17 +33,17 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @return mixed|\Illuminate\Contracts\Foundation\Application |
35 | 35 | */ |
36 | - function wpb_app( $abstract = null, array $parameters = array() ) { |
|
36 | + function wpb_app($abstract = null, array $parameters = array()) { |
|
37 | 37 | $app = new Application(); |
38 | - if ( is_null( $abstract ) && $container != null ) { |
|
38 | + if (is_null($abstract) && $container != null) { |
|
39 | 39 | return $container; |
40 | 40 | } |
41 | 41 | |
42 | - return Container::getInstance()->make( $abstract, $parameters ); |
|
42 | + return Container::getInstance()->make($abstract, $parameters); |
|
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 |
||
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,11 +78,11 @@ discard block |
||
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 | } |
@@ -54,516 +54,516 @@ |
||
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 | } |
@@ -101,7 +101,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -16,37 +16,37 @@ |
||
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 | $container = $app->get_instance(); |
27 | 27 | |
28 | 28 | $container->singleton( |
29 | - Illuminate\Contracts\Http\Kernel::class, |
|
30 | - \WPB\App\Http\Kernel::class |
|
29 | + Illuminate\Contracts\Http\Kernel::class, |
|
30 | + \WPB\App\Http\Kernel::class |
|
31 | 31 | ); |
32 | 32 | $container->singleton( |
33 | - \Illuminate\Contracts\Debug\ExceptionHandler::class, |
|
34 | - \WPB\App\Exceptions\Handler::class |
|
33 | + \Illuminate\Contracts\Debug\ExceptionHandler::class, |
|
34 | + \WPB\App\Exceptions\Handler::class |
|
35 | 35 | ); |
36 | 36 | |
37 | 37 | if ( \WPB\Support\Facades\Route::exists( \Illuminate\Http\Request::capture() ) ) { |
38 | - try { |
|
38 | + try { |
|
39 | 39 | |
40 | - $kernel = $container->make( \Illuminate\Contracts\Http\Kernel::class ); |
|
40 | + $kernel = $container->make( \Illuminate\Contracts\Http\Kernel::class ); |
|
41 | 41 | |
42 | - $response = $kernel->handle( \Illuminate\Http\Request::capture() ); |
|
42 | + $response = $kernel->handle( \Illuminate\Http\Request::capture() ); |
|
43 | 43 | |
44 | - $response->send(); |
|
44 | + $response->send(); |
|
45 | 45 | |
46 | - } catch ( \Exception $ex ) { |
|
47 | - if ( ! \WPB\Support\Facades\Route::current() ) { |
|
48 | - return true; |
|
49 | - } |
|
50 | - throw new \Exception( $ex, 1 ); |
|
51 | - } |
|
46 | + } catch ( \Exception $ex ) { |
|
47 | + if ( ! \WPB\Support\Facades\Route::current() ) { |
|
48 | + return true; |
|
49 | + } |
|
50 | + throw new \Exception( $ex, 1 ); |
|
51 | + } |
|
52 | 52 | } |
@@ -9,19 +9,19 @@ discard block |
||
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 | $container = $app->get_instance(); |
27 | 27 | |
@@ -34,19 +34,19 @@ discard block |
||
34 | 34 | \WPB\App\Exceptions\Handler::class |
35 | 35 | ); |
36 | 36 | |
37 | -if ( \WPB\Support\Facades\Route::exists( \Illuminate\Http\Request::capture() ) ) { |
|
37 | +if (\WPB\Support\Facades\Route::exists(\Illuminate\Http\Request::capture())) { |
|
38 | 38 | try { |
39 | 39 | |
40 | - $kernel = $container->make( \Illuminate\Contracts\Http\Kernel::class ); |
|
40 | + $kernel = $container->make(\Illuminate\Contracts\Http\Kernel::class); |
|
41 | 41 | |
42 | - $response = $kernel->handle( \Illuminate\Http\Request::capture() ); |
|
42 | + $response = $kernel->handle(\Illuminate\Http\Request::capture()); |
|
43 | 43 | |
44 | 44 | $response->send(); |
45 | 45 | |
46 | - } catch ( \Exception $ex ) { |
|
47 | - if ( ! \WPB\Support\Facades\Route::current() ) { |
|
46 | + } catch (\Exception $ex) { |
|
47 | + if (!\WPB\Support\Facades\Route::current()) { |
|
48 | 48 | return true; |
49 | 49 | } |
50 | - throw new \Exception( $ex, 1 ); |
|
50 | + throw new \Exception($ex, 1); |
|
51 | 51 | } |
52 | 52 | } |