-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[WIP][DX] Automatic registration of installed bundles #695
Conversation
👍 Just an idea for that: We could use an |
@hacfi: I like your idea :) . I don't think that people would add a parameter to their bundle's |
While we’re at it: Should we consider adding a way to provide a default config file which gets appended to the config.yml? |
That would be the easier way to provide automatic configuration (we've tried many times to implement it using the Config Tree, but to no avail). The only downside of this idea is that it requires the community to update their bundles |
@gnugat As it’s optional I don’t think that’s a problem. Active bundles will eventually add a default config and for the other ones you have to add the config manually as you do these days. |
Hey @gnugat! I just tried the bundle commands and they worked great! I like them because (A) they work and (B) they stay out of the way (I choose to use them). I'm less convinced about the composer plugin part, at least for now. Because: So I'm +1 for the bundle but -1 for the plugin. What do others think? And also, would we need/want to move the bundle into either a sensio or symfony namespace (this is something @gnugat and I were wondering). Once we agree, then we could continue to work on the bundle - clean up a few small things, and see about the bundle configuration command. Thanks! |
Hey @weaverryan! I'm glad the bundle suits you. If @fabpot or any symfony (core?) contributor agree with moving it to sensio or symfony, then it's ok for me :) . |
nice approach @gnugat however the problem starts when you have to have your bundle installed for all of this to work which is a manual step unless installing the plugin also installs the bundle. @weaverryan i don't think we do manipulation of bundles on production so not sure where would this mean problems on deployment. |
How does this work for bundles that depend on other bundles? For instance, the sonata admin bundle needs 4 other bundles in order to work. |
With the plugin, this is handled nicely by composer: it installs the highest dependencies first and fires the event on each installation (so the plugin installs each bundle in the correct order). The only case which isn't handled yet: |
What's the status of this PR? |
I'm ready to make any required changes for this to happen. What are the current blockers? |
Hey @gnugat Hmm, now I'm -1 on this. But here's why:
So, I'm just not clear now that there is a big enough problem worth solving. I have talked to people before that disagree with me, and say that this functionality (modifying AppKernel) should exist, and that it should also be smart enough to take into account that one bundle depends on another (e.g. HautelookAliceBundle also require DoctrineFixturesBundle), but we don't have that information currently. So, I don't see a path from here - but @gnugat please let me know what you think :). Thanks! |
Hi @weaverryan, I agree with you, only the composer plugin is worth the installation, so if in the end you choose not to use it we can close this PR. I'd like you to know that I really understand your concerns about newcomers, but on the other hand this kind of "magic" behaviour already exists: when Finally, regarding the dependency issue, Composer installs the highest ones first, so in your example it will first install I'll soon have the time to (finally!) take your advices into account and make it way more simple, so I'm putting this PR in a WIP state, if you don't mind :) . |
@gnugat hmm, nice point about the
I'm still not sold, but maybe .... ;) |
And what about bundles that depends on many other bundles ? When you want to install For this feature, maybe we should think about old issues like #598 and #608. By the way, it would be great to have such a feature, but it's primordial not to force the user to use this feature when it's available. In fact, if the command prompts the user for automatic bundle install if the composer dependency is a |
@Pierstoval oh, I didn't know SonataAdminBundle couldn't be installed via "composer require". I'll have a look. @weaverryan it would be interesting to know if beginners need to know about the existence of AppKernel, but I suppose we can't use something like A/B testing to find out... |
@gnugat SoantaAdminBundle is like any other Symfony libraries, it's a package that is installed through composer, but the problem is that it depends on SonataCoreBundle and SonataBlockBundle. And it's becoming even worse if you want the SonataPageBundle, it depends on the Admin, Core, Block, Seo, Cache, Grid bundles from Sonata, but also with FosRestBundle, JMSSerializerBundle and NelmioApiBundle. Do you see ? It depends on no less than 12 bundles, and it's strongly recommended to use a 13th bundle, SonataDoctrineOrmAdminBundle. That's why I'd be more interested in setting up bundle dependencies instead of setting up bundle auto-registration after composer install. |
@Pierstoval I've taken a look at SonataAdminBundle, and it says the following:
As I've said above, this kind of dependency is absolutely not an issue with wizard-plugin. It is a composer plugin hooked on the "package installed" event, which means that it would proceed as follows:
To be fair Composer did a pretty good job here, so wizard-plugin hasn't to take care of it on its own. The bundle you install can have many dependencies, and those can have even more dependencies on their, it won't be a problem: they'll all be registered in the right order. |
Wow, then it's simply AWESOME if it works well 😄 |
I think this is a good idea, given, as @weaverryan suggested, that it asks for "permission". Better yet would probably be a y/n/? option, where the ? option shows a small piece of text on the subject of "What is the AppKernel, and why does it need to be updated?", with a link to the docs, before asking again. Furthermore, I would suggest standardising some way in which bundles could opt-in to show a "post-install" note pointing the user to any other steps required to complete installation of the bundle. As an example, DoctrineFixturesBundle doesn't require additional steps for installation and wouldn't show anything install notes, but LiipImagineBundle would probably add a note about requiring the user to update their routing.xml, and pointing them to documentation on the subject. The same goes for bundles with mandatory configuration. |
A "post-install" note can be very big if packages want to give many informations. imagine installing, as explained before, SonataPageBundle, it'll install more than a dozen of bundles, just imagine how dirty your console would look after installing all these packages. A simple link to the different READMEs or a link to another documentation might sound better The "Auto-registration" prompt should probably better be a "yes/no/all/none" , if you select "yes" or "no", it still asks for other packages, unless you answer "all" or "none", I think it's better. |
@Pierstoval Well, terseness would be up to the package author, but unless it's really simple, a link to the appropriate section of the readme is probably best, yes. Hopefully most of the dozen bundles required by SonataPageBundle wouldn't require any install notes at all. Also, while it is useful to look at the "worst case" scenario, the most common case is a bundle has no dependencies, or like one or two dependencies total, in which case an install note still makes sense. |
As you might guess, the main challenge here is to convert a Composer package name into the bundle's Fully Qualified Classname. |
@gnugat How about using Symfony Finder and look for a file called |
@hacfi that's basing on conventions. Bundle classes don't have to be suffixed with Bundle. |
Ok..wasn’t aware of that as this convention is used so often. Then the only way would be checking if any class of the .php files in the main directory (taken from composer’s PSR-4 path) extends |
@hacfi good idea, I'll try that. It won't handle everything, but it's better than nothing |
It’s kind of the brute force attack but as you said - there is no other way. As this operation doesn’t happen too often we can ignore the performance. |
I agree @hacfi for using a composer attribute in The problem with searching automatically is that it can be a problem for a few bundles when they have the bundle instance in their tests directory, so it looks a bit dirty to me :/ |
@Pierstoval Good point..but we could try if excluding the directories |
Even if it is a good idea, it can be a problem IMO. In fact, what you are expecting to be "usual" is unfortunately not "standard", and it is both non-permissive and too permissive. Too permissive because the user and developer don't have to do anything, which is great, but non-permissive because it would not allow one to use the "Test" keyword in his bundle name. That said, you can do as you want for this feature, as it's yours :) It's just my opinion ;) |
As discussed here, this PR integrates the Wizard Bundle in the Standard Edition.
On each
composer require ...
, this library will:AppKernel
(if not already registered)It depends on a Bundle which provides a the two following commands:
wizard:register:bundle
: registers the given FCQN in theAppKernel
(useful when a bundle has been created manually)wizard:register:package
: converts the given package name into a FCQN and registers it in theAppKernel
(useful when a bundle has been unregistered, but is still installed, and needs to be enabled again)