Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DependencyInjection] Document %env(...)% dynamic parameters#6918

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

Merged
xabbuh merged 1 commit intosymfony:3.2fromnicolas-grekas:env-params
Dec 14, 2016

Conversation

@nicolas-grekas
Copy link
Member

@nicolas-grekasnicolas-grekas commentedAug 25, 2016
edited
Loading

$container->setParameter('env(DATABASE_HOST)', 'localhost');
Unlike ``SYMFONY__`` prefixed environment variables, ``%env(...)%`` parameters are
truned into run-time environment variable reads, so that dumped containers can
Copy link
Contributor

Choose a reason for hiding this comment

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

turned

@nicolas-grekasnicolas-grekasforce-pushed theenv-params branch 2 times, most recently fromd816802 to9f7017eCompareAugust 25, 2016 12:39
be reconfigured dynamically even after being compiled.

..versionadded::3.2
``env(...)`` parameters were introduced in Symfony 3.2.
Copy link
Member

Choose a reason for hiding this comment

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

please put the versionadded directive after the section header, instead of at the end

@wouterj
Copy link
Member

status: needs work

@javiereguiluzjaviereguiluz changed the title[DI] Document %env(...)% dynamic parameters[WCM][DependencyInjection] Document %env(...)% dynamic parametersAug 29, 2016
fabpot added a commit to symfony/symfony that referenced this pull requestSep 15, 2016
…env(MY_ENV_VAR)% (nicolas-grekas)This PR was merged into the 3.2-dev branch.Discussion----------[DI] Allow injecting ENV parameters at runtime using %env(MY_ENV_VAR)%| Q             | A| ------------- | ---| Branch?       | master| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#10138,#7555,#16403,#18155| License       | MIT| Doc PR        |symfony/symfony-docs#6918This is an alternative approach to#18155 for injecting env vars into container configurations.With this PR, anywhere parameters are allowed, one can use `%env(ENV_VAR)%` to inject a dynamic env var. Additionally, if one sets a value to such parameters in e.g. the `parameter.yml` file (`env(ENV_VAR): foo`), this value will be used as a default value when the env var is not defined. If no default value is specified, an `EnvVarNotFoundException` will be thrown at runtime.Unlike previous attempts that also used parameters (#16403), the implementation is compatible with DI extensions: before being dumped, env vars are resolved to uniquely identifiable string placeholders that can get through DI extensions manipulations. When dumped, these unique placeholders are replaced by dynamic calls to a getEnv method..ping@magnusnordlander@dzuelke@fabpotCommits-------bac2132 [DI] Allow injecting ENV parameters at runtime using %env(MY_ENV_VAR)% syntax
symfony-splitter pushed a commit to symfony/http-kernel that referenced this pull requestSep 15, 2016
…env(MY_ENV_VAR)% (nicolas-grekas)This PR was merged into the 3.2-dev branch.Discussion----------[DI] Allow injecting ENV parameters at runtime using %env(MY_ENV_VAR)%| Q             | A| ------------- | ---| Branch?       | master| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |  #10138, #7555, #16403, #18155| License       | MIT| Doc PR        |symfony/symfony-docs#6918This is an alternative approach to #18155 for injecting env vars into container configurations.With this PR, anywhere parameters are allowed, one can use `%env(ENV_VAR)%` to inject a dynamic env var. Additionally, if one sets a value to such parameters in e.g. the `parameter.yml` file (`env(ENV_VAR): foo`), this value will be used as a default value when the env var is not defined. If no default value is specified, an `EnvVarNotFoundException` will be thrown at runtime.Unlike previous attempts that also used parameters (#16403), the implementation is compatible with DI extensions: before being dumped, env vars are resolved to uniquely identifiable string placeholders that can get through DI extensions manipulations. When dumped, these unique placeholders are replaced by dynamic calls to a getEnv method..ping@magnusnordlander@dzuelke@fabpotCommits-------bac2132 [DI] Allow injecting ENV parameters at runtime using %env(MY_ENV_VAR)% syntax
symfony-splitter pushed a commit to symfony/dependency-injection that referenced this pull requestSep 15, 2016
…env(MY_ENV_VAR)% (nicolas-grekas)This PR was merged into the 3.2-dev branch.Discussion----------[DI] Allow injecting ENV parameters at runtime using %env(MY_ENV_VAR)%| Q             | A| ------------- | ---| Branch?       | master| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |  #10138, #7555, #16403, #18155| License       | MIT| Doc PR        |symfony/symfony-docs#6918This is an alternative approach to #18155 for injecting env vars into container configurations.With this PR, anywhere parameters are allowed, one can use `%env(ENV_VAR)%` to inject a dynamic env var. Additionally, if one sets a value to such parameters in e.g. the `parameter.yml` file (`env(ENV_VAR): foo`), this value will be used as a default value when the env var is not defined. If no default value is specified, an `EnvVarNotFoundException` will be thrown at runtime.Unlike previous attempts that also used parameters (#16403), the implementation is compatible with DI extensions: before being dumped, env vars are resolved to uniquely identifiable string placeholders that can get through DI extensions manipulations. When dumped, these unique placeholders are replaced by dynamic calls to a getEnv method..ping@magnusnordlander@dzuelke@fabpotCommits-------bac2132 [DI] Allow injecting ENV parameters at runtime using %env(MY_ENV_VAR)% syntax
@weaverryanweaverryan changed the title[WCM][DependencyInjection] Document %env(...)% dynamic parameters[DependencyInjection] Document %env(...)% dynamic parametersSep 18, 2016
Copy link
Member

@weaverryanweaverryan left a comment

Choose a reason for hiding this comment

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

Status: Reviewed

Setting this as reviewed because all of my comments are very minor!


..code-block::yaml
parameters:
Copy link
Member

Choose a reason for hiding this comment

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

Add#app/config/parameters.yml above this - it'sprobably the file where they will define the default value

));
``env(...)`` parameters can have default values be set and used whenever their
corresponding environment variables are not found:
Copy link
Member

Choose a reason for hiding this comment

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

You can also give the ``env(...)`` parameters a default value: the default value will be used wheneverthe corresponding environment variable is *not* found:

..note::

All popular web servers support setting environment variables. Read their
documentation to know how.
Copy link
Member

Choose a reason for hiding this comment

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

... to find out how.

..note::

You can also define the default value of any existing parameters using
special environement variables named after their corresponding parameter
Copy link
Member

Choose a reason for hiding this comment

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

environment

@weaverryan
Copy link
Member

Status: Reviewed

Just needs a few minor changes.

You can also define the default value of any existing parameters using
special environement variables named after their corresponding parameter
prefixed with ``SYMFONY__`` after replacing dots by double underscores
(e.g. ``SYMFONY__FOO__BAR`` to set the default value of the ``foo.bar``
Copy link
Member

Choose a reason for hiding this comment

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

let's keep using a real example here:(e.g.SYMFONY__DATABASE__USERto set the default value of thedatabase.user` parameter).

@nicolas-grekas
Copy link
MemberAuthor

Comments addressed, thanks for the review.

@wouterj
Copy link
Member

👍

#app/config/parameters.yml
parameters:
env(DATABASE_HOST):localhost
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this functionality part of thesymfony/symfony#19681 PR? I've tried something similar with:

database_driver: 'env(DATABASE_DRIVER): pdo_mysql'

but it doesn't use the default and just complains that:

"The given 'driver' env(DATABASE_DRIVER): pdo_mysql is unknown"

Copy link
Member

Choose a reason for hiding this comment

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

@mickadoo your code isnot what is documented here

Copy link
Contributor

Choose a reason for hiding this comment

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

@stof I just thought I'd try it out, didn't work though

Copy link
Member

Choose a reason for hiding this comment

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

What's documented here is:

parameters:database_driver:'%env(DATABASE_DRIVER)%'env(DATABASE_DRIVER):pdo_mysql

Which, as you can see, is quite different from the format you tested. If there is something we can do to improve the description of the feature, please tell us!

Copy link
Contributor

@mickadoomickadooOct 13, 2016
edited
Loading

Choose a reason for hiding this comment

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

@wouterj Ah, I get it now. Sorry about that!

Copy link
Member

Choose a reason for hiding this comment

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

No problem@mickadoo thanks for test-casing this documentation proposal.

I think we should include thedatabase_driver: '%env(DATABASE_DRIVER)%' line in this example to avoid confusing for other readers.


You can now reference these parameters wherever you need them.
For example, if you want to use the value of the ``DATABASE_HOST`` environment
variable into you service container configuration, you can reference it using
Copy link
Member

Choose a reason for hiding this comment

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

[...] variable in your service container configuration [...]


..code-block::yaml
#app/config/parameters.yml
Copy link
Member

Choose a reason for hiding this comment

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

missing space between comment and "app"

..code-block::yaml
#app/config/parameters.yml
Copy link
Member

Choose a reason for hiding this comment

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

blank line should be removed

..code-block::xml
<?xml version="1.0" encoding="UTF-8" ?>
Copy link
Member

Choose a reason for hiding this comment

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

missing filename comment

Copy link
Member

Choose a reason for hiding this comment

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

same for the PHP config example

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Do you have an example of such filenames for xml & php?

Copy link
Member

Choose a reason for hiding this comment

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

We usually simply replace the file extension. So here we would haveapp/config/parameters.yml,app/config/parameters.xml, andapp/config/parameters.php. By the way, can you also add similar comments in the example above to, but usingconfig.yml,config.xml, andconfig.php there?

Copy link
Member

Choose a reason for hiding this comment

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

Ah well, the previous example is not new. We should add the comments there in older branches too and can probably better do that in a separate PR.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

got it, fixed

$container->setParameter('env(DATABASE_HOST)', 'localhost');
If you're using Apache, environment variables can be set e.g. using the following
Copy link
Member

Choose a reason for hiding this comment

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

Everywhere else we give examples for Nginx too IIRC. I think we should do the same here.

<Directory "/path/to/symfony_2_app/web">
AllowOverride All
Allow from All
</Directory>
Copy link
Member

Choose a reason for hiding this comment

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

We should also add a placeholder comment to indicate that this config is not a complete working examples, but only shows how to configure environment variables for a virtual host.

@wouterj
Copy link
Member

status: needs work

ping@nicolas-grekas

@nicolas-grekas
Copy link
MemberAuthor

comments addressed
Status: needs review

..code-block::terminal
You can reference environment variables by using special parameters named after
the variables you want to use enclosed between ``env()``. Their actual values
will be resolved at runtime, so that dumped containers can be reconfigured

Choose a reason for hiding this comment

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

A quick question about this:

Their actual values will be resolved at runtime [...]

Are they resolved at runtimeevery time they are used ... or are they resolvedjust the first time they are used and then Symfony reuses the cached value? I say this because ofthe code of the getEnv() method.

Copy link
Member

Choose a reason for hiding this comment

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

Per request they are resolved once. But if you change the value, during the next request you will see the new value (again resolved only once during this request). Should we make that more clear somehow?

javiereguiluz reacted with thumbs up emoji

Choose a reason for hiding this comment

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

Thanks@xabbuh. I wouldn't add any notice about this because that behavior is exactly what we should expect.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I added(once per request), good enough?


..configuration-block::

..code-block::apache
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

looking at the tests,apache here makes sphinx fail, any clue why?

Copy link
Member

Choose a reason for hiding this comment

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

Apache has no label configured. Please edit the_build/conf.py file and add:'apache': 'Apache' (same for the other formats in this block). (and also ping javier that the symfony.com config has to be updated)

Choose a reason for hiding this comment

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

@wouterj thanks for the heads up. It will be merged in symfony.com soon:

apache-sphinx

Copy link
Member

Choose a reason for hiding this comment

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

@javiereguiluz please note that you also have to add'nginx': 'NGINX'

Choose a reason for hiding this comment

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

@wouterj thanks! It's fixed now. I opted forNginx as the human-readable name instead ofNGINX. The official website mixesnginx,Nginx andNGINX ... but the Wikipedia always usesNginx.

@wouterjwouterj added this to the3.2 milestoneNov 9, 2016
@wouterj
Copy link
Member

👍
status: reviewed

Note to merger: Please fix theconf.py configuration to suppor the new configuration block formats.

@wouterj
Copy link
Member

ping@javiereguiluz@weaverryan@xabbuh please review & vote

)
));
You can also give the ``env()`` parameters a default value: the default value

Choose a reason for hiding this comment

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

... a default value: the default value will be used whenever ...

-->

... a default value used whenever ...

Copy link
Member

@javiereguiluzjaviereguiluz left a comment

Choose a reason for hiding this comment

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

👍

@xabbuhxabbuh changed the base branch frommaster to3.2December 8, 2016 20:26
@xabbuh
Copy link
Member

👍

@xabbuh
Copy link
Member

Thank you Nicolas.

@xabbuhxabbuh merged commit083da46 intosymfony:3.2Dec 14, 2016
xabbuh added a commit that referenced this pull requestDec 14, 2016
…eters (nicolas-grekas)This PR was merged into the 3.2 branch.Discussion----------[DependencyInjection] Document %env(...)% dynamic parametersRef.symfony/symfony#19681Commits-------083da46 [DI] Document %env()% dynamic parameters
@nicolas-grekasnicolas-grekas deleted the env-params branchJuly 1, 2018 20:44
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@wouterjwouterjwouterj approved these changes

@xabbuhxabbuhxabbuh left review comments

@weaverryanweaverryanweaverryan requested changes

@javiereguiluzjaviereguiluzjaviereguiluz approved these changes

+2 more reviewers

@stofstofstof left review comments

@mickadoomickadoomickadoo left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.2

Development

Successfully merging this pull request may close these issues.

10 participants

@nicolas-grekas@wouterj@weaverryan@xabbuh@javiereguiluz@lyrixx@stof@tgalopin@mickadoo@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp