From 88c67a7718f88a4115a75752c4f54a7e2902d348 Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Mon, 12 Jun 2023 12:02:39 -0400 Subject: [PATCH 01/34] allow kernels to be overridden --- src/Roots/Acorn/Bootloader.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index afda524e..dde8f1c7 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -261,12 +261,12 @@ public function getApplication(): ApplicationContract $this->app->singleton( \Illuminate\Contracts\Http\Kernel::class, - \Roots\Acorn\Kernel::class + $this->app->config->get('kernels.http', \Roots\Acorn\Kernel::class) ); $this->app->singleton( \Illuminate\Contracts\Console\Kernel::class, - \Roots\Acorn\Console\Kernel::class + $this->app->config->get('kernels.console', \Roots\Acorn\Console\Kernel::class) ); $this->app->singleton( @@ -285,6 +285,7 @@ public function getApplication(): ApplicationContract return $this->app; } + /** * Get the application basepath * From d63c4f505b5fd700c455c9a9fbf74ad5defaeadb Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Mon, 12 Jun 2023 12:03:24 -0400 Subject: [PATCH 02/34] fix formatting --- src/Roots/Acorn/Bootloader.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index dde8f1c7..f598a8aa 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -285,7 +285,6 @@ public function getApplication(): ApplicationContract return $this->app; } - /** * Get the application basepath * From 5d1bb21f75d87e290c7ff7418d09b5e03c52e48d Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Mon, 12 Jun 2023 13:30:40 -0400 Subject: [PATCH 03/34] fix acorn router not being loaded when WP_CLI is active --- src/Roots/Acorn/Bootloader.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index f598a8aa..99cb6e14 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -111,10 +111,6 @@ public function boot($callback = null) } if (Env::get('ACORN_ENABLE_EXPIRIMENTAL_ROUTER')) { - $app->singleton( - \Illuminate\Contracts\Http\Kernel::class, - \Roots\Acorn\Http\Kernel::class - ); return $this->bootHttp($app); } @@ -261,12 +257,14 @@ public function getApplication(): ApplicationContract $this->app->singleton( \Illuminate\Contracts\Http\Kernel::class, - $this->app->config->get('kernels.http', \Roots\Acorn\Kernel::class) + Env::get('ACORN_ENABLE_EXPIRIMENTAL_ROUTER') + ? \Roots\Acorn\Http\Kernel::class + : \Roots\Acorn\Kernel::class ); $this->app->singleton( \Illuminate\Contracts\Console\Kernel::class, - $this->app->config->get('kernels.console', \Roots\Acorn\Console\Kernel::class) + \Roots\Acorn\Console\Kernel::class ); $this->app->singleton( From 63ec2f49b199d06de0a0869cba10432ae464ab23 Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Tue, 13 Jun 2023 22:00:56 -0400 Subject: [PATCH 04/34] bootloader changes giving router better compatibility and addressing issue #276 --- src/Roots/Acorn/Bootloader.php | 75 +++++++++++++++++----------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index 99cb6e14..65cdf947 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -197,20 +197,18 @@ protected function bootHttp(ApplicationContract $app) { $kernel = $app->make(\Illuminate\Contracts\Http\Kernel::class); $request = \Illuminate\Http\Request::capture(); + $time = time(); + + // Create a default route for wordpress actions to go through + $app->make('router')->get('{any?}', function () use ($time) { + return response()->json(['message' => "wordpress_request_$time" ]); + })->where('any', '.*'); $app->instance('request', $request); Facade::clearResolvedInstance('request'); $kernel->bootstrap($request); - try { - if (! $app->make('router')->getRoutes()->match($request)) { - throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException(); - } - } catch (\Exception $e) { - return; - } - add_filter( 'do_parse_request', fn ($do_parse, \WP $wp, $extra_query_vars) => @@ -219,17 +217,29 @@ protected function bootHttp(ApplicationContract $app) 3 ); - add_action('parse_request', function () use ($kernel, $request) { - /** @var \Illuminate\Http\Response */ + add_action('parse_request', function () use ($time, $kernel, $request) { + /** @var \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\BinaryFileResponse */ $response = $kernel->handle($request); - if (! $response->isServerError() && $response->status() >= 400) { + if (in_array(true, [ + $response instanceof \Illuminate\Http\Response + && ! $response->isServerError() && $response->status() >= 400, + $response instanceof \Symfony\Component\HttpFoundation\BinaryFileResponse + && ! $response->isServerError() && $response->getStatusCode() >= 400, + ])) { return; } - $body = $response->send(); + if (in_array(false, [ + $response instanceof \Illuminate\Http\JsonResponse, + is_string($response->getContent()), + $data = json_decode($response->getContent()), + isset($data->message) && $data->message == "wordpress_request_$time", + ])) { + $body = $response->send(); - $kernel->terminate($request, $body); + $kernel->terminate($request, $body); + } }); } @@ -255,30 +265,21 @@ public function getApplication(): ApplicationContract { $this->app ??= new Application($this->basePath(), $this->usePaths()); - $this->app->singleton( - \Illuminate\Contracts\Http\Kernel::class, - Env::get('ACORN_ENABLE_EXPIRIMENTAL_ROUTER') - ? \Roots\Acorn\Http\Kernel::class - : \Roots\Acorn\Kernel::class - ); - - $this->app->singleton( - \Illuminate\Contracts\Console\Kernel::class, - \Roots\Acorn\Console\Kernel::class - ); - - $this->app->singleton( - \Illuminate\Contracts\Debug\ExceptionHandler::class, - \Roots\Acorn\Exceptions\Handler::class - ); - - if (class_exists(\Whoops\Run::class)) { - $this->app->bind( - \Illuminate\Contracts\Foundation\ExceptionRenderer::class, - fn (\Illuminate\Contracts\Foundation\Application $app) => - $app->make(\Roots\Acorn\Exceptions\Whoops\WhoopsExceptionRenderer::class) - ); - } + $httpKernel = Env::get('ACORN_ENABLE_EXPIRIMENTAL_ROUTER') + ? \Roots\Acorn\Http\Kernel::class + : \Roots\Acorn\Kernel::class; + + collect(apply_filters('acorn/early/singletons', [ + \Illuminate\Contracts\Http\Kernel::class => $httpKernel, + \Illuminate\Contracts\Console\Kernel::class => \Roots\Acorn\Console\Kernel::class, + \Illuminate\Contracts\Debug\ExceptionHandler::class => \Roots\Acorn\Exceptions\Handler::class, + ])) + ->each(fn($concrete, $abstract) => $this->app->singleton($abstract, $concrete)); + + collect(apply_filters('acorn/early/bindings', class_exists(\Whoops\Run::class) + ? [\Illuminate\Contracts\Foundation\ExceptionRenderer::class => \Roots\Acorn\Exceptions\Whoops\WhoopsExceptionRenderer::class] + : [])) + ->each(fn($concrete, $abstract) => $this->app->bind($abstract, $concrete)); return $this->app; } From d02ecdde65db78adf51f5f1e1122a8af7d082a72 Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Wed, 14 Jun 2023 11:23:16 -0400 Subject: [PATCH 05/34] use symfony base class as everything extends this class in the response factory --- src/Roots/Acorn/Bootloader.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index 65cdf947..54802d88 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -218,15 +218,13 @@ protected function bootHttp(ApplicationContract $app) ); add_action('parse_request', function () use ($time, $kernel, $request) { - /** @var \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\BinaryFileResponse */ + /** @var \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response */ $response = $kernel->handle($request); if (in_array(true, [ - $response instanceof \Illuminate\Http\Response - && ! $response->isServerError() && $response->status() >= 400, - $response instanceof \Symfony\Component\HttpFoundation\BinaryFileResponse - && ! $response->isServerError() && $response->getStatusCode() >= 400, - ])) { + $response instanceof \Illuminate\Http\Response && $response->status() >= 400, + $response instanceof \Symfony\Component\HttpFoundation\Response && $response->getStatusCode() >= 400, + ]) && ! $response->isServerError()) { return; } From 1c34f8672b02af0a1cc4f2615a3518433736c520 Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Wed, 14 Jun 2023 11:23:27 -0400 Subject: [PATCH 06/34] use symfony base class as everything extends this class in the response factory --- src/Roots/Acorn/Bootloader.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index 54802d88..f988dae1 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -218,13 +218,16 @@ protected function bootHttp(ApplicationContract $app) ); add_action('parse_request', function () use ($time, $kernel, $request) { - /** @var \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response */ + /** + * @var \Symfony\Component\HttpFoundation\Response $response + * @see \Illuminate\Contracts\Routing\ResponseFactory + */ $response = $kernel->handle($request); - if (in_array(true, [ - $response instanceof \Illuminate\Http\Response && $response->status() >= 400, - $response instanceof \Symfony\Component\HttpFoundation\Response && $response->getStatusCode() >= 400, - ]) && ! $response->isServerError()) { + if ($response instanceof \Symfony\Component\HttpFoundation\Response + && ! $response->isServerError() + && $response->getStatusCode() >= 400 + ) { return; } From e4740b6a1999836830e58b1a1226aa5f5175ccf5 Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Wed, 14 Jun 2023 11:36:04 -0400 Subject: [PATCH 07/34] move wordpress default route to after kernel bootstrap so that it is the last route --- src/Roots/Acorn/Bootloader.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index f988dae1..11f34d3f 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -199,16 +199,16 @@ protected function bootHttp(ApplicationContract $app) $request = \Illuminate\Http\Request::capture(); $time = time(); - // Create a default route for wordpress actions to go through - $app->make('router')->get('{any?}', function () use ($time) { - return response()->json(['message' => "wordpress_request_$time" ]); - })->where('any', '.*'); - $app->instance('request', $request); Facade::clearResolvedInstance('request'); $kernel->bootstrap($request); + // Create a default route for wordpress actions to go through + $app->make('router')->get('{any?}', function () use ($time) { + return response()->json(['message' => "wordpress_request_$time" ]); + })->where('any', '.*'); + add_filter( 'do_parse_request', fn ($do_parse, \WP $wp, $extra_query_vars) => From 5755e03fe2e728528addb727f584b8158cc3412a Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Wed, 14 Jun 2023 12:28:40 -0400 Subject: [PATCH 08/34] add class replacement for singleton replacements as an option & remove binding replacements --- src/Roots/Acorn/Bootloader.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index 11f34d3f..907dcd78 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -266,21 +266,34 @@ public function getApplication(): ApplicationContract { $this->app ??= new Application($this->basePath(), $this->usePaths()); + $namespace = $this->app->getNamespace(); + $httpKernel = Env::get('ACORN_ENABLE_EXPIRIMENTAL_ROUTER') ? \Roots\Acorn\Http\Kernel::class : \Roots\Acorn\Kernel::class; - collect(apply_filters('acorn/early/singletons', [ + collect([ \Illuminate\Contracts\Http\Kernel::class => $httpKernel, \Illuminate\Contracts\Console\Kernel::class => \Roots\Acorn\Console\Kernel::class, \Illuminate\Contracts\Debug\ExceptionHandler::class => \Roots\Acorn\Exceptions\Handler::class, - ])) + ]) + ->map(fn($concrete, $abstract) => class_exists(str_replace('\\Roots\\Acorn', "\\$namespace", $concrete)) + ? str_replace('\\Roots\\Acorn', "\\$namespace", $concrete) + : $concrete) + ->map(fn($concrete, $abstract) => apply_filters( + "acorn/container/" + . Str::of($abstract)->replaceFirst('Illuminate\\Contracts', '')->replace('\\', ' ')->slug(), + $concrete, + $abstract + )) ->each(fn($concrete, $abstract) => $this->app->singleton($abstract, $concrete)); - collect(apply_filters('acorn/early/bindings', class_exists(\Whoops\Run::class) - ? [\Illuminate\Contracts\Foundation\ExceptionRenderer::class => \Roots\Acorn\Exceptions\Whoops\WhoopsExceptionRenderer::class] - : [])) - ->each(fn($concrete, $abstract) => $this->app->bind($abstract, $concrete)); + if (class_exists(\Whoops\Run::class)) { + $this->app->bind( + \Illuminate\Contracts\Foundation\ExceptionRenderer::class, + \Roots\Acorn\Exceptions\Whoops\WhoopsExceptionRenderer::class + ); + } return $this->app; } From 5eb4d888d76fd80745a4f072eaae0a4672a287c8 Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Wed, 14 Jun 2023 12:30:13 -0400 Subject: [PATCH 09/34] classname::class doesn't render with starting backslash --- src/Roots/Acorn/Bootloader.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index 907dcd78..d42d9e8f 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -277,8 +277,8 @@ public function getApplication(): ApplicationContract \Illuminate\Contracts\Console\Kernel::class => \Roots\Acorn\Console\Kernel::class, \Illuminate\Contracts\Debug\ExceptionHandler::class => \Roots\Acorn\Exceptions\Handler::class, ]) - ->map(fn($concrete, $abstract) => class_exists(str_replace('\\Roots\\Acorn', "\\$namespace", $concrete)) - ? str_replace('\\Roots\\Acorn', "\\$namespace", $concrete) + ->map(fn($concrete, $abstract) => class_exists(str_replace('Roots\\Acorn', "$namespace", $concrete)) + ? str_replace('Roots\\Acorn', "$namespace", $concrete) : $concrete) ->map(fn($concrete, $abstract) => apply_filters( "acorn/container/" From a873f6ace51936c73da1564e5a34680db62f11a2 Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Wed, 14 Jun 2023 12:49:04 -0400 Subject: [PATCH 10/34] remove class replacement functionality becuase of odd 'already defined' error --- src/Roots/Acorn/Bootloader.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index d42d9e8f..ebba562f 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -277,9 +277,6 @@ public function getApplication(): ApplicationContract \Illuminate\Contracts\Console\Kernel::class => \Roots\Acorn\Console\Kernel::class, \Illuminate\Contracts\Debug\ExceptionHandler::class => \Roots\Acorn\Exceptions\Handler::class, ]) - ->map(fn($concrete, $abstract) => class_exists(str_replace('Roots\\Acorn', "$namespace", $concrete)) - ? str_replace('Roots\\Acorn', "$namespace", $concrete) - : $concrete) ->map(fn($concrete, $abstract) => apply_filters( "acorn/container/" . Str::of($abstract)->replaceFirst('Illuminate\\Contracts', '')->replace('\\', ' ')->slug(), From 39e3dbf6f0fbab46a9602a9f4ac1c42db7bf4699 Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Wed, 14 Jun 2023 13:56:04 -0400 Subject: [PATCH 11/34] put back closure --- src/Roots/Acorn/Bootloader.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index ebba562f..770bffdd 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -288,7 +288,8 @@ public function getApplication(): ApplicationContract if (class_exists(\Whoops\Run::class)) { $this->app->bind( \Illuminate\Contracts\Foundation\ExceptionRenderer::class, - \Roots\Acorn\Exceptions\Whoops\WhoopsExceptionRenderer::class + fn (\Illuminate\Contracts\Foundation\Application $app) => + $app->make(\Roots\Acorn\Exceptions\Whoops\WhoopsExceptionRenderer::class) ); } From 4c352b53187cfa2d11a6ef9be83c58b797dcf63a Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Wed, 14 Jun 2023 13:56:29 -0400 Subject: [PATCH 12/34] remove pointless namespace var --- src/Roots/Acorn/Bootloader.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index 770bffdd..92cb12b4 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -266,8 +266,6 @@ public function getApplication(): ApplicationContract { $this->app ??= new Application($this->basePath(), $this->usePaths()); - $namespace = $this->app->getNamespace(); - $httpKernel = Env::get('ACORN_ENABLE_EXPIRIMENTAL_ROUTER') ? \Roots\Acorn\Http\Kernel::class : \Roots\Acorn\Kernel::class; From 27d452436d4ebd4c5d63e62d2be019113697898a Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Mon, 19 Jun 2023 13:38:57 -0400 Subject: [PATCH 13/34] make acorn/router/do_parse_request filter backwards compatible --- src/Roots/Acorn/Bootloader.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index 92cb12b4..42cf5659 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -209,13 +209,13 @@ protected function bootHttp(ApplicationContract $app) return response()->json(['message' => "wordpress_request_$time" ]); })->where('any', '.*'); - add_filter( - 'do_parse_request', - fn ($do_parse, \WP $wp, $extra_query_vars) => - apply_filters('acorn/router/do_parse_request', $do_parse, $wp, $extra_query_vars), - 100, - 3 - ); + add_filter('do_parse_request', function ($do_parse, \WP $wp, $extra_query_vars) use ($time) { + if (isset($wp->query_vars['any']) && $wp->query_vars['any'] === "wordpress_request_$time") { + return $do_parse; + } + + return apply_filters('acorn/router/do_parse_request', $do_parse, $wp, $extra_query_vars); + }, 100, 3); add_action('parse_request', function () use ($time, $kernel, $request) { /** From 6eac48140c16e55ba317cbefe1a20002efdbf153 Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Mon, 19 Jun 2023 13:40:43 -0400 Subject: [PATCH 14/34] fix do_parse_request filter --- src/Roots/Acorn/Bootloader.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index 42cf5659..84925073 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -204,19 +204,20 @@ protected function bootHttp(ApplicationContract $app) $kernel->bootstrap($request); + add_filter('do_parse_request', function ($do_parse, \WP $wp, $extra_query_vars) use ($kernel, $request) { + // check to see if route matches current routes + if ($kernel->getRouter()->getRoutes()->match($request)) { + return apply_filters('acorn/router/do_parse_request', $do_parse, $wp, $extra_query_vars); + } + + return $do_parse; + }, 100, 3); + // Create a default route for wordpress actions to go through $app->make('router')->get('{any?}', function () use ($time) { return response()->json(['message' => "wordpress_request_$time" ]); })->where('any', '.*'); - add_filter('do_parse_request', function ($do_parse, \WP $wp, $extra_query_vars) use ($time) { - if (isset($wp->query_vars['any']) && $wp->query_vars['any'] === "wordpress_request_$time") { - return $do_parse; - } - - return apply_filters('acorn/router/do_parse_request', $do_parse, $wp, $extra_query_vars); - }, 100, 3); - add_action('parse_request', function () use ($time, $kernel, $request) { /** * @var \Symfony\Component\HttpFoundation\Response $response From 552158144b285267ffa26fc885e0e06225e02762 Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Mon, 19 Jun 2023 13:41:05 -0400 Subject: [PATCH 15/34] remove 'goes without saying' comment --- src/Roots/Acorn/Bootloader.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index 84925073..b16bd924 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -205,7 +205,6 @@ protected function bootHttp(ApplicationContract $app) $kernel->bootstrap($request); add_filter('do_parse_request', function ($do_parse, \WP $wp, $extra_query_vars) use ($kernel, $request) { - // check to see if route matches current routes if ($kernel->getRouter()->getRoutes()->match($request)) { return apply_filters('acorn/router/do_parse_request', $do_parse, $wp, $extra_query_vars); } From a338218abb07283db4baee690c0b765aade65f0a Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Mon, 19 Jun 2023 13:43:24 -0400 Subject: [PATCH 16/34] use a better check for do_parse_request --- src/Roots/Acorn/Bootloader.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index b16bd924..8b3c83cf 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -204,12 +204,12 @@ protected function bootHttp(ApplicationContract $app) $kernel->bootstrap($request); - add_filter('do_parse_request', function ($do_parse, \WP $wp, $extra_query_vars) use ($kernel, $request) { - if ($kernel->getRouter()->getRoutes()->match($request)) { - return apply_filters('acorn/router/do_parse_request', $do_parse, $wp, $extra_query_vars); + add_filter('do_parse_request', function ($do_parse, \WP $wp, $extra_query_vars) use ($app) { + if (! $app->make('router')->getRoutes()->match($request)) { + return $do_parse; } - return $do_parse; + return apply_filters('acorn/router/do_parse_request', $do_parse, $wp, $extra_query_vars); }, 100, 3); // Create a default route for wordpress actions to go through From 5e0082013229752105d74f71b932126ccaba0ada Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Mon, 19 Jun 2023 13:48:07 -0400 Subject: [PATCH 17/34] use better comment --- src/Roots/Acorn/Bootloader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index 8b3c83cf..8f4192e6 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -212,7 +212,7 @@ protected function bootHttp(ApplicationContract $app) return apply_filters('acorn/router/do_parse_request', $do_parse, $wp, $extra_query_vars); }, 100, 3); - // Create a default route for wordpress actions to go through + // Create a default route for wordpress routes to use $app->make('router')->get('{any?}', function () use ($time) { return response()->json(['message' => "wordpress_request_$time" ]); })->where('any', '.*'); From 267217bcd0e6994cd6dcaa1f0e6102a48a659e55 Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Mon, 19 Jun 2023 16:17:10 -0400 Subject: [PATCH 18/34] need to be able to use --- src/Roots/Acorn/Bootloader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index 8f4192e6..fdfba2f3 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -204,7 +204,7 @@ protected function bootHttp(ApplicationContract $app) $kernel->bootstrap($request); - add_filter('do_parse_request', function ($do_parse, \WP $wp, $extra_query_vars) use ($app) { + add_filter('do_parse_request', function ($do_parse, \WP $wp, $extra_query_vars) use ($app, $request) { if (! $app->make('router')->getRoutes()->match($request)) { return $do_parse; } From f5757f85b6e78d12bb5a052b92e878e829d660a7 Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Mon, 19 Jun 2023 16:19:08 -0400 Subject: [PATCH 19/34] clean up code for default wordpress route --- src/Roots/Acorn/Bootloader.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index fdfba2f3..e743f1ed 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -213,9 +213,9 @@ protected function bootHttp(ApplicationContract $app) }, 100, 3); // Create a default route for wordpress routes to use - $app->make('router')->get('{any?}', function () use ($time) { - return response()->json(['message' => "wordpress_request_$time" ]); - })->where('any', '.*'); + $app->make('router') + ->get('{any?}', fn () => response()->json(['message' => "wordpress_request_$time" ])) + ->where('any', '.*'); add_action('parse_request', function () use ($time, $kernel, $request) { /** From 27603346b3abf83c848a04885d1a37cb4f02cdea Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Tue, 27 Jun 2023 13:36:56 -0400 Subject: [PATCH 20/34] revisions from QWp6t --- src/Roots/Acorn/Bootloader.php | 86 ++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 35 deletions(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index e743f1ed..59b338b6 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -217,31 +217,45 @@ protected function bootHttp(ApplicationContract $app) ->get('{any?}', fn () => response()->json(['message' => "wordpress_request_$time" ])) ->where('any', '.*'); - add_action('parse_request', function () use ($time, $kernel, $request) { - /** - * @var \Symfony\Component\HttpFoundation\Response $response - * @see \Illuminate\Contracts\Routing\ResponseFactory - */ - $response = $kernel->handle($request); - - if ($response instanceof \Symfony\Component\HttpFoundation\Response - && ! $response->isServerError() - && $response->getStatusCode() >= 400 - ) { - return; - } + add_action('parse_request', fn () => $this->handleLaravelRequest($time, $kernel, $request)); + } - if (in_array(false, [ - $response instanceof \Illuminate\Http\JsonResponse, - is_string($response->getContent()), - $data = json_decode($response->getContent()), - isset($data->message) && $data->message == "wordpress_request_$time", - ])) { - $body = $response->send(); + /** + * Handle the Request with Laravel's Router + * + * @param string $time + * @param \Illuminate\Contracts\Http\Kernel $kernel + * @param \Illuminate\Http\Request $request + * @return void + */ + protected function handleLaravelRequest( + string $time, + \Illuminate\Contracts\Http\Kernel $kernel, + \Illuminate\Http\Request $request + ) { + /** + * @var \Symfony\Component\HttpFoundation\Response $response + * @see \Illuminate\Contracts\Routing\ResponseFactory + */ + $response = $kernel->handle($request); + + if ($response instanceof \Symfony\Component\HttpFoundation\Response + && ! $response->isServerError() + && $response->getStatusCode() >= 400 + ) { + return; + } - $kernel->terminate($request, $body); - } - }); + if (in_array(false, [ + $response instanceof \Illuminate\Http\JsonResponse, + is_string($response->getContent()), + $data = json_decode($response->getContent()), + isset($data->message) && $data->message == "wordpress_request_$time", + ])) { + $body = $response->send(); + + $kernel->terminate($request, $body); + } } /** @@ -270,18 +284,20 @@ public function getApplication(): ApplicationContract ? \Roots\Acorn\Http\Kernel::class : \Roots\Acorn\Kernel::class; - collect([ - \Illuminate\Contracts\Http\Kernel::class => $httpKernel, - \Illuminate\Contracts\Console\Kernel::class => \Roots\Acorn\Console\Kernel::class, - \Illuminate\Contracts\Debug\ExceptionHandler::class => \Roots\Acorn\Exceptions\Handler::class, - ]) - ->map(fn($concrete, $abstract) => apply_filters( - "acorn/container/" - . Str::of($abstract)->replaceFirst('Illuminate\\Contracts', '')->replace('\\', ' ')->slug(), - $concrete, - $abstract - )) - ->each(fn($concrete, $abstract) => $this->app->singleton($abstract, $concrete)); + $this->app->singleton( + \Illuminate\Contracts\Http\Kernel::class, + apply_filters('acorn/container/http-kernel', $httpKernel) + ); + + $this->app->singleton( + \Illuminate\Contracts\Console\Kernel::class, + apply_filters('acorn/container/console-kernel', \Roots\Acorn\Console\Kernel::class) + ); + + $this->app->singleton( + \Illuminate\Contracts\Debug\ExceptionHandler::class, + apply_filters('acorn/container/exception-handler', \Roots\Acorn\Console\Kernel::class) + ); if (class_exists(\Whoops\Run::class)) { $this->app->bind( From 669b8a4e5ae2b02a2eec9db9fab9c7f509aef0ef Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Tue, 27 Jun 2023 13:52:53 -0400 Subject: [PATCH 21/34] fix exceptions handler --- src/Roots/Acorn/Bootloader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index 6de745b0..44da614a 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -301,7 +301,7 @@ public function getApplication(): ApplicationContract $this->app->singleton( \Illuminate\Contracts\Debug\ExceptionHandler::class, - apply_filters('acorn/container/exception-handler', \Roots\Acorn\Console\Kernel::class) + apply_filters('acorn/container/exception-handler', \Roots\Acorn\Exceptions\Handler::class) ); if (class_exists(\Whoops\Run::class)) { From 24415ba056f86088497bfa09c109c429a9686e3d Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Sat, 21 Oct 2023 13:05:18 -0400 Subject: [PATCH 22/34] fix bug where WordPress request types other than GET throw an error --- src/Roots/Acorn/Bootloader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index 30c34a7c..ce54e0cc 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -219,7 +219,7 @@ protected function bootHttp(ApplicationContract $app) // Create a default route for wordpress routes to use $app->make('router') - ->get('{any?}', fn () => response()->json(['message' => "wordpress_request_$time" ])) + ->any('{any?}', fn () => response()->json(['message' => "wordpress_request_$time" ])) ->where('any', '.*'); add_action('parse_request', fn () => $this->handleLaravelRequest($time, $kernel, $request)); From 7718ef535752629e5dcc5a0f8a27377d878e6e1b Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Sat, 21 Oct 2023 13:47:48 -0400 Subject: [PATCH 23/34] phpcs linting --- src/Roots/Acorn/Bootloader.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index ce54e0cc..97281c6c 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -244,19 +244,22 @@ protected function handleLaravelRequest( */ $response = $kernel->handle($request); - if ($response instanceof \Symfony\Component\HttpFoundation\Response + if ( + $response instanceof \Symfony\Component\HttpFoundation\Response && ! $response->isServerError() && $response->getStatusCode() >= 400 ) { return; } - if (in_array(false, [ + if ( + in_array(false, [ $response instanceof \Illuminate\Http\JsonResponse, is_string($response->getContent()), $data = json_decode($response->getContent()), isset($data->message) && $data->message == "wordpress_request_$time", - ])) { + ]) + ) { $body = $response->send(); $kernel->terminate($request, $body); From dd417932ab2c20b6d35882b6a95b2a6b0c9486f0 Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Sat, 21 Oct 2023 13:52:36 -0400 Subject: [PATCH 24/34] add .idea folder to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0d43e670..7aa6985c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .php_cs.cache .phpunit.* +.idea phpunit.xml /composer.lock /coverage From 7fe6c76d63ab81f4c56edf2b6fbc11b337eabc02 Mon Sep 17 00:00:00 2001 From: Joseph Roberts Date: Sat, 21 Oct 2023 13:53:08 -0400 Subject: [PATCH 25/34] remove .idea files --- .idea/.gitignore | 8 - .idea/acorn.iml | 133 ---------------- .idea/inspectionProfiles/Project_Default.xml | 6 - .idea/modules.xml | 8 - .idea/php.xml | 150 ------------------- .idea/vcs.xml | 6 - 6 files changed, 311 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/acorn.iml delete mode 100644 .idea/inspectionProfiles/Project_Default.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/php.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b81..00000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/acorn.iml b/.idea/acorn.iml deleted file mode 100644 index 50bfa126..00000000 --- a/.idea/acorn.iml +++ /dev/null @@ -1,133 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 23850f4e..00000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 3e815877..00000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml deleted file mode 100644 index 1ae4b9d6..00000000 --- a/.idea/php.xml +++ /dev/null @@ -1,150 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1ddf..00000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 15528510c1c2c188025446196650999b4f3323ca Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 4 Jan 2024 01:03:40 -0600 Subject: [PATCH 26/34] =?UTF-8?q?=F0=9F=9A=A8=20Run=20Pint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Roots/Acorn/Bootloader.php | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index d2d5f257..0c045db5 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -216,7 +216,7 @@ protected function bootHttp(ApplicationContract $app) }, 100, 3); $app->make('router') - ->any('{any?}', fn () => response()->json(['message' => "wordpress_request_$time" ])) + ->any('{any?}', fn () => response()->json(['message' => "wordpress_request_$time"])) ->where('any', '.*'); add_action('parse_request', fn () => $this->handleLaravelRequest($time, $kernel, $request)); @@ -225,9 +225,6 @@ protected function bootHttp(ApplicationContract $app) /** * Handle the Request with Laravel's Router * - * @param string $time - * @param \Illuminate\Contracts\Http\Kernel $kernel - * @param \Illuminate\Http\Request $request * @return void */ protected function handleLaravelRequest( @@ -235,10 +232,6 @@ protected function handleLaravelRequest( \Illuminate\Contracts\Http\Kernel $kernel, \Illuminate\Http\Request $request ) { - /** - * @var \Symfony\Component\HttpFoundation\Response $response - * @see \Illuminate\Contracts\Routing\ResponseFactory - */ $response = $kernel->handle($request); if ( @@ -251,10 +244,10 @@ protected function handleLaravelRequest( if ( in_array(false, [ - $response instanceof \Illuminate\Http\JsonResponse, - is_string($response->getContent()), - $data = json_decode($response->getContent()), - isset($data->message) && $data->message == "wordpress_request_$time", + $response instanceof \Illuminate\Http\JsonResponse, + is_string($response->getContent()), + $data = json_decode($response->getContent()), + isset($data->message) && $data->message == "wordpress_request_$time", ]) ) { $body = $response->send(); From fbb166672478f2659947a96b98d6a12228633e40 Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 4 Jan 2024 01:35:18 -0600 Subject: [PATCH 27/34] =?UTF-8?q?=E2=9E=95=20Add=20`illuminate/encryption`?= =?UTF-8?q?=20to=20the=20project?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 020ba092..033bb6c0 100644 --- a/composer.json +++ b/composer.json @@ -49,6 +49,7 @@ "illuminate/container": "^10.33", "illuminate/contracts": "^10.33", "illuminate/database": "^10.33", + "illuminate/encryption": "^10.33", "illuminate/events": "^10.33", "illuminate/filesystem": "^10.33", "illuminate/http": "^10.33", From 52b8f071d7fdf552b1fae31e45170b353ee2879b Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 4 Jan 2024 01:36:06 -0600 Subject: [PATCH 28/34] =?UTF-8?q?=F0=9F=A9=B9=20Fix=20Http=20Kernel=20regi?= =?UTF-8?q?stration=20=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Use=20`microtime?= =?UTF-8?q?()`=20for=20the=20route=20timestamp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Roots/Acorn/Bootloader.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index 0c045db5..e9a3e57b 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -200,7 +200,7 @@ protected function bootHttp(ApplicationContract $app) { $kernel = $app->make(\Illuminate\Contracts\Http\Kernel::class); $request = \Illuminate\Http\Request::capture(); - $time = time(); + $time = microtime(); $app->instance('request', $request); Facade::clearResolvedInstance('request'); @@ -216,7 +216,7 @@ protected function bootHttp(ApplicationContract $app) }, 100, 3); $app->make('router') - ->any('{any?}', fn () => response()->json(['message' => "wordpress_request_$time"])) + ->any('{any?}', fn () => response()->json(['message' => "wordpress_request_{$time}"])) ->where('any', '.*'); add_action('parse_request', fn () => $this->handleLaravelRequest($time, $kernel, $request)); @@ -269,7 +269,7 @@ public function getApplication(): ApplicationContract $this->app->singleton( \Illuminate\Contracts\Http\Kernel::class, - apply_filters('acorn/container/http-kernel', $httpKernel) + apply_filters('acorn/container/http-kernel', \Roots\Acorn\Http\Kernel::class) ); $this->app->singleton( From ae66b314657dd0818e57ffc6e744e8b21e764ffb Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 4 Jan 2024 03:46:31 -0600 Subject: [PATCH 29/34] =?UTF-8?q?=E2=9C=A8=20Implement=20the=20`key:genera?= =?UTF-8?q?te`=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Console/Commands/KeyGenerateCommand.php | 38 +++++++++++++++++++ src/Roots/Acorn/Console/Kernel.php | 1 + 2 files changed, 39 insertions(+) create mode 100644 src/Roots/Acorn/Console/Commands/KeyGenerateCommand.php diff --git a/src/Roots/Acorn/Console/Commands/KeyGenerateCommand.php b/src/Roots/Acorn/Console/Commands/KeyGenerateCommand.php new file mode 100644 index 00000000..6b21d770 --- /dev/null +++ b/src/Roots/Acorn/Console/Commands/KeyGenerateCommand.php @@ -0,0 +1,38 @@ +laravel->environmentFilePath()) + ? $this->laravel->environmentFilePath() + : File::closest(base_path(), '.env'); + + $replaced = preg_replace( + $this->keyReplacementPattern(), + 'APP_KEY='.$key, + $input = file_get_contents($env) + ); + + if ($replaced === $input || $replaced === null) { + $this->error('Unable to set application key. No APP_KEY variable was found in the .env file.'); + + return false; + } + + file_put_contents($env, $replaced); + + return true; + } +} diff --git a/src/Roots/Acorn/Console/Kernel.php b/src/Roots/Acorn/Console/Kernel.php index 6f06e668..3bf0a093 100644 --- a/src/Roots/Acorn/Console/Kernel.php +++ b/src/Roots/Acorn/Console/Kernel.php @@ -36,6 +36,7 @@ class Kernel extends FoundationConsoleKernel \Roots\Acorn\Console\Commands\AcornInitCommand::class, \Roots\Acorn\Console\Commands\ComposerMakeCommand::class, \Roots\Acorn\Console\Commands\ConfigCacheCommand::class, + \Roots\Acorn\Console\Commands\KeyGenerateCommand::class, \Roots\Acorn\Console\Commands\OptimizeClearCommand::class, \Roots\Acorn\Console\Commands\OptimizeCommand::class, \Roots\Acorn\Console\Commands\RouteCacheCommand::class, From 201f1b7f84a2467625ecab3851d129d419dedc26 Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 4 Jan 2024 03:53:12 -0600 Subject: [PATCH 30/34] =?UTF-8?q?=F0=9F=8E=A8=20Improve=20the=20`key:gener?= =?UTF-8?q?ate`=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Acorn/Console/Commands/KeyGenerateCommand.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Roots/Acorn/Console/Commands/KeyGenerateCommand.php b/src/Roots/Acorn/Console/Commands/KeyGenerateCommand.php index 6b21d770..f6f52a81 100644 --- a/src/Roots/Acorn/Console/Commands/KeyGenerateCommand.php +++ b/src/Roots/Acorn/Console/Commands/KeyGenerateCommand.php @@ -15,14 +15,20 @@ class KeyGenerateCommand extends FoundationKeyGenerateCommand */ protected function writeNewEnvironmentFileWith($key) { - $env = file_exists($this->laravel->environmentFilePath()) + $envFile = file_exists($this->laravel->environmentFilePath()) ? $this->laravel->environmentFilePath() - : File::closest(base_path(), '.env'); + : File::closest($this->laravel->basePath(), '.env'); + + if (! $envFile) { + $this->error('Unable to set application key. Create a .env file.'); + + return false; + } $replaced = preg_replace( $this->keyReplacementPattern(), 'APP_KEY='.$key, - $input = file_get_contents($env) + $input = file_get_contents($envFile) ); if ($replaced === $input || $replaced === null) { @@ -31,7 +37,7 @@ protected function writeNewEnvironmentFileWith($key) return false; } - file_put_contents($env, $replaced); + file_put_contents($envFile, $replaced); return true; } From 9365ba17eee2410f9a4bb6b3f9fbef9a13bba35d Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 4 Jan 2024 04:10:13 -0600 Subject: [PATCH 31/34] =?UTF-8?q?=F0=9F=99=88=20Remove=20`.idea`=20from=20?= =?UTF-8?q?`.gitignore`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7aa6985c..0d43e670 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ .php_cs.cache .phpunit.* -.idea phpunit.xml /composer.lock /coverage From 8228ca5f048562ad90742794dcdd84894c4c9abe Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 4 Jan 2024 04:10:35 -0600 Subject: [PATCH 32/34] =?UTF-8?q?=F0=9F=8E=A8=20Improve=20the=20Bootloader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Roots/Acorn/Bootloader.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index e9a3e57b..e6402f98 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -146,6 +146,7 @@ protected function bootConsole(ApplicationContract $app) ); $kernel->terminate($input, $status); + exit($status); } @@ -247,7 +248,7 @@ protected function handleLaravelRequest( $response instanceof \Illuminate\Http\JsonResponse, is_string($response->getContent()), $data = json_decode($response->getContent()), - isset($data->message) && $data->message == "wordpress_request_$time", + isset($data->message) && $data->message == "wordpress_request_{$time}", ]) ) { $body = $response->send(); @@ -269,17 +270,17 @@ public function getApplication(): ApplicationContract $this->app->singleton( \Illuminate\Contracts\Http\Kernel::class, - apply_filters('acorn/container/http-kernel', \Roots\Acorn\Http\Kernel::class) + \Roots\Acorn\Http\Kernel::class ); $this->app->singleton( \Illuminate\Contracts\Console\Kernel::class, - apply_filters('acorn/container/console-kernel', \Roots\Acorn\Console\Kernel::class) + \Roots\Acorn\Console\Kernel::class ); $this->app->singleton( \Illuminate\Contracts\Debug\ExceptionHandler::class, - apply_filters('acorn/container/exception-handler', \Roots\Acorn\Exceptions\Handler::class) + \Roots\Acorn\Exceptions\Handler::class ); if (class_exists(\Whoops\Run::class)) { @@ -409,6 +410,7 @@ protected function fallbackPath(string $path): string protected function fallbackStoragePath() { $path = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'acorn'; + $this->files->ensureDirectoryExists($path.DIRECTORY_SEPARATOR.'framework'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'data', 0755, true); $this->files->ensureDirectoryExists($path.DIRECTORY_SEPARATOR.'framework'.DIRECTORY_SEPARATOR.'views', 0755, true); $this->files->ensureDirectoryExists($path.DIRECTORY_SEPARATOR.'framework'.DIRECTORY_SEPARATOR.'sessions', 0755, true); From 80eedab7b92c1f8a1559abf4cb482d4f81ea8734 Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 4 Jan 2024 04:23:10 -0600 Subject: [PATCH 33/34] =?UTF-8?q?=F0=9F=8E=A8=20Improve=20the=20Bootloader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Roots/Acorn/Bootloader.php | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index e6402f98..15fa12b2 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -13,28 +13,28 @@ class Bootloader { /** - * Bootloader instance + * The Bootloader instance. * * @var static */ protected static $instance; /** - * Application instance + * The Application instance. * * @var \Illuminate\Contracts\Foundation\Application */ protected $app; /** - * Filesystem helper + * The Filesystem instance. * * @var \Roots\Acorn\Filesystem\Filesystem */ protected $files; /** - * Base path for the application + * The application's base path. * * @var string */ @@ -48,7 +48,7 @@ class Bootloader protected $absoluteApplicationPathPrefixes = ['/', '\\']; /** - * Set the Bootloader instance + * Set the Bootloader instance. */ public static function setInstance(?self $bootloader) { @@ -56,7 +56,7 @@ public static function setInstance(?self $bootloader) } /** - * Get the Bootloader instance + * Get the Bootloader instance. * * @return static */ @@ -220,15 +220,15 @@ protected function bootHttp(ApplicationContract $app) ->any('{any?}', fn () => response()->json(['message' => "wordpress_request_{$time}"])) ->where('any', '.*'); - add_action('parse_request', fn () => $this->handleLaravelRequest($time, $kernel, $request)); + add_action('parse_request', fn () => $this->handleRequest($time, $kernel, $request)); } /** - * Handle the Request with Laravel's Router + * Handle the request. * * @return void */ - protected function handleLaravelRequest( + protected function handleRequest( string $time, \Illuminate\Contracts\Http\Kernel $kernel, \Illuminate\Http\Request $request @@ -260,9 +260,7 @@ protected function handleLaravelRequest( } /** - * Get Application instance. - * - * @param ApplicationContract $app + * Get the Application instance. */ public function getApplication(): ApplicationContract { @@ -294,7 +292,7 @@ public function getApplication(): ApplicationContract } /** - * Get the application basepath + * Get the application's base path. */ protected function basePath(): string { From 1b964df6c14b0ca312c7e5caf4ed2b77e23a5cd2 Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 4 Jan 2024 08:53:29 -0600 Subject: [PATCH 34/34] =?UTF-8?q?=E2=9E=95=20Add=20`illuminate/queue`=20to?= =?UTF-8?q?=20the=20project?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 033bb6c0..e79b41cc 100644 --- a/composer.json +++ b/composer.json @@ -54,6 +54,7 @@ "illuminate/filesystem": "^10.33", "illuminate/http": "^10.33", "illuminate/log": "^10.33", + "illuminate/queue": "^10.33", "illuminate/routing": "^10.33", "illuminate/support": "^10.33", "illuminate/view": "^10.33",