-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[RFC] Enhance Kernel to allow removal of AppBundle concept (Advanced Usages) #20099
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
Comments
It is a very interesting approach, and, in my humble opinion, deserves a good talk or article with details and delicacies. I am particularly in favor of having entities outside of the AppBundle and controller as a service, however, the use-case for that is not in the reach of the newcomer who probably is more suited to a standard MVC layout. |
@sh4ka Basically I want this to start out as a more advanced usage. Once something is standing as is, I would like to iterate over it with DX to make it easy to use for new developers (or maybe even do all at once). Having no bundles means a new-comer could actually skip having to be told about bundles (and what they are), they can just get going. |
compiler passes can also be registered in the kernel, by overriding Prepending extension config is useless, as the kernel controls the main loading of the config. Just loads an extra config before the loading of the config_dev.yml file in your so the only missing point is the possibility to inject extra classes in the class cache @sh4ka having entities outside bundles is supported by DoctrineBundle since years. It requires a bit of config though, as DoctrineBundle cannot automatically discover them (there is no convention for finding entities outside bundles, as the convention is precisely based on bundles, so this goes into the configuration way) |
@stof I know about that functionality in Doctrine, is very handy. Just pointing out that the current docs (https://symfony.com/doc/current/doctrine.html#main) encourages newcomers to put them in the AppBundle. |
@sh4ka sure it does, as the recommended way in the Symfony doc is to use AppBundle. If the Symfony doc changes its recommendation, we will change the DoctrineBundle doc. The doc still shows how to configure mapping explicitly for people wanting it elsewhere. |
@stof that works fine until you want dynamically calculated paths. For KNP Snappy we resolve a path based on the OS (not using images). However, this is simply done in the load method of the extension: Regarding the class cache, this is simple a set method in the kernel that is being called from a compiler pass. So in theory a custom implementation could be added but is a bit of overhead. So while all of this is already possible, it's not really clear. In // new method in Kernel
protected function build(ContainerBuilder $container)
{
// register compiler passes in here like in the bundle build method
}
// new method in Kernel
protected function getClassesToBeCached()
{
return array();
}
public function setClassCache(array $classes)
{
$classes = array_merge($this->getClassesToBeCached(), $classes);
file_put_contents($this->getCacheDir().'/classes.map', sprintf('<?php return %s;', var_export($classes, true)));
} This means the kernel will get 3 new extension points:
of course names are up for discussion I think this would lay a decent foundation for something that might eventually end up as a best practice. Even if it wouldn't, it would give people a decent method to start removing their AppBundle if they wish to. |
See #20107 |
…build() (iltar) This PR was merged into the 3.3-dev branch. Discussion ---------- Added a build method to the kernel to replace Bundle::build() | Q | A | | --- | --- | | Branch? | master | | Bug fix? | no | | New feature? | yes | | BC breaks? | no | | Deprecations? | no | | Tests pass? | yes | | Fixed tickets | #20099 | | License | MIT | | Doc PR | ~ | Adds a DX method to make it easier to omit using an AppBundle in your application. **Old situation** ``` php // src/AppBundle.php class AppBundle extends Bundle { public function build(ContainerBuilder $container) { $container->addCompilerPass(new SomeCompilerPass()); $container->addCompilerPass(new AnotherCompilerPass()); $container->addCompilerPass(new YetAnotherCompilerPass()); } } // src/DependencyInjection/AppExtension.php class AppExtension extends Extension { public function load(array $config, ContainerBuilder $container) { $binary = ExecutableResolver::getPath($container->getParameter('kernel.root_dir').'/../'); $snappyConfig = ['pdf' => ['binary' => realpath($binary)]]; $container->prependExtensionConfig('knp_snappy', $snappyConfig); } } ``` **New situation** ``` php // rm src/AppBundle.php // rm src/DependencyInjection/AppExtension.php // app/AppKernel.php class AppKernel extends Kernel { protected function build(ContainerBuilder $container) { $binary = ExecutableResolver::getPath($container->getParameter('kernel.root_dir').'/../'); $snappyConfig = ['pdf' => ['binary' => realpath($binary)]]; $container->prependExtensionConfig('knp_snappy', $snappyConfig); $container->addCompilerPass(new SomeCompilerPass()); $container->addCompilerPass(new AnotherCompilerPass()); $container->addCompilerPass(new YetAnotherCompilerPass()); } } ``` Still missing tests, wondering if worth adding in this state first. Commits ------- 62e80fc Added build and class cache to kernel
you don't need |
While the AppBundle concept is already a big improvement, it's still a bundle. I have done some digging and I hope I've come up with a solution.
What is the AppBundle good for?
What additional stuff does it do under the hood?
Provides a basic entry point for:
What features does it have that are useless to applications as AppBundle?
My personal use-case
app/Resources/views
so I don't need the alias for templates eitherOf course this is based on my needs, but could be expanded on. Doctrine for example allows you to configure your AppBundle manually as well. If you look at it like this, the whole AppBundle concept is actually overhead, but it requires quite a bit more effort to get it to work using just the Kernel.
When looking at the list, there's only 3 things my application really needs from the bundle: Classes to compile, compiler passes and prepending extension config. I would like to add an extension point for those 3 points in the kernel (4 if you count the new 3.2 annotated class cache) to make it easier to use a bundle-less setup of Symfony.
Is this something people are interested in? Did I forget any cases? Should Symfony provide a default "fake bundle" entry point in a directory and namespace of your choosing, e.g. registering a virtual bundle?
The text was updated successfully, but these errors were encountered: