-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] Unable to use env() on params passed to ReplaceAliasByActualDefinitionPass #21609
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
Aliases cannot use parameters at all (since Symfony 2.0.0), be there env variables or no. And btw, supporting env variables there is a no-go IMO. The whole point of env variables is that they are resolved at runtime. And aliases are validated and resolved at compile time. Adding a dynamic target for an alias would require rewriting all code dealing with aliases (and adding overhead for all aliases in the container, to check at runtime whether they need to be resolved dynamically...) |
I suggest opening an issue on swiftmailer bundle instead, this is where the issue exists: too many logic done at compile time |
@nicolas-grekas this issue comes from MonologBundle. And processing the whole bundle config at runtime to decide which handlers to create and how looks insane to me. I don't think the overhead it will add is justified, compared to being able to switch the logger handlers at runtime without a deployment (thus, most of them expect different configuration settings, and potentially different dependencies, so it would simply not work). |
indeed :) |
btw, the same is true for the swiftmailer transport: each transport expect different config settings |
Well there is still option B and C available :) |
Why not use |
They are rather pointless, they are overridden by defined parameters making them useless for the case at hand (yml having defaults, env being able to override), hence support use with and without.
I did get rid of |
OK. You can also do that in your bundle extension: resolve env vars and inject them in params. That'd be 100% compile time. |
true, but if symfony came with something like |
I'd be in favor of closing this one, and replacing it with a doc issue. IMHO, we should not provide helpers to make people use env vars at compile time. Doing so means making the container not runtime-configurable for the corresponding envs. While there are legitimate use cases to do so, there are already ways to do that (the simplest one being to |
ok |
is there a way to shut down the %env()% trick? honestly i ran into so many issues with it that i just use a parameters.php to do set my parameters, wasted a lot of time because of this. |
@cordoval it's not really a trick but a feature :) And there's no direct way to disable it ... but there's an indirect way: not using it in any config file. |
thanks @javiereguiluz i know the features are with good intentions, just so frustrating 👴 uff uff |
It's stated in #20434 that env variables currently does not support being used in place for service names, which limits it's usefulness.
Is there plans to provide a best practice around this?
Possible alternatives:
A.
Change how configuration of handlers are done to allow switching service on runtimeDoes not make sense as pointed out by @stof below, often you need to compile config depending on a handler, this is something to do at compile time and not run timeB. Introduce a compile time env variable support as well so we can also be allowed to inject variables at compile time without having to resolve to custom env.php kind of solutions.
C. If there are no plans to tackle this with additional features, improvment potential here is to improve doc and more clearly throw on use like this as done in #20687.
Example:
The text was updated successfully, but these errors were encountered: