-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Adding a MicroKernel that holds service configuration #15820
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
74d3037
to
ee5bd54
Compare
return $this->containerBuilder; | ||
} | ||
|
||
public function getResourceLoader() |
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.
does this actually need to be exposed ?
Agreed on not exposing the Loader - I've just fixed both issues! |
2cc23d7
to
6278eca
Compare
I've just drastically simplified this PR and updated the description to describe it. This is ready for review! |
*/ | ||
public function registerContainerConfiguration(LoaderInterface $loader) | ||
{ | ||
if (!$loader instanceof ContainerBuilderAwareLoader) { |
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.
This should maybe be an interface, but the class is so simple and we just use it to fetch the ContainerBuilder and real Loader out, so I don't know if there's a real-use case to pass other concrete implementation in.
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.
I agree with you here
@weaverryan can you give me a use case on why you would choose to have a new kernel whose goal is to be able to build an application without any external files ? Thank you :-) |
@dupuchba Good question. Here are some reasons:
I think this is superior to the normal Cheers! |
@weaverryan you convinced me as at work we are currently migrating to a micro service architecture. Very interesting project! |
* @param ContainerBuilder $c | ||
* @param LoaderInterface $loader | ||
*/ | ||
abstract protected function configureServices(ContainerBuilder $c, LoaderInterface $loader); |
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.
what about implementing these methods with an empty body, so that you only need to overwrite the ones you need ?
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 - I like that better
ping @symfony/deciders |
👍 another step in the right direction! |
Probably I miss an important point here, but I don't see right now how this really makes things much easier. @weaverryan Can you show a simple example on how I would use this in a real application? |
@xabbuh I have a (somewhat complex) kernel example here (+route integration, which isn't part of this PR, but you can see how the kernel could handle both): https://gist.github.com/weaverryan/e4b19cabb1d9286c4217 Adding services in php is certainly not objectively better, but I think the approach of Here's the big win for me: End users would now implement Make sense? |
* | ||
* @param LoaderInterface $loader | ||
*/ | ||
public function registerContainerConfiguration(LoaderInterface $loader) |
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.
Usually we put public methods before protected ones. Is there a special reason to keep this method here (for example, to make it easier to spot the configureExtensions()
and configureServices()
methods)?
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.
that was exactly my thinking (making them more visible) - but I'd be happy to change the order if this is a hard rule we want to stick to
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.
actually, I just changed the order :)
@weaverryan Thanks for the example. I think I now understand your approach better. :) Besides the minor comments I left, I like this approach. 👍 |
@xabbuh thanks for the review! |
6bf3f82
to
f58a625
Compare
👍 Status: Reviewed |
…xtensions) can be configured direclty inside.
f58a625
to
1b1ad92
Compare
What about this? <?php
namespace Symfony\Component\HttpKernel;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class MicroKernel extends Kernel
{
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(function (ContainerBuilder $container) use ($loader) {
$this->configureExtensions($container, $loader);
$this->configureServices($container, $loader);
});
}
protected function configureExtensions(ContainerBuilder $c, LoaderInterface $loader)
{
}
protected function configureServices(ContainerBuilder $c, LoaderInterface $loader)
{
}
} |
I'm going to submit a PR soon with my own version of a micro-kernel. |
see #15990 |
} | ||
|
||
$this->configureExtensions($loader->getContainerBuilder(), $loader->getResourceLoader()); | ||
$this->configureServices($loader->getContainerBuilder(), $loader->getResourceLoader()); |
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.
We should probably add:
$loader->addResource(new FileResource(__FILE__));
Closing this one as #15990 provides an easier approach. |
This PR was merged into the 2.8 branch. Discussion ---------- added a micro kernel | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Related to #15948 and #15820 Commits ------- eab0f0a added a micro kernel
Hi guys!
This introduces a new kernel whose goal is to be able to build an application without any external files (and to make loading external files easier, since conditional logic can be in PHP).
This allows you to register services and configure DI extensions right in the kernel. With #15742, this (or a sub-class) would be updated to also allow routes to be configured inside the kernel as well.
There is really only one goal of this PR:
Thanks!