Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[DI] Add a "default" EnvProcessor#28976
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
ro0NL commentedOct 25, 2018
why not stick with |
jderusse commentedOct 25, 2018
@ro0NL because sometime the env variable exist, but the processing doesn't. See my examples. |
ro0NL commentedOct 25, 2018
understood. Im a bit skeptical about making values part of the prefix string, but i cant think of anything better either. |
nicolas-grekas commentedOct 25, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
That won't work as the |
| 4.3.0 | ||
| ----- | ||
| * added`%env(catch:...)%` processor to catch exception and fallback to a default value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
it must be(catch:...:DEFAULT_KEY) right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
to be consistent withadded %env(key:...)% processor
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
| } | ||
| $next =substr($name,0,$i); | ||
| $default =substr($name,$i +1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
perhaps check to be non empty, im also worried it causes confusion as the last segment will always be used. If you forget it, another part will be implicitly used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
refactored the logic todefault:fallback:origin in order to catch onlyNotFoundException and letRuntimeException bubble
src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
jderusse commentedNov 5, 2018
Thank your for the review@ro0NL , changed the logic in the PR to trap only the |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
| return$getEnv($next); | ||
| }catch (EnvNotFoundException$e) { | ||
| if (!$this->container->hasParameter($default)) { | ||
| thrownewEnvNotFoundException(sprintf('Parameter "%s" not found. (fallback from not found "%s")',$default,$next),0,$e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
sprintf('Invalid env fallback in "default:%s": parameter "%s" not found.', $name, $default)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
should it be a runtime exception btw?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
fix message.
what's aboutdefault:my_fallback:default:optionnal_parameter_injected_by_third_party:foo?
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterEnvVarProcessorsPassTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
b7e1db3 to16461d6Compare| * | ||
| * @author Nicolas Grekas <p@tchwork.com> | ||
| */ | ||
| class EnvNotFoundExceptionextends InvalidArgumentException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
while at it..extends RuntimeException?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
If the variable is not found or a a key contain a typo, it make sens to be a logic exception.
javiereguiluz commentedNov 7, 2018
@jderusse your examples are great as always ... but would this feature require any changes in Symfony apps? (both when using it as a stand-alone component and when using it as part of a full-stack Symfony app). Thanks! |
jderusse commentedNov 7, 2018
@javiereguiluz Same implementation thant#28975 😉 |
nicolas-grekas left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
please submit a doc PR or doc issue at least
nicolas-grekas commentedDec 1, 2018
Thank you@jderusse. |
This PR was squashed before being merged into the 4.3-dev branch (closes#28976).Discussion----------[DI] Add a "default" EnvProcessor| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | -| License | MIT| Doc PR | TODOThis PR add a new fallback env processor in order to return a default value when the primary processor is not able to fetch a value (env variable, file or key does not exists)```#default_host: localhosthost: '%env(default:default_host:OPTIONAL_ENV_VARIABLE)%"default_secret: this secret is not secretsecret: '%env(default:default_secret:file:THIS_FILE_ONLY_EXIST_IN_PRODUCTION)%"default_charset: utf8charset: '%env(default:default_charset:key:charset:json:DATABASE_CONFIG)%"```Commits-------aee4e33 [DI] Add a \"default\" EnvProcessor
This PR was merged into the master branch.Discussion----------Add env default processorThis PR documentssymfony/symfony#28976Commits-------8d3afcc Add env default processor
itscaro commentedJan 9, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Hey guys, awesome work! thanks for this change. But IMO, the syntax is a little bit illegible, if it would be great to use the syntax in shell I can do a PR for that, wdyt? |
… "default" one (nicolas-grekas)This PR was merged into the 4.3-dev branch.Discussion----------[DI] replace "nullable" env processor by improving the "default" one| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | -| License | MIT| Doc PR | -Neither `nullable` nor `default` are released yet.I propose to replace the `nullable` processor (see#29767) with an improved `default` one (from#28976).`%env(default::FOO)%` now defaults to `null` when the env var doesn't exist or compares to false".ping@jderusse@bpolaszekCommits-------c50aad2 [DI] replace "nullable" env processor by improving the "default" one
rubenrua commentedApr 16, 2019
IMHO and my devops team Let me know in a new pull request with this rename and creating a new |
Uh oh!
There was an error while loading.Please reload this page.
This PR add a new fallback env processor in order to return a default value when the primary processor is not able to fetch a value (env variable, file or key does not exists)