8000 [Routing] allow disabling the requirements check on URL generation by Tobion · Pull Request #5187 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Routing] allow disabling the requirements check on URL generation #5187

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 3 commits into from
Aug 30, 2012

Conversation

Tobion
Copy link
Contributor
@Tobion Tobion commented Aug 6, 2012

This adds the possibility to disable the requirements check (strict_requirements = null) on URL generation.

To sum up, here the possibilities:

  • strict_requirements = true: throw exception for mismatching requirements (most useful in development environment).
  • strict_requirements = false: don't throw exception but return null as URL for mismatching requirements and log it (useful when you cannot control all params because they come from third party libs or something but don't want to have a 404 in production environment. it logs the mismatch so you can review it).
  • strict_requirements = null: Return the URL with the given parameters without checking the requirements at all. When generating an URL you should either trust your params or you validated them beforehand because otherwise it would break your link anyway (just as with strict_requirements=false). So in production environment you should know that params allways pass the requirements. Thus you could disable the check on each URL generation for performance reasons. If you have 300 links on a page and each URL at least one param you safe 300 unneeded preg_match calls. I tested the performance in one of my projects. The rendering time of a single template that contains ~300 links with several params was reduced from avg. 46ms to avg. 42ms. That are 8.7% reduction in the twig layer where the links are created on each request. So this option combines the improved usability of strict_requirements=false with an additional increased performance.

@travisbot
Copy link

This pull request fails (merged 8388cb6b into 20d2e5a).

@travisbot
Copy link

This pull request fails (merged c119d6e3 into 20d2e5a).

@fabpot
Copy link
Member
fabpot commented Aug 30, 2012

Can you put the comment about all the possibilities you have mentioned here in the phpdoc for future reference? Thanks.

@Tobion
Copy link
Contributor Author
Tobion commented Aug 30, 2012

In ConfigurableRequirementsInterface or which phpdoc would you like to have it? Because ConfigurableRequirementsInterface already has it explained. But I can extend its description if thats what you mean.

@fabpot
Copy link
Member
fabpot commented Aug 30, 2012

The comment in the PR is more explicit and more detailed than the one in the interface. So, yes, basically, it would be great if you can move all the information in the interface phpdoc.

@Tobion
Copy link
Contributor Author
Tobion commented Aug 30, 2012

Done.

@fabpot
Copy link
Member
fabpot commented Aug 30, 2012

merged, thanks

fabpot added a commit that referenced this pull request Aug 30, 2012
Commits
-------

3363832 extended phpdoc of ConfigurableRequirementsInterface
5f64503 [Routing] added test for disabled requirements check
4225869 [Routing] allow disabling the requirements check on URL generation

Discussion
----------

[Routing] allow disabling the requirements check on URL generation

This adds the possibility to disable the requirements check (`strict_requirements = null`) on URL generation.

To sum up, here the possibilities:
- `strict_requirements = true`: throw exception for mismatching requirements (most useful in development environment).
- `strict_requirements = false`: don't throw exception but return null as URL for mismatching requirements and log it (useful when you cannot control all params because they come from third party libs or something but don't want to have a 404 in production environment. it logs the mismatch so you can review it).
- `strict_requirements = null`: Return the URL with the given parameters without checking the requirements at all. When generating an URL you should either trust your params or you validated them beforehand because otherwise it would break your link anyway (just as with strict_requirements=false). So in production environment you should know that params allways pass the requirements. Thus you could disable the check on each URL generation for performance reasons. If you have 300 links on a page and each URL at least one param you safe 300 unneeded `preg_match` calls. I tested the performance in one of my projects. The rendering time of a single template that contains ~300 links with several params was reduced from avg. 46ms to avg. 42ms. That are 8.7% reduction in the twig layer where the links are created on each request. So this option combines the improved usability of strict_requirements=false with an additional increased performance.

---------------------------------------------------------------------------

by fabpot at 2012-08-30T13:40:38Z

Can you put the comment about all the possibilities you have mentioned here in the phpdoc for future reference? Thanks.

---------------------------------------------------------------------------

by Tobion at 2012-08-30T13:49:25Z

In `ConfigurableRequirementsInterface` or which phpdoc would you like to have it? Because `ConfigurableRequirementsInterface` already has it explained. But I can extend its description if thats what you mean.

---------------------------------------------------------------------------

by fabpot at 2012-08-30T13:50:40Z

The comment in the PR is more explicit and more detailed than the one in the interface. So, yes, basically, it would be great if you can move all the information in the interface phpdoc.

---------------------------------------------------------------------------

by Tobion at 2012-08-30T14:35:59Z

Done.
@fabpot fabpot merged commit 3363832 into symfony:master Aug 30, 2012
@travisbot
Copy link

This pull request fails (merged 3363832 into 569e29d).

@travisbot
Copy link

This pull request passes (merged 5f64503 into 569e29d).

8000

fabpot added a commit that referenced this pull request Sep 5, 2012
This reverts commit 2cf50b7, reversing
changes made to 569e29d.
@fabpot
Copy link
Member
fabpot commented Sep 5, 2012

I've just reverted this pull request as it introduces some regressions? It was a very bad idea to merge this so close to the release of 2.1 and I'm the one to blame. Sorry about that.

@Tobion As apparently it is not possible to reopen a pull request, can you re-submit it again, so that it is not lost? Thanks and sorry again for the trouble.

@Tobion
Copy link
Contributor Author
Tobion commented Sep 5, 2012

What regressions does it introduce? I cannot reopen as i already deleted the branch locally and remote.

@stof
Copy link
Member
stof commented Sep 5, 2012

@Tobion as the commits are still in the symfony history, you can recreate the branches (note that you need to cherry-pick the commits anyway as the existing commits are already merged)

fabpot added a commit that referenced this pull request Oct 3, 2012
This PR was merged into the master branch.

Commits
-------

faee47c added note in changelog about disabling requirements check
5fbed36 extended phpdoc of ConfigurableRequirementsInterface
1964d43 [Routing] added test for disabled requirements check
98fb915 [Routing] allow disabling the requirements check on URL generation

Discussion
----------

[Routing] allow disabling the requirements check on URL generation

Reopened version of #5187
Requires #5445 first

---------------------------------------------------------------------------

by fabpot at 2012-10-03T19:03:25Z

Can you rebase on master and add a note in the CHANGELOG? Also, I think the doc should be updated accordingly. Thanks.

---------------------------------------------------------------------------

by Tobion at 2012-10-03T19:04:07Z

@fabpot ping. The config for this feature is already present in master in symfony-standard. See [config_prod.yml](https://github.com/symfony/symfony-standard/blob/master/app/config/config_prod.yml)

---------------------------------------------------------------------------

by Tobion at 2012-10-03T19:06:53Z

Hehe, I already rebased while you wrote that. You mean I should add a tip to the routing component documentation?
Sure, I have alread planned to adjust the symfony doc for the recent routing PRs.

---------------------------------------------------------------------------

by fabpot at 2012-10-03T19:12:36Z

Just adding a note about the new possibility in the CHANGELOG.

---------------------------------------------------------------------------

by Tobion at 2012-10-03T19:53:19Z

@fabpot done
sarramegnag pushed a commit to sarramegnag/symfony-vue that referenced this pull request Sep 16, 2018
sarramegnag pushed a commit to sarramegnag/symfony-vue that referenced this pull request Sep 16, 2018
Commits
-------

ef43472 added upgrade note for strict_requirements = null
33eaa39 configure strict_requirements: null in production

Discussion
----------

configure strict_requirements: null in production

possible since symfony/symfony#5187
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0