-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Have a common way to override services per storage #11460
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
Bundles already handle this by defining a set of backend specific services as private, and setting an alias for the appropriate one to a primary service id based on configuration. Private services not referenced get removed by a cleanup compiler pass. https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/config/orm.xml#L8 defines a default service, and the extension class then sets an alias based on its configuration: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/DependencyInjection/FOSUserExtension.php#L48 This lets the developer define their own service and tell the extension about it and that it should become the manager. |
What the code of drupal allows is something like the following: lock: As a site adminstrator you just need to set 'default_backend' and mysql.lock will be automatically aliased to lock |
The code I linked achieves the same thing. |
I don't see how this is done in a generic way for all possible storages. On Thu, Jul 24, 2014 at 11:40 AM, Tim Nagel notifications@github.com
|
@dawehner You define every possible storage as private service and you use a (non-yet used) service-id as dependency for every occurence, where one of this storages is required. In your $storageName = $config['storage']; // For example "redis"
$container->setAlias('foo_bar.storage', "foo_bar.storage.$storageName"); or if you want it super-generic use the full qualified service id in the configuration instead (that's what you can see in the links given by @merk ) |
So it is not automatic as proposed in the issue ... This is not a support
|
It can be handled by a simple compiler pass that looks for a parameter and handles this without tags. I'm not talking about support - I'm mentioning that this is already possible with very little additional effort on top of a container. |
I totally don't argue against that, I think we have kind of a communication problem. I just wanted to ask whether symfony would like to have such an automatic backend switching system included, maybe in FrameworkBundle. |
I don't think it can be in FrameworkBundle. You can have different bundles supporting to choose their backend while the choice in one is totally independant from the choice in others (potentially with different values for the choice items btw). Making something generic in FrameworkBundle would probably end up being more complex than having the bundle handling the config it needs. |
Just talked with @Crell about this one. So, basically, that's interesting but if it should be more generic than the Drupal use case. The problem Drupal is trying to solve is to automatically create aliases based on some parameter value. We could imagine a tag that makes this easier to achieve, based on some conventions/options:
And the compiler would make lock an alias for |
I like the more generic format @fabpot suggests. It's a little bit more wordy for the person setting up the service but gives more flexibility. (One could have multiple "classes" of swappable services this way, which is nice.) I don't know if we could switch Drupal's syntax to that now that we're in beta but I would not object to doing so. |
@javiereguiluz I don't have any special recommendations here, except that it's going to be in 2.7. |
Which hopefully will be the version in which d8 ships |
I'm OK with an API change in Drupal to use the Symfony format if that's added since the one we added isn't used much yet. However the change would need to be made before we start supporting an upgrade path between betas (which doesn't have an explicit timeframe - it's tied to issues fixed). |
This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #12526). Discussion ---------- Add an auto_alias compiler pass Discussion see #11460 | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | [#11460] | License | MIT | Doc PR | Commits ------- d7432c0 Add an auto_alias compiler pass
In Drupal we want to deal with the problem that some services are bound to the database, for example a lock service. Per default this is using the database but you might want to use something else.
You can for sure always write a compiler pass and replace the service with one for your wanted backend like redis (just as example). This is quite annoying if you as a developer have a lot of services, or you just want to switch the storage as site administrator.
We came up with a schema which basically allows you to set a tag on these services (https://www.drupal.org/node/2302617). A pass will then try to look up "$backend.$service" services, with $backend being a configurable container parameter. This for example allows us to write mysql specific optimizations into "mysql.$service".
I wonder whether you are interested in a generic functionality. Given the structure I guess this should be part of some bundle, so it is not reusable but at least we would have a common functionality.
The text was updated successfully, but these errors were encountered: