Skip to content

[Routing] RequestMatcherInterface doesn't need context #4582

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

Conversation

Tobion
Copy link
Contributor

@Tobion Tobion commented Jun 14, 2012

Matchers that implement RequestMatcherInterface should match a Request, thus they don't need the request context.

@travisbot
Copy link

This pull request fails (merged f5ff1fe0 into 7c91ee5).

if ($this->matcher instanceof RequestMatcherInterface) {
$parameters = $this->matcher->matchRequest($request);
} else {
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
$this->matcher->getContext()->fromRequest($request);
Copy link
Member

Choose a reason for hiding this comment

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

this means that the RequestContext is not initialized anymore whereas the generator uses it too, thus breaking things.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but it's the context of the matcher. if the generator needs an updated context it should be updated on the generator.
otherwise this listener simply assumes that the generator and matcher use the same context instance which is flawed imo.

Copy link
Member

Choose a reason for hiding this comment

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

@Tobion the matcher and the generator are meant to share the same context, otherwise it becomes a pain to support parameters in the context (for instance when implementing host-based routing, where different contexts would be a mess as soon as they become out of sync)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see no other solution than injecting the generator too in the RouterListener. As this PR removes the RequestContextAwareInterface from the RequestMatcher (which makes total sense, don't you think?), it means when using a RequestMatcher it cannot initialize the context for the generator.
So we need to inject the generator, which would also remove the confusing and interdependent implementation.

Copy link
Member

Choose a reason for hiding this comment

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

@Tobion but in the context of the full-stack framework, what is injected is the router (which implements both the MatcherInterface and the GeneratorInterface and lazy-loads the actual matcher and generators from the cache). Injecting the same object twice seems really weird

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the default instantiation didn't make much sense anyway because the default values (like localhost) will not be useful in 99% of the cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So where should I inject the context and where retrieve it from DIC? I'm not sure about the implementation suggested by you guys.

Copy link
Member

Choose a reason for hiding this comment

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

@Tobion instead of injecting the UrlGenerator (as suggested previously) to get the RequestContext from it, simply inject the RequestContext itself (in the constructor like other deps)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah ok, thought there was more to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, ready for review.

@schmittjoh
Copy link
Contributor

I think it makes sense to remove the RequestContext from the RequestMatcher.

try {
// matching requests is more powerful than matching URLs only, so try that first
// matching a request is more straightforward than matching a URL path + context, so try that first
Copy link
Contributor

Choose a reason for hiding this comment

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

Why changing this comment? I think the previous one was better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the comment was wrong. It matches path + context and not "only URLs", which is almost identical to the request.

Copy link
Member

Choose a reason for hiding this comment

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

almost identical ? Look at what is available in the Request. There is far more stuff in it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, but what I don't like is the word "straightforward" here, I think "powerful" is way better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok i can revert the term

@travisbot
Copy link

This pull request passes (merged 7464dcd into f881d28).

@Tobion
Copy link
Contributor Author

Tobion commented Jun 26, 2012

Anything missing?

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

7464dcd added phpdoc
c413e7b [Routing] remove RequestContextAwareInterface from RequestMatcherInterface
921be34 [Routing] fix phpdoc

Discussion
----------

[Routing] RequestMatcherInterface doesn't need context

Matchers that implement RequestMatcherInterface should match a Request, thus they don't need the request context.

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

by travisbot at 2012-06-14T21:39:48Z

This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1624496) (merged f5ff1fe0 into 7c91ee5).

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

by schmittjoh at 2012-06-15T13:32:59Z

I think it makes sense to remove the RequestContext from the RequestMatcher.

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

by travisbot at 2012-06-15T15:54:28Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1628931) (merged 7464dcd into f881d28).

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

by Tobion at 2012-06-26T12:32:06Z

Anything missing?
@fabpot fabpot merged commit 7464dcd into symfony:master Jul 1, 2012
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.

5 participants