8000 [Routing] Allow using kernel parameters in routes by helmer · Pull Request #3316 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Routing] Allow using kernel parameters in routes #3316

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

Closed
wants to merge 1 commit into from

Conversation

helmer
Copy link
Contributor
@helmer helmer commented Feb 9, 2012

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Tests pass: Tests

I've had this snippet in my DelegatingLoader override for a while now, but as I saw others are also interested (#3276), I thought I'd share.

@helmer
Copy link
Contributor Author
helmer commented Feb 10, 2012

While trying to write tests for this, I've realised parameter replacement is already done, inside Router, which actually makes alot more sense. The thing is, parameters cannot be used directly inside routes (although one can set a variable placeholder and define it through defaults/requirements. Question being, should we allow direct replacement of route placeholders, @fabpot?

As a side note, is there a reason, why it is narrowed to ^%.*%$? Perhaps (no clear real-world scenario, but still) I'd want to define something like defaults: { blah: lang_%session.locale% } ..

@helmer
Copy link
Contributor Author
helmer commented Feb 10, 2012

Some more elaborations, as to why I want pattern replacements. I have defined a custom parameter named public_path, which I want to include in routes for which security firewall is disabled. Using pattern replacement, this is easy:
pattern: /%public_path%/some-route
as opposed to

pattern: /{_public}/some-route
requirements: { _public: %public_path% }

which of course does the trick but involves an extra line and is heavier on matcher, thoughts?

@Koc
Copy link
Contributor
Koc commented Feb 16, 2012

@Koc
Copy link
Contributor
Koc commented Feb 16, 2012

oh, no, you have better sollution that supports concatenation, sorry.

@stof
Copy link
Member
stof commented Apr 4, 2012

@fabpot ping

@helmer
Copy link
Contributor Author
helmer commented Jul 4, 2012

#4745 solves this issue more cleanly, closing this one.

@helmer helmer closed this Jul 4, 2012
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.
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.

3 participants
0