Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced Router Compatibility (Including Livewire Support) And Filters For Early Service Container Overrides #291

Merged
merged 38 commits into from
Jan 5, 2024
Merged
Changes from 19 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
88c67a7
allow kernels to be overridden
digital-joe-co Jun 12, 2023
d63c4f5
fix formatting
digital-joe-co Jun 12, 2023
5d1bb21
fix acorn router not being loaded when WP_CLI is active
digital-joe-co Jun 12, 2023
63ec2f4
bootloader changes giving router better compatibility and addressing …
digital-joe-co Jun 14, 2023
d02ecdd
use symfony base class as everything extends this class in the respon…
digital-joe-co Jun 14, 2023
1c34f86
use symfony base class as everything extends this class in the respon…
digital-joe-co Jun 14, 2023
e4740b6
move wordpress default route to after kernel bootstrap so that it is …
digital-joe-co Jun 14, 2023
5755e03
add class replacement for singleton replacements as an option & remov…
digital-joe-co Jun 14, 2023
5eb4d88
classname::class doesn't render with starting backslash
digital-joe-co Jun 14, 2023
a873f6a
remove class replacement functionality becuase of odd 'already define…
digital-joe-co Jun 14, 2023
39e3dbf
put back closure
digital-joe-co Jun 14, 2023
4c352b5
remove pointless namespace var
digital-joe-co Jun 14, 2023
27d4524
make acorn/router/do_parse_request filter backwards compatible
digital-joe-co Jun 19, 2023
6eac481
fix do_parse_request filter
digital-joe-co Jun 19, 2023
5521581
remove 'goes without saying' comment
digital-joe-co Jun 19, 2023
a338218
use a better check for do_parse_request
digital-joe-co Jun 19, 2023
5e00820
use better comment
digital-joe-co Jun 19, 2023
267217b
need to be able to use
digital-joe-co Jun 19, 2023
f5757f8
clean up code for default wordpress route
digital-joe-co Jun 19, 2023
2760334
revisions from QWp6t
digital-joe-co Jun 27, 2023
a8bac6d
merge upstream main
digital-joe-co Jun 27, 2023
669b8a4
fix exceptions handler
digital-joe-co Jun 27, 2023
8d4a9cf
solve merge conflicts
broskees Oct 21, 2023
24415ba
fix bug where WordPress request types other than GET throw an error
broskees Oct 21, 2023
7718ef5
phpcs linting
broskees Oct 21, 2023
dd41793
add .idea folder to gitignore
broskees Oct 21, 2023
7fe6c76
remove .idea files
broskees Oct 21, 2023
3edfca3
Merge branch 'main' into main
Log1x Jan 4, 2024
1552851
🚨 Run Pint
Log1x Jan 4, 2024
fbb1666
➕ Add `illuminate/encryption` to the project
Log1x Jan 4, 2024
52b8f07
🩹 Fix Http Kernel registration
Log1x Jan 4, 2024
ae66b31
✨ Implement the `key:generate` command
Log1x Jan 4, 2024
201f1b7
🎨 Improve the `key:generate` command
Log1x Jan 4, 2024
9365ba1
🙈 Remove `.idea` from `.gitignore`
Log1x Jan 4, 2024
8228ca5
🎨 Improve the Bootloader
Log1x Jan 4, 2024
80eedab
🎨 Improve the Bootloader
Log1x Jan 4, 2024
1b964df
➕ Add `illuminate/queue` to the project
Log1x Jan 4, 2024
fbaf249
Merge branch 'main' into main
QWp6t Jan 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 44 additions & 35 deletions src/Roots/Acorn/Bootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -201,39 +197,50 @@ protected function bootHttp(ApplicationContract $app)
{
$kernel = $app->make(\Illuminate\Contracts\Http\Kernel::class);
$request = \Illuminate\Http\Request::capture();
$time = time();

$app->instance('request', $request);
Facade::clearResolvedInstance('request');

$kernel->bootstrap($request);

try {
add_filter('do_parse_request', function ($do_parse, \WP $wp, $extra_query_vars) use ($app, $request) {
if (! $app->make('router')->getRoutes()->match($request)) {
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
return $do_parse;
}
} catch (\Exception $e) {
return;
}

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
);
return apply_filters('acorn/router/do_parse_request', $do_parse, $wp, $extra_query_vars);
}, 100, 3);

// Create a default route for wordpress routes to use
$app->make('router')
->get('{any?}', fn () => response()->json(['message' => "wordpress_request_$time" ]))
->where('any', '.*');

add_action('parse_request', function () use ($kernel, $request) {
/** @var \Illuminate\Http\Response */
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->isServerError() && $response->status() >= 400) {
if ($response instanceof \Symfony\Component\HttpFoundation\Response
&& ! $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);
}
QWp6t marked this conversation as resolved.
Show resolved Hide resolved
});
}

Expand All @@ -259,20 +266,22 @@ public function getApplication(): ApplicationContract
{
$this->app ??= new Application($this->basePath(), $this->usePaths());

$this->app->singleton(
\Illuminate\Contracts\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
);
$httpKernel = Env::get('ACORN_ENABLE_EXPIRIMENTAL_ROUTER')
? \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));
QWp6t marked this conversation as resolved.
Show resolved Hide resolved

if (class_exists(\Whoops\Run::class)) {
$this->app->bind(
Expand Down