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

Document how to override Acorn kernel / boot #507

Open
3 tasks done
stefanfisk opened this issue Feb 20, 2023 · 3 comments
Open
3 tasks done

Document how to override Acorn kernel / boot #507

stefanfisk opened this issue Feb 20, 2023 · 3 comments
Labels

Comments

@stefanfisk
Copy link
Sponsor

stefanfisk commented Feb 20, 2023

Terms

Summary

I'd like the possibility to provide my own subclasses for the kernels.

Motivation

Why are we doing this?

To allow configuring stuff like bootstrappers and middleware.

What use cases does it support?

For example, I'd like to add the standard TrimStrings middleware.

What is the expected outcome?

Maybe a filter per kernel type?

Potential conflicts / foreseeable issues

Not sure, I guess it depends on how stable you consider the kernel APIs to be.

Additional Context

No response

@QWp6t
Copy link
Sponsor Member

QWp6t commented Feb 20, 2023

Maybe I'll check for the existence of \Http\Kernel and \Console\Kernel and load those instead. 🤔

I'll give it a think and come up with a solution. 👍

@retlehs retlehs changed the title Allow orderriding the kernel implementations Allow overriding the kernel implementations Mar 16, 2023
@oskar-koli
Copy link

oskar-koli commented Jan 20, 2024

I needed to add a middleware to the kernel so as a workaround for this issue I was able to override the http kernel singleton in functions.php, right after the bootloader has been booted:

\Roots\bootloader()->boot();

app()->singleton(
    \Illuminate\Contracts\Http\Kernel::class,
    CustomKernel::class
);

Where the CustomKernel extends the Acorn kernel:

namespace App\Core;

use App\Core\Acorn\ViewMiddleware;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Routing\Router;
use Roots\Acorn\Http\Kernel as AcornHttpKernel;

class CustomKernel extends AcornHttpKernel
{

    public function __construct(Application $app, Router $router)
    {
        $this->middlewareGroups["web"][] = ViewMiddleware::class;

        parent::__construct($app, $router);
    }
}

Haven't tested this in production yet, but it seems to work.
A proper fix seems to be on it's way, looking at the PRs, but thought I'd post this workaround here in case someone needs it asap.

@QWp6t
Copy link
Sponsor Member

QWp6t commented Mar 18, 2024

You can pass a callback to Bootloader::boot()

Roots\bootloader()->boot(function ($app) {
    $app->singleton(
        \Illuminate\Contracts\Http\Kernel::class,
        \App\Http\MySuperCoolKernel::class
    );
});

That should be fine for most of you.

If you want to have complete control over the boot process, just bootstrap your kernel, our bootloader will short-circuit.


➡️ Moving this to docs.

@QWp6t QWp6t transferred this issue from roots/acorn Mar 18, 2024
@QWp6t QWp6t changed the title Allow overriding the kernel implementations Document how to override Acorn kernel / boot Mar 18, 2024
@retlehs retlehs added acorn and removed enhancement labels Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants