-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Config] Transform a value into an array #21817
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
Comments
See also #20223 Some generic if/then's for casting purposes would be really nice. |
@ro0NL I partially agree with you. It's OK to add more if/then helpers ... but only if they are used enough. In the case of the string/number -> array conversion, it's a very common need (even in the Symfony code itself). |
I'd vote for a generic solution, covering all types;
Something like that. |
I don't like the generic solution you suggest @ro0NL as it has many drawbacks. The main one being discoverability and autocompletion (think IDEs). As @javiereguiluz suggested, we only need some of them, the most used ones. Let's do that. |
Agree. My proposed syntax may not be suitable; i actually meant #20223 (comment) and indeed for common |
Rethinking the numeric to int conversion from #20223, it looks convenient but im not sure it's good practice. Ie. TTL values and such are probably best defined as an integer node anyway (being strict).. @chalasr wdyt? Not saying a generic conversion api doesnt workout, but it's most likely overkill. What about tackling both usecases pointed out by @javiereguiluz with a nice one-liner.. ->beforeNormalization()
->castToArray()
->ifTrue($something)
->then($profit)
->end()
Any thoughts? |
This PR was squashed before being merged into the 3.3-dev branch (closes #21893). Discussion ---------- Added a castToArray() config helper | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21817 | License | MIT | Doc PR | - Commits ------- 3a589df Added a castToArray() config helper
In config trees is common to see code like the following to turn a value into an array:
You can see it tens of times in Symfony, popular bundles and elsewhere. Could we add a helper method to remove this boilerplate code? Thanks!
The text was updated successfully, but these errors were encountered: