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
[RFC] Discussion starter: how could we best tackle Extensions? #492
Comments
I think this should be saved as a file in
Methinks that's pretty much unavoidable. It'll be up to the extension developers to make sure the initialisation is as simple as possible (as in: Try to do nothing, but register the extension)
I'd prefer to use
Can be prevented with this
Yes, that pretty much sums up the goal. :-) |
For stuff meant to be shared between different projects there is |
There's something to be said for both locations for extensions. Personally, I wouldn't make it configurable, since that's adding another variable to a user's setup that could make troubleshooting an issue harder, without a hard benefit. If we decide to plonk extensions into Of course, that might also be the biggest drawback: I could see autowiring and the DI you can do with it making a lot of extensions work far more Symfony-esque (or at least enable them to work that way), which is a plus in my book. As for storing the found extensions in a config file: yes, it'll enable us to switch extensions off and on, as a matter of fact you could add an If you do go the separate which-plugins-are-enabled file route, I'd just have an array of FQCNs, no need to add a 1 or 0. Not being listed in that array means the extension is disabled. Using the FQCN means never having name collisions there. |
This might be interesting to take a peek at: https://github.com/heiglandreas/wp_talkToComposer |
There's something to be said for that - just roll plugins into the regular Edit (because post bike-ride-to-work clarity): also, if we were to drop extensions into Doing that might make the whole discovery and tagging song and dance I outlined above superfluous, by the way. If we're going to explicitly point at stuff, there's no need for that. |
It does have some benefits for sure, but it also has one mayor drawback that I can think of: Installing or removing extensions will force a We should keep in mind that we're dealing with different audiences here: the people who keep dependencies in check, like which exact bolt version and composer versions are being used, are not necessarily the same people that will add the "Bolt SEO" or "Add Facebook spyware"-extensions. additionally, the autowiring looks much more straightforward if we keep them in |
Add the Interface, Registry, Compiler pass and Kernel glue. See bolt#492
Unless you call |
I didn't know about that flag. 🤔 I can't find much about it online, but my mind is too small to comprehend how that would work if the newly installed package comes with its own dependencies or version constraints. |
It will only install what is required for the new dependency and stop if some current deps needs an update to work with the new one. |
OK, if that's the case, let's go for |
Yes, it will also rise a namespace conflict between vendors. But there is https://getcomposer.org/doc/06-config.md#vendor-dir which could point extension's vendor to project's vendor dir, so it's not a problem. However
This is a very strong argument as Bolt and it's extensions are also dependencies for a project. |
I'd like to close this for now. So far, we have working extensions. If they need improvements, we'll open more focused issues. |
This relates to #134
A couple of weeks ago I asked Bob how he figured Extensions would fit into B4, and he figured
after which I hinted at having implemented something similar in an application somewhere, and promising to do a little write-up about how that works. That got me thinking that the way I used in that application might not actually fullfil the entire need Bolt has, but at least it could get things started, people might have some ideas, and so on. So without further ado:
How to get Symfony to do special things to classes implementing a given Interface
Actually the whole thing is quite simple, and consists of the following parts:
The Interface
In fact, the interface doesn't need to do anything to be useful. Bob mentioned that the Interface could define an initialize function to be run (possible); what I did in my project was make sure the implementor can identify itself.
All code below is barely above pseudocode level, in real life this should all be properly namespaced (probably under \Bolt\Extension) et cetera.
That's all.
The registry
For the registry, we need to be able to add implementors, retrieve them, etc.
Getting the implementors into a repository
Finally, at compile time, we need to grab all our implementing classes and have them stuffed into the repository. This is done using a CompilerPass:
The CompilerPass is called from within
kernel.php
:Create an extension
Boom, done.
At this point we can inject the
ExtensionsRepository
and Do Things™ with extensions. Of course, now that I'm typing all this "from a distance" the registry starts smelling like a service locator, which some people might take offence at. Of course it's still very possible to do something else in the CompilerPass, like runinitialise()
on all the tagged implementors as Bob envisioned.The things I'm somewhat less than happy with:
/src
directory as per Symfony standard - that means that extensions can depend on one another and things can get tied up.That feels less than clean to me as a user - this feels like giving up on a lot of control. I'd prefer nothing in the extensions space to be autowired, except for the implementing "main" extension class, which can then do the things it needs to do.
This is where the "discussion" bit comes in.
The idea is that Bolt ends up with a simple, safe and elegant way for extension developers to extend it, and for Bolt users to install those extensions and use them. I'm sure there's some folks with an even better idea than me about how to keep this solution clean enough for a situation where we can have an arbitrary number of extensions from arbitrary sources - a scenario that my application doesn't encounter, I am the sole creator of modules (as they're called there), so I know what I can and cannot (and should and should not) do in them.
I also see some relation with the Bundle system of old, that was removed from Symfony - I know the system was there, I roughly know what it did, but since I didn't do a whole lot of Symfony back then I'm not sure if they'd be a great fit for this task, or what the exact reason was for them being axed from Symfony. If someone has some relevant info on that, I'd personally love to hear it.
Thoughts, ideas and critique welcome!
The text was updated successfully, but these errors were encountered: