-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[WIP][HttpKernel] Expose bundle hierarchy/metadata as a service #19594
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
@wesleylancel noted this could perhaps be enhanced using the |
Besides that, to fix the caching this parameter needs to be converted some way, some how. We can go serialization way, or maybe introduce a |
* | ||
* @author Roland Franssen <franssen.roland@gmail.com> | ||
*/ | ||
final class BundleVO |
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.
BundleMetadata
?
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.
Yes. Will do.
Why do you need that ? |
Main problem is the So this approach is about exposing bundle info as a parameter, so it's available in a early phase. Ie when building the container, ie extensions. Besides that, i like the way this represents your bundle ecosystem, imho it's more useful then just |
@ro0NL as you said i think the real problem here is that the kernel is not available during compilation, maybe we should try to do that at first ? |
Good point. However, im not sure we should pass the kernel around, as is, in this phase. I can imagine reasons why it's currently added afterwards, ie you can really break the ecosystem as lots of stuff is publicly accessible, not frozen, etc. Hence i chose for a VO object, to avoid passing bundle instances around at all. But maybe someone can advice why to, or why not. I just hope we can agree this needs to be available. |
I like the idea of separating the kernel from metadata/utilities, and break it down to just booting/handling/terminating etc. For metadata/utility the real kernel just uses the "kernel as a service". Eventually im not to sure about passing the real kernel as a service (like now after building), i think it's made available for the wrong reasons (ie exposing metadata/utilities). |
@ro0NL many things can break an app, i don't think that because someone can misuse a feature we should not include it. |
Im pretty sure this is the reason it's registered after building. If not, this is as easy as moving a few lines around, so im really curious here... |
@ro0NL no that's not that easy because the |
I havent fully investigated this yet, im still a bit unaware of inner workings here. Could you perhaps explain "the ContainerBuilder removes definitions when you use set" / point me to it. Eventually i would like the kernel metadata to be cached as a service definition. |
That's very complicated to access services during the compilation, mostly due to this. |
Got it. This is hard.. what about an object being a frozen definition and a real service at the same time... |
@ro0NL it could be a solution but remember that we have to deal with bc :) |
Of course, i'll have look at it this weekend to work on a better poc. |
Not convinced by the use cases targeted by this feature, but what about something like: $container->set('booting_kernel', new BootingKernel($this)); where However:
|
The usecase is to have a ecosystem that allows for bugs like #6919 and #18563 to be fixed, and not have to workaround each time. Im aware of the container builder, and how it works. I tend to go with a Basically i want to write an extension that acts upon bundles and the kernel. |
public function __toString() | ||
{ | ||
return $this->className; | ||
} |
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.
Is a __toString
really necessary? If you want the class name, you can just call it from the getter
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.
No.. i forgot to remove it. So ignore for now.
I'm not entirely sure what this does yet... But will this allow the addition of a "virtual" bundle? Basically hinting towards 2 things:
|
Yes, it should allow for virtual bundles. I dont get your 2 points fully yet, but i try to show a better POC this afternoon. |
I've taken some snapshots of how we've currently implemented it: class EntityPackage
{
public function __construct($name, $path, $namespace = '', $alias = '');
public function getAlias();
public function getName();
public function getPath();
public function getNamespace();
}
// ...
public static function load(&$bundles, $file = EntityInformation::CACHE_FILE)
{
$packages = (new EntityInformation($file))->getEntityPackages();
// Create and append HostnetEntityBundles for all entries.
foreach ($packages as $package) {
$bundles[] = new HostnetEntityBundle($package);
}
$bundles[] = new HostnetDoctrineBundle();
}
// and in the end of registerBundles() in AppKernel
HostnetEntityBundle::load($bundles);
return $bundles; Basically comes down to having entity packages which feature no bundle concept/dependency while still registering all of them as bundle once in symfony and hooking up their repositories to the DIC by registering them as services. |
Looks creative :-) no offense. Imho this looks more event related (ideally listening to kernel boot events that is). My need is to modify the containerbuilder from a bundle extension, based on the ecosystem (kernel info, bundle info, etc.). For exmple the twig issue which needs to act upon the bundle hierarchy. Having this available as a service would be so convenient :-) edit:
In a way, it solves #18563 pretty easy. Maybe to get my bigger picture, i want to decouple the way we (ab)use the See master...ro0NL:http-kernel/kernel-as-a-service to get an idea how i want to solve this. Eventually the kernel can be passed to a compiler pass, which registers/builds the kernel as a definition+service object (hence service aware definition). In early phase we have a useful kernel service object, later on, from cache we have the same service object. Via the kernel service you can get bundle vo's/metadata (anything but the real bundle interface). |
@ro0NL: Why not simply allow to use (undeprecate) |
Im not sure.. i can imagine this is a design choice. There are 2 phases (building and runtime), where there's only 1 container per phase (respectively However due the 1st phase we cant use it as a container throughout as it cant guarantee safe services yet (not fully built) when getting. Why setting direct (fully built) services is not allowed, im not sure.. like i said i guess it's a design choice: The Anyway, to adhere to all this, i chose for true service objects representing the ecosystem (ie they have a corresponding definition), which allows it to work in both phases (it introcudes a design change though to do that, so im curious about it). Eventually this allows also for separation of concerns (the kernel (functional), and kernel-service (informational/util)). To clarify, edit: master...ro0NL:http-kernel/kernel-as-a-service is a better poc now, so i guess im gonna close this one in favor of a new PR. |
This is a proof of concept to expose the bundle hierarchy and metadata in a early phase. For example when needed in a bundle extension. This makes the ecosystem a lot more flexible imho.