-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Allow Twig callable arguments to use camel or snake names #4318
Conversation
I love how this implementation dances around most of the differences between the previous I encountered many problems when the Note i only looked at the code of the changed class, i am not 100% sure this concerns real use cases (especially after the recent naming convention updates) ResultsA ❌ in the
ReproducerI took the code from the current normalize method, the two new toSnake and toCamel from your changes and the snake and camel methods from Symfony You can find the small script i made to test on this gist. |
7ab7d46
to
1ef4e7b
Compare
Your comment @smnandre made me realize that there is nothing forcing people to use proper snake or camel cases. There are of course some edge cases where several parameters might resolve to the same name, but having such similar names in a signature would not be very smart :) |
1ef4e7b
to
67dc1b2
Compare
I feared I was gonna make you lose time here .. so i'm really glad if in the end the implementation is more robust and more "tolerant" at the same time. 🎩 |
what happens for named arguments passed to variadic functions ? AFAIU, the issue you referenced was about that case, not about the case where Twig is resolving named arguments for its callables. |
Variadic is just one problem, which I "fixed" in the last commit. For variadics, I keep the attribute name as is. |
Not normalizing variadic arguments to snake case anymore will fix #3475 but would be a BC break for functions/templates that currently rely on this behavior (because the function implementation expects snake case but the template does not provide it). |
I know :) |
I should elaborate a bit more here. Even if it is a BC break, is it a problem in practice? The current behavior is to always convert to snake_case. So, for any app that runs today, developers must have used snake case names as well for their variadic names. And I bet developers also changed their templates to use snake_case as well to be consistent. Is it a fair assumption? |
Now, we trigger a deprecation when a name for a variadic arg is not snake-cased. That way, we're sure that the upgrade is smooth. |
d5f4277
to
1a4c5ee
Compare
1a4c5ee
to
52ded20
Compare
Closes #3475
Twig callables (functions/filters/tests) now accept snake and camel argument names independently of the name of the underlying PHP callable parameter names.