-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Put enabled bundles in a configuration file #598
Conversation
Currently, the easiest way to enable a bundle is to manually edit the AppKernel (vs programmatically). Enabling a bundle programmatically involves [Reflection and Zend engine's lexical scanner](https://github.com/sensiolabs/SensioGeneratorBundle/blob/9e29c8e898b98da6a3b63de80ad7679305262308/Manipulator/KernelManipulator.php#L46), how ridiculously complex! So here's my proposal: use a configuration file to register bundles. We have a configuration file which allows to register unrestricted bundles (bundles available in every environment) and restricted bundles (bundles available in the given set of environments).
$yaml = new Parser(); | ||
$bundlesConfig = $yaml->parse(file_get_contents(__DIR__.'/config/enabled_bundles.yml')); | ||
foreach ($bundlesConfig['unrestricted_bundles'] as $bundle) { | ||
$bundles[] = new $bundle(); |
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 makes it impossible to use bundles requiring to pass the kernel as first argument (i.e. some JMS bundles)
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 don't really see what you mean, could you give me some links so I can look at some code?
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.
Ok I see, it's about annotations, right?
Is there anyway to work around?
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.
Now that I think of it, "impossible" is a bit too strong: the AppKernel
file is still open to modifications, so the good old way would stay possible (adding $bundles[] = new Acme\Bundle\DemoBundle($this);
before the return statement).
Or if you like to make things complex, you could add a bit of reflexivity to check if the bundle needs an argument, and pass it $this
.
Or you could add some more options in the YAML file to provide constructor arguments.
Bundles being enabled in configuration vs in AppKernel makes a lot more sense to me. However we don't want to be parsing that yaml file on each request (as with 71f9989), it would need to be part of a caching pass |
@peterjmit that makes sense. Could you provide us with a prototype? |
This has already been discussed in the past and rejected. |
Oh, I didn't know (couldn't find an issue related to this, and google contains too much noise). Could you provide us with a link so we can be reminded of the reasons? |
Hmm, if it's not possible to update the kernel to load bundles with a configuration file, maybe you can create a bundle that reads a configuration file (it can have dependencies on main config files parser) to automatically add other bundle. That way you will have only the BundleLoader registered in your appKernel, and every other bundle you want are loaded following your configuration file. This should solve the problem mentioned by Stof (about bundles that require kernel as first element). |
@emerick42 as a matter of fact, this PR came to my mind because I'm already working on a bundle that would help to install bundles. The problem mentioned by Stof isn't really one, as the |
Allows to show that bundles can still be manually registered (for example bundles that have a dependency on the AppKernel).
* usage of convenient wrapper Yaml::parse * combined usage of: * instanciator: anonymous function to convert fully qualified classnames into instances * array_map to apply instanciator * array_merge for restricted bundles
I updated the code to show that bundles can still be manually registered (for example bundles that have a dependency on the AppKernel). Also refactored a bit. |
|
hey @lyrixx
I just felt that adding a bundle to the application was more a configuration thing... But I guess I was wrong. Do you think the AppKernel generation would be wise? If you do I can try something in this direction. |
For now, I don't have any thought ;) I guess we can wait for symfony/symfony#9341 |
Like I wrote, the process of registering bundles is actually a registration, so it should not need to be coded. |
Closing in favor of #639, which a meta-issue about things we might improve in the future but for which we don't have the solution yet. |
Enabled bundles in a configuration file
The problem
The simple task of enabling programmatically a bundle is too complex: it involves Reflection and Zend engine's lexical scanner.
The proposal
Put enabled bundles in a configuration file:
Impact on the community
Bundles installation documentation
Current bundle installation instructions will be still valid.
KernelManipulator
BC break on KernelManipulator implementations, but easy to fix (manipulating a YAML file instead of actually modifying the source code).
It all depends on how many people would be affected.
Except the SensioGeneratorBundle, do you know any library that would be affected?
What do you think?
This is just a draft, so if you have any improvements, be sure to propose them!
If the idea of putting enabled bundles in a configuration file is terribly silly, go on and say it: I'd like to know your arguments.