-
Notifications
You must be signed in to change notification settings - Fork 824
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
What is the purpose of backticks as a (yml) config value? #7987
Comments
AFAIK this is for constants, not env vars, but it does look like it might be broken in my testing too... |
Oh, right - it only works for silverstripe-framework/src/Core/Injector/Injector.php Lines 525 to 535 in 75a29b8
That’s a shame, it’d be nice to be able to use constants/env vars anywhere in config like this |
Yeah, I spotted the test for Injector, but also thought it was more generic than that. I'll leave it for the core team to make any further decisions as I have no opinion either way, but thanks for the clarification :) |
It's kind of like another injector-shorthand for "some evaluated value". Other examples:
|
@NightJar you should use |
For reference, I've logged an enhancement issue to add support for backticked env vars in all YAML config, rather than just in Injector definitions: silverstripe/silverstripe-config#37 |
That would be cool, but careful since environment variables can change as a result of code execution, but config vars cannot (are cached at boot time). |
FWIW, if you were determined to incorporate this yourself, you could probably still do it with some success, depending on your use case. I don't know of an easy way to allow you to decorate your YAMLs with environment variables anywhere you please, but if you're like me, you can probably settle for having them in just one or two places and then do the interpolation yourself and just update the config values in-situ using something like I realized that I needed this bad enough to justify the relatively simple implementation overhead (at least of defining these environment variables in just one place in my config). For anyone interested or googling and landing here, my implementation/hack is outlined at silverstripe/silverstripe-config#37 (comment). But, very basically: ---
Name: mysite-config-name
After:
- 'framework/*'
- 'cms/*'
---
Globals:
# These values are accessible via Globals::config()->Values['NAME']
Values:
SomeValue: '`ENV_VAR1`'
ComplexValue: 'The value `ENV_VAR2` can be interpolated mid-string as well.' So you just write some code to iterate over those values and interpolate the backtick values from |
Affected Version
silverstripe/framework
4.1.x-dev
99426cd
Description
I was under the impression that there is a specific syntax to parse environment variables into config values. e.g.
Where the environment variable value would then become the value of
some_setting
within that class's config context.However in testing this recently I was alarmed to find that this string literal was instead being requested as a URI endpoint for an external service
keeping with the example above -
var_dump($this->config()->some_setting);
Simply removing the config setting this value to the environment config resolved the issue (the code falls back from local (object instance) settings -> config settings -> environment setting).
I was then confused as to whether this functionality applied to environment settings, or to global constants. I added to
mysite/_config.php
a linedefine('SOME_ENV_VAR', 'thisisa.test');
This also failed. The resulting value attempted to be used by the code was the same as when testing with an environment variable.
Steps to Reproduce
In this particular case I am using an development environment with a
.env
file, however I hope that should be inconsequential.I am using
silverstripe/documentconverter
@c990914with
cwp/cwp-core
@a6aef24 providing the configuration.The text was updated successfully, but these errors were encountered: