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

Appearance settings

Improve the config validation in TwigBundle #14859

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
Jun 4, 2015

Conversation

stof
Copy link
Member

@stof stof commented Jun 4, 2015

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #14858
License MIT
Doc PR n/a

This ensures we have better error messages in case of misconfiguration instead of having crappy errors from Twig (which does not validates its options fully either, missing these things)

@jakzal
Copy link
Contributor

jakzal commented Jun 4, 2015

👍

->scalarNode('auto_reload')->end()
->scalarNode('optimizations')->end()
->integerNode('optimizations')->end()
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of adding a ifNotInArray() validation with the four possible values (-1, 0, 2, 4, 8) for this option? Or even create an enum() node instead of an integer one?

Copy link
Member Author

Choose a reason for hiding this comment

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

optimizations are a binary flag. So it cannot be an enum node, unless we have all combinations of the binary flag (and we would have to update it each time Twig adds a new optimization)

Copy link
Member Author

Choose a reason for hiding this comment

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

I could add a ->min(-1) though

Copy link
Member

Choose a reason for hiding this comment

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

OK then, there is nothing else to do. Thanks for the explanation!

@stof stof force-pushed the better_twig_config branch from 0348c0d to f4dfee3 Compare June 4, 2015 10:53
@aitboudad
Copy link
Contributor

👍

->scalarNode('cache')->defaultValue('%kernel.cache_dir%/twig')->end()
->scalarNode('charset')->defaultValue('%kernel.charset%')->end()
->scalarNode('debug')->defaultValue('%kernel.debug%')->end()
->scalarNode('strict_variables')->end()
->booleanNode('debug')->defaultValue('%kernel.debug%')->end()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think defaultValue('%kernel.debug%') will be treated as a simple string.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes? It's resolved later. What is your objection?

Copy link
Member Author

Choose a reason for hiding this comment

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

Using such string resolved later works because the default value is applied after the validation. FrameworkBundle already does it.

It is true however that the DI extension will still receive the string here, not the resolved value. But we don't care because the DI extension does not care about the value itself. It just sets it in the container (where it will be resolved).
For cases where the value influences the DI extension logic, it is indeed necessary to resolve the value, which can either be done explicitly in the DI extension or by passing the debug flag to the Configuration class (which is what DoctrineBundle does for instance)

@Tobion
Copy link
Contributor

Tobion commented Jun 4, 2015

👍

@stof
Copy link
Member Author

stof commented Jun 4, 2015

@fabpot please fix fabbot.io so that statuses are not reported as errored on Github. Having PRs marked as red because of a fabbot.io 404 is not great.

@fabpot
Copy link
Member

fabpot commented Jun 4, 2015

Thank you @stof.

@fabpot fabpot merged commit f4dfee3 into symfony:2.3 Jun 4, 2015
fabpot added a commit that referenced this pull request Jun 4, 2015
This PR was merged into the 2.3 branch.

Discussion
----------

Improve the config validation in TwigBundle

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #14858
| License       | MIT
| Doc PR        | n/a

This ensures we have better error messages in case of misconfiguration instead of having crappy errors from Twig (which does not validates its options fully either, missing these things)

Commits
-------

f4dfee3 Improve the config validation in TwigBundle
@stof stof deleted the better_twig_config branch July 2, 2015 21:39
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.

6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.