Skip to content

[DependencyInjection] Negated (not:) env var processor #40169

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

Merged
merged 1 commit into from
Feb 14, 2021

Conversation

bpolaszek
Copy link
Contributor

@bpolaszek bpolaszek commented Feb 12, 2021

Q A
Branch? 5.x
Bug fix? no
New feature? yes
Deprecations? no
License MIT
Doc PR symfony/symfony-docs#14976

This little PR suggests a not: env var processor (in a perfect world, I would name it !: but only words are accepted as prefixes 🙃)
Goal is to negate a boolean env variable.

Example usage:

FOO=yes
BAR=off
# config/services.yaml
parameters:
    not_foo: '%env(not:FOO)%' # false
    not_bar: '%env(not:BAR)%' # true

I'm thinking of this for this kind of usages:

  • some_prod_related_stuff: '%env(not:APP_DEBUG)%'
  • enabled: '%env(not:bool:key:disabled:query_string:SOME_DSN)%'

Processor raises an exception when preceding resolved value is not a boolean.
This processor allows any truthy/falsy values, like bool:.

Thank you,
Ben

@bpolaszek bpolaszek force-pushed the feat/negated-env-var-processor branch 2 times, most recently from bbf79ba to bf08da7 Compare February 12, 2021 21:37
@bpolaszek
Copy link
Contributor Author

Travis seems unhappy, doesn't look related.

@bpolaszek bpolaszek changed the title Feat: negated env var processor [DependencyInjection] Negated (not:) env var processor Feb 12, 2021
@bpolaszek bpolaszek force-pushed the feat/negated-env-var-processor branch from bf08da7 to 0205893 Compare February 13, 2021 08:33
@nicolas-grekas nicolas-grekas added this to the 5.x milestone Feb 13, 2021
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks 😊

@nicolas-grekas
Copy link
Member

( but see CI )

Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI failures are unrelated. The component's changelog needs to be updated though

bpolaszek added a commit to bpolaszek/symfony-docs that referenced this pull request Feb 14, 2021
bpolaszek added a commit to bpolaszek/symfony-docs that referenced this pull request Feb 14, 2021
@bpolaszek
Copy link
Contributor Author

Changelog updated, doc PR submitted here.

@fabpot fabpot force-pushed the feat/negated-env-var-processor branch from b42c825 to 56545fd Compare February 14, 2021 10:22
@fabpot
Copy link
Member

fabpot commented Feb 14, 2021

Thank you @bpolaszek.

@fabpot fabpot merged commit 7ed7217 into symfony:5.x Feb 14, 2021
@bpolaszek bpolaszek deleted the feat/negated-env-var-processor branch February 14, 2021 15:30
OskarStark added a commit to symfony/symfony-docs that referenced this pull request Feb 15, 2021
… (bpolaszek)

This PR was squashed before being merged into the 5.3-dev branch.

Discussion
----------

[DependencyInjection] Negated (not:) env var processor

This PR adds documentation for symfony/symfony#40169: negated env var processor:

------
Casts to a bool (just as `env(bool:...)` does) except it returns the inverted value(falsy values are returned as `true`, truthy values are returned as `false`):

```yaml
# config/services.yaml
parameters:
    safe_for_production: '%env(not:APP_DEBUG)%'
```

Commits
-------

3ff812d [DependencyInjection] Negated (not:) env var processor
@fabpot fabpot mentioned this pull request Apr 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants