-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Simpler Kernel setup with MicroKernelTrait
#57408
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
Conversation
Wondering if we could also go with a abstract class SingleAppKernel extends Kernel
{
use MicroKernelTrait;
return static function init(): \Closure
{
return static function (array $context) {
return new static($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};
}
public function registerBundles(): iterable
{
yield new FrameworkBundle();
}
} and then reduce this use case to: final class App extends SingleAppKernel
{
#[Route('/')]
public function __invoke(): Response
{
return new Response('Hello World!');
}
}
return App::init(); ? |
Not convinced by SingleAppKernel. Could be OK to provide a fallback for registerBundles. |
What is the use-case for defining an invokable controller in the kernel? This is a convention for action controllers with a class per controller, I don't think we should apply that convention to other classes. Replacing I'm also not sure about the |
@wouterj, the |
96b5e5b
to
33bac4c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea!
Well, I'm really happy with how small it is now, even though we still have to set up the closure function ourselves: return static function (array $context) {
$kernel = new StripeWebhookEventSubscriber($context['APP_ENV'], (bool) $context['APP_DEBUG']);
return \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? new Application($kernel) : $kernel;
}; Any idea to simplify it more? In a nutshell, I'd love to just initialize my kernel/app and run. Random proposals: return fn () => StripeWebhookEventSubscriber::class; // and then the Runtime does the rest new $kernelClass(...)
return StripeWebhookEventSubscriber::init(); // implement a default in `MicroKernelTrait`
return new StripeWebhookEventSubscriber(); // and set up the env and debug vars using setter through the Runtime?
|
I've updated the PR description to include my use case as code example |
08ed13a
to
fd7d3b9
Compare
It's ready on my side. Thank you all for your reviews! |
Thank you @yceruto. |
Not sure why, but after this commit my controllers and commands are no longer loaded. Can be reproduced with a fresh installation with the symfony cli with |
Oops! Fixed in #57455 |
Minor improvements to create minimalistic Symfony apps with zero config (initially) + invokable controller using the Kernel class only:
Note
Ideal for one-file apps or workers.
What exactly does this PR improve?
config/
directory optional. Then you can add extension configs by redefining theconfigureContainer()
method or by importing external files inconfig/packages/*
as usual.yield new FrameworkBundle()
inregisterBundles()
method in case the$this->getBundlesPath()
file does not exist.What do you think?