Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[FrameworkBundle] Allow using kernel parameters in routes #4745

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
Jul 4, 2012

Conversation

vicb
Copy link
Contributor

@vicb vicb commented Jul 4, 2012

Kernel parameters can now be used at any position in patterns, defaults and requirements.

Relates to: #3316, #3276

Differences from 3316:

  • The substitution is now done in the Router,
  • 3316 uses $container->getParameterBag() which is not part of the ContainerInterface. The way it been solved in this PR is that some code have been duplicated inside the Router, see resolveString().

BC break:

Before this PR, nonexistent parameters would have be silently ignored (ie %idontexist% would not have been replaced). After this PR, they will throw an exception. However you can escape the value (ie %%idontexist%% will be accepted and replaced by %idontexist%).

This behavior is not mandatory and can be reverted if needed. However this keeps the router more consistent with the DI.

Any feedback ? @helmer @Koc

*
* @param $collection
* @param RouteCollection|Route $collection
Copy link
Member

Choose a reason for hiding this comment

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

this is wrong as the RouteCollection is typehinted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, thanks.

@Seldaek
Copy link
Member

Seldaek commented Jul 4, 2012

👍 for consistency.

Kernel parameters can now be used at any position in patterns, defaults and requirements.
@helmer
Copy link
Contributor

helmer commented Jul 4, 2012

+1 a much better solution to the problem than mine, closing #3316

@Tobion
Copy link
Contributor

Tobion commented Jul 4, 2012

How about escaping kernel params with \%idontexist% as I suggested it for route params in 4563?

@stof
Copy link
Member

stof commented Jul 4, 2012

@Tobion this would not be consistent with the way DI parameters are escaped elsewhere

@Koc
Copy link
Contributor

Koc commented Jul 4, 2012

Looks good for me, thanx.

fabpot added a commit that referenced this pull request Jul 4, 2012
Commits
-------

0555913 [FrameworkBundle] Allow using kernel parameters in routes

Discussion
----------

[FrameworkBundle] Allow using kernel parameters in routes

Kernel parameters can now be used at any position in patterns, defaults and requirements.

Relates to: #3316, #3276

**Differences from 3316:**

- The substitution is now done in the `Router`,
- 3316 uses `$container->getParameterBag()` which is not part of the `ContainerInterface`. The way it been solved in this PR is that some code have been duplicated inside the `Router`, see `resolveString()`.

**BC break:**

Before this PR, nonexistent parameters would have be silently ignored (ie `%idontexist%` would not have been replaced). After this PR, they will throw an exception. However you can escape the value (ie `%%idontexist%%` will be accepted and replaced by `%idontexist%`).

_This behavior is not mandatory and can be reverted if needed. However this keeps the router more consistent with the DI_.

Any feedback ? @helmer @Koc

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

by Seldaek at 2012-07-04T12:40:08Z

:+1: for consistency.

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

by helmer at 2012-07-04T13:07:11Z

+1 a much better solution to the problem than mine, closing #3316

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

by Tobion at 2012-07-04T13:21:59Z

How about escaping kernel params with `\%idontexist%` as I suggested it for route params in 4563?

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

by stof at 2012-07-04T13:28:55Z

@Tobion this would not be consistent with the way DI parameters are escaped elsewhere

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

by Koc at 2012-07-04T14:24:25Z

Looks good for me, thanx.
@fabpot fabpot merged commit 0555913 into symfony:master Jul 4, 2012
@isometriks
Copy link

This still does not work with prefixes, it ends up writing the parameter to the UrlMatcher dump.

The routes end up working fine because the prefix is simply added to the pattern. However, in the PhpMatcherDumper, the prefix is obtained by using getPrefix() from the RouteCollection which has not been resolved, so any time there is more than one route you end up getting something like

if( 0 === strpos($pathinfo, '/%parameter_here%'){

The only thing I can see right now is added a setPrefix to RouteCollection, but that is very misleading because you can't exactly undo the route prefixes as it updates the patterns directly..

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.

8 participants