Skip to content

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

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 15, 2021

Conversation

bpolaszek
Copy link
Contributor

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):

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

@xabbuh xabbuh added the Waiting Code Merge Docs for features pending to be merged label Feb 14, 2021
@carsonbot carsonbot added this to the next milestone Feb 14, 2021
fabpot added a commit to symfony/symfony that referenced this pull request Feb 14, 2021
… (bpolaszek)

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

Discussion
----------

[DependencyInjection] Negated (not:) env var processor

| 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:

```bash
FOO=yes
BAR=off
```

```yaml
# 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

Commits
-------

56545fd [DependencyInjection] Negated (not:) env var processor
@OskarStark OskarStark removed the Waiting Code Merge Docs for features pending to be merged label Feb 14, 2021
@OskarStark OskarStark modified the milestones: next, 5.3 Feb 14, 2021
Copy link
Contributor

@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

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

Please add a versionadded directive, thank

@bpolaszek
Copy link
Contributor Author

Please add a versionadded directive, thank

Sure, here it is.

@OskarStark OskarStark force-pushed the feat/negated-env-var-processor branch from 486d495 to 3ff812d Compare February 15, 2021 07:29
@OskarStark
Copy link
Contributor

Thanks @bpolaszek for working on this feature, this is much appreciated.

@OskarStark OskarStark merged commit 86a577a into symfony:5.x Feb 15, 2021
@bpolaszek bpolaszek deleted the feat/negated-env-var-processor branch February 15, 2021 11:01
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.

4 participants