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

Allow "json:" env var processor to accept null value#26498

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
fabpot merged 1 commit intosymfony:masterfrommcfedr:json_env_any
Mar 27, 2018

Conversation

@mcfedr
Copy link
Contributor

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets
LicenseMIT
Doc PRCurrently no docs for this feature

Edits the EnvVarProcessor so that it allows any type of variable in JSON encoded vars.

Previously it was only possible to use%env(json:ENV)% for array types, but this seems to be an arbitrary restriction, when I could have any other data type in that JSON.

Valid JSON that was previously rejected:

  • 1
  • null
  • "string"

@nicolas-grekas
Copy link
Member

There are reasons for the current restriction:

  • having a single type (array) makes it easier to validate types, eg for chained processors or config validation
  • the other JSON types can easily be achieved using other processors (ie int, bool, string, null)

@nicolas-grekasnicolas-grekas added this to the4.1 milestoneMar 12, 2018
@mcfedr
Copy link
ContributorAuthor

I wondered if this might be what's happening. I have a case where in passing either an array or null.
What if I changed this to allownull? I feel like this might be a useful case.

@nicolas-grekas
Copy link
Member

if you want to setnull, I think you can already achieve it with the const processor:const:null

@javiereguiluz
Copy link
Member

@nicolas-grekas but I think he's saying that an external piece of software generates this config that usually is a JSON-encoded array but it can benull when the config is empty (Symfony does the same and we usearray|null everywhere instead ofarray|empty array). But I guess you'll need to change that external software to encode an empty JSON array when the config is empty.

@mcfedr
Copy link
ContributorAuthor

Exactly, I need to accept either array or null.

@mcfedrmcfedr changed the titleAllow "json:" env var processor to parse any json valueAllow "json:" env var processor to accept null valueMar 12, 2018
@nicolas-grekas
Copy link
Member

would you mind adding a test case please?

@mcfedrmcfedrforce-pushed thejson_env_any branch 2 times, most recently from05ec676 tofdee150CompareMarch 15, 2018 11:29
@mcfedr
Copy link
ContributorAuthor

Sure, also added some more general testing around EnvVarProcessor as there don't seem to exist any at the moment.

useSymfony\Component\DependencyInjection\EnvVarProcessor;
useSymfony\Component\DependencyInjection\Exception\LogicException;

class EnvVarProcessorTestextends TestCase

Choose a reason for hiding this comment

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

would you mind opening a separate PR against branch 3.4 for this test class?

Copy link
ContributorAuthor

@mcfedrmcfedrMar 15, 2018
edited
Loading

Choose a reason for hiding this comment

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

Ok, I moved to#26542, but had to remove the case forjson:null because it will fail in 3.4, and i cannot add it here until that PR lands in master. I can probably make another PR later with more cases.


if (!is_array($env)) {
if (null !==$env &&!is_array($env)) {
thrownewRuntimeException(sprintf('Invalid JSON env var "%s": array expected, %s given.',$name,gettype($env)));

Choose a reason for hiding this comment

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

The error message should be updated:array expected ... ->array or null expected ...

@mcfedrmcfedrforce-pushed thejson_env_any branch 2 times, most recently fromd523a2c to98b1ae5CompareMarch 19, 2018 10:31
@mcfedr
Copy link
ContributorAuthor

Rebased on master to see if it would fix the tests, but now seems to fail on some other doctrine tests

nicolas-grekas added a commit that referenced this pull requestMar 19, 2018
This PR was squashed before being merged into the 3.4 branch (closes#26542).Discussion----------[DI] Add tests for EnvVarProcessor| Q             | A| ------------- | ---| Branch?       | 3.4| Bug fix?      | no| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets || License       | MIT| Doc PR        | n/aAdd tests for the `EnvVarProcessor` as it doesn't have any at the moment.Originally from this PR against master,#26498Commits-------2992bb3 [DI] Add tests for EnvVarProcessor
@nicolas-grekas
Copy link
Member

@mcfedr you said had more tests in26542 before moving it to 3.4. Did you add them back here after the rebase?

@mcfedr
Copy link
ContributorAuthor

I was thinking it would make sense for the tests in#26542 in to be expanded to include this specific case of paring"null" as valid json, as this commit is based on master I cannot add that here until that commitd818636 is merged into master.

@nicolas-grekas
Copy link
Member

Indeed. Merge done, rebase unlocked on your side.

@mcfedr
Copy link
ContributorAuthor

Ok, rebased with extra test cases

Amend EnvVarProcessorTest to include all possible json values
@fabpot
Copy link
Member

Thank you@mcfedr.

@fabpotfabpot merged commitabc7480 intosymfony:masterMar 27, 2018
fabpot added a commit that referenced this pull requestMar 27, 2018
…mcfedr)This PR was merged into the 4.1-dev branch.Discussion----------Allow "json:" env var processor to accept null value| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets || License       | MIT| Doc PR        | Currently no docs for this featureEdits the EnvVarProcessor so that it allows any type of variable in JSON encoded vars.Previously it was only possible to use `%env(json:ENV)%` for array types, but this seems to be an arbitrary restriction, when I could have any other data type in that JSON.Valid JSON that was previously rejected:- `1`- `null`- `"string"`Commits-------abc7480 Allow "json:" env var processor to parse null values
@ro0NL
Copy link
Contributor

@mcfedr
Copy link
ContributorAuthor

@ro0NL I don't see anything specific to this change, this PR makes it possible for thejson: processor to return either an array ornull, so it can still never be anint.

@mcfedrmcfedr deleted the json_env_any branchMarch 27, 2018 14:02
@fabpotfabpot mentioned this pull requestMay 7, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@javiereguiluzjaviereguiluzjaviereguiluz left review comments

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

4.1

Development

Successfully merging this pull request may close these issues.

6 participants

@mcfedr@nicolas-grekas@javiereguiluz@fabpot@ro0NL@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp