-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add fallback value syntax for ini variables #11351
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
Conversation
529ff3c
to
4a5eaac
Compare
@Misterio77 Thank you for your PR! You might get away with just a mail to the mailing list, if nobody objects to the change. If there are discussions on semantics or the usefulness then an RFC is definitely in order. |
95b6c39
to
735ff4a
Compare
I redid this and now fallback is a You can do some cool stuff such as nesting:
If you're using the typed parser, numbers become numbers, as expected:
Both are
|
735ff4a
to
d659c90
Compare
@Misterio77 I pushed the changes for making |
Thanks a lot for helping out, @iluuu1994! I will send an email to the list shortly |
Did you announce this on the ML? I wasn't aware of this... and spend some time on #11661 which is a much simpler solution (I guess, with some different drawbacks). |
Sent an email myself now: https://news-web.php.net/php.internals/120805 |
Hey @derickr, Life got in the way and I couldn't quite muster the energy to write the email. Thanks a lot for sending it! :) |
Would it make sense to improve
Would be extended with env var clause and default to default values, like:
|
Hey @brzuchal, I think it does make sense! Maybe as a separate PR after we merge this one? |
Hi, all!
This PR implements fallback/default values when substituting variables on ini files, like:
${VAR:-fallback}
. I was actually surprised this wasn't implemented yet, as it's a very useful feature.I know a thing or two about lexers/parsers, but it's not something I'm super familiar with, so let me know if there's any way this can be improved!
At the moment, the fallback value is treated similarly to a raw string, so it does not support arbitrary expressions (such as nested variables), I couldn't get it to without adding state pushes and pops everywhere on the lexer.It works similarly to offsets/sections now, and supports nesting!As I understand, this should go through the RFC process? If so, I'm totally okay with writing one :). Let me know if there's any etiquette I might have missed, too.
As an example, my usecase is using environment variables to configure php-fpm, while also having some sane defaults. Like so: