Skip to content

[Routing][HttpKernel] Add RequestMatcherInterface. #4363

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 9, 2012

Conversation

niklasf
Copy link
Contributor

@niklasf niklasf commented May 21, 2012

First try at implementing #4351.

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Fixes the following tickets: -
Todo: -
License of the code: MIT

@travisbot
Copy link

This pull request fails (merged 457496db into ea33d4d).

if ($this->urlMatcher instanceof RequestMatcherInterface) {
$parameters = $this->urlMatcher->matchRequest($request);
}
else {
Copy link
Contributor

Choose a reason for hiding this comment

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

should be on previous line, right after }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Heh, Symfony coding standards. Thanks for reviewing. Should I amend my previous commit or push the fix in a seperate one?

Copy link
Member

Choose a reason for hiding this comment

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

amend please

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 and pushed.

@travisbot
Copy link

This pull request passes (merged 78effa98 into ea33d4d).

@everzet
Copy link
Contributor

everzet commented May 21, 2012

No tests?

@travisbot
Copy link

This pull request passes (merged 6564fb6a into ea33d4d).

@schmittjoh
Copy link
Contributor

You need to remove the type-hint from the constructor, and probably add an exception instead where the matching methods are called to ensure that either UrlMatcherInterface, or RequestMatcherInterface were passed. Alternatively, you could also add such a check to the constructor.

@@ -16,6 +16,7 @@
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a benefit in changing this file? I think we could revert all of these changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not required at all and does nothing new. That would just give us a default implemenation. Implementations that override this could just as well implement RequestMatcherInterface themselves. Any other votes?

@fabpot
Copy link
Member

fabpot commented May 22, 2012

related to #4020

@niklasf
Copy link
Contributor Author

niklasf commented May 25, 2012

Reverted the changes to UrlMatcher.php.

@fabpot
Copy link
Member

fabpot commented May 25, 2012

@niklasf: it looks good now except for the listener constructor (see @schmittjoh suggestion above). Can you fix that and add some unit tests to ensure that everything works as expected? Thanks.

@stof
Copy link
Member

stof commented May 25, 2012

Another solution could be to make the RequestMatcherInterface extend the MatcherInterface to keep the typehint in the constructor

@fabpot
Copy link
Member

fabpot commented May 25, 2012

I thought about that as well, but that does not make sense.

@stof
Copy link
Member

stof commented May 25, 2012

Well, the RouterInterface extends UrlMatcherInterface anyway (and it should stay this way as it would be a huge BC break) so I guess most people will implement both interfaces when implementing the RquestMatcherInterface

@@ -32,8 +33,13 @@ class RouterListener implements EventSubscriberInterface
private $urlMatcher;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did that and added some basic tests. This one is private --- should this be renamed to matcher?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, renaming to matcher is a good idea.

@travisbot
Copy link

This pull request fails (merged 8f36204c into ff4d446).

@travisbot
Copy link

This pull request fails (merged 6d2f2cd9 into ff4d446).

@travisbot
Copy link

This pull request fails (merged 3c1d89e2 into ff4d446).

@@ -52,6 +52,19 @@ public function testPort($defaultHttpPort, $defaultHttpsPort, $uri, $expectedHtt
$this->assertEquals($expectedHttpPort, $context->getHttpPort());
$this->assertEquals($expectedHttpsPort, $context->getHttpsPort());
$this->assertEquals(0 === strpos($uri, 'https') ? 'https' : 'http', $context->getScheme());

$requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mhh ... probably picked the wrong test method - should add a new one. Not sure why the tests are failing ...

Copy link
Member

Choose a reason for hiding this comment

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

for an interface, you could use $this->getMock('...') directly. Disablign the original constructor is useless for interfaces as they don't have one

Copy link
Member

Choose a reason for hiding this comment

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

btw, you should probably create another test method for the case of the RequestMatcherInterface instead of putting all assertions in the same test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, stof. Pushed a fix.

@travisbot
Copy link

This pull request fails (merged 3ab997c1 into ff4d446).

@travisbot
Copy link

This pull request fails (merged d8c0e387 into ff4d446).

*
* @author Fabien Potencier <fabien@symfony.com>
*
* @api
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove the @api tag here and below. We will mark them later on. Thanks.

@fabpot
Copy link
Member

fabpot commented May 26, 2012

Can you add a note in the CHANGELOG of the component?

@travisbot
Copy link

This pull request fails (merged c7458733 into 9e95199).

@niklasf
Copy link
Contributor Author

niklasf commented May 26, 2012

@fabpot: Sorry, not sure how: Under 2.1.0 or in a new section? As the first or last entry of the list?

@stof
Copy link
Member

stof commented May 26, 2012

@niklasf the new interface should be mentioned in the changelog of the Routing component

@@ -4,6 +4,7 @@ CHANGELOG
2.1.0
-----

* added RequestMatcherInterface
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 guess I should just try it and you'll tell me where to move it, if it's wrong here.

@travisbot
Copy link

This pull request fails (merged 34ea86a9 into 9e95199).

@niklasf
Copy link
Contributor Author

niklasf commented Jun 2, 2012

Ah ... so there were two pitfalls:

  • PHPUnit clones the arguments of mocked functions. So they wouldn't equal.
  • createGetResponseEventForUri() disables routing on purpose. So not using that helper, now.

Tests should be passing.

@travisbot
Copy link

This pull request passes (merged 7fab0118 into 1541fe2).

While UrlMatcherInterface is only for matching URLs with routes, add
RequestMatcherInterface, that allows to match against whole requests.
fabpot added a commit that referenced this pull request Jun 9, 2012
Commits
-------

2277500 [Routing][HttpKernel] Add RequestMatcherInterface.

Discussion
----------

[Routing][HttpKernel] Add RequestMatcherInterface.

First try at implementing #4351.

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Fixes the following tickets: -
Todo: -
License of the code: MIT

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

by travisbot at 2012-05-21T19:37:07Z

This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1392716) (merged 457496db into ea33d4d).

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

by travisbot at 2012-05-21T19:47:51Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1392939) (merged 78effa98 into ea33d4d).

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

by everzet at 2012-05-21T20:17:03Z

No tests?

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

by travisbot at 2012-05-21T20:18:18Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1393392) (merged 6564fb6a into ea33d4d).

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

by schmittjoh at 2012-05-21T20:35:14Z

You need to remove the type-hint from the constructor, and probably add an exception instead where the matching methods are called to ensure that either ``UrlMatcherInterface``, or ``RequestMatcherInterface`` were passed. Alternatively, you could also add such a check to the constructor.

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

by fabpot at 2012-05-22T06:52:01Z

related to #4020

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

by niklasf at 2012-05-25T11:11:45Z

Reverted the changes to UrlMatcher.php.

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

by fabpot at 2012-05-25T12:46:06Z

@niklasf: it looks good now except for the listener constructor (see @schmittjoh suggestion above). Can you fix that and add some unit tests to ensure that everything works as expected? Thanks.

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

by stof at 2012-05-25T12:52:59Z

Another solution could be to make the ``RequestMatcherInterface`` extend the ``MatcherInterface`` to keep the typehint in the constructor

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

by fabpot at 2012-05-25T13:52:26Z

I thought about that as well, but that does not make sense.

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

by stof at 2012-05-25T14:12:19Z

Well, the RouterInterface extends UrlMatcherInterface anyway (and it should stay this way as it would be a huge BC break) so I guess most people will implement both interfaces when implementing the RquestMatcherInterface

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

by travisbot at 2012-05-25T15:26:22Z

This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1433963) (merged 8f36204c into ff4d446).

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

by travisbot at 2012-05-25T15:33:13Z

This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1433996) (merged 6d2f2cd9 into ff4d446).

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

by travisbot at 2012-05-25T15:39:01Z

This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1434060) (merged 3c1d89e2 into ff4d446).

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

by travisbot at 2012-05-25T22:06:34Z

This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1437398) (merged 3ab997c1 into ff4d446).

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

by travisbot at 2012-05-25T22:06:47Z

This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1437385) (merged d8c0e387 into ff4d446).

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

by fabpot at 2012-05-26T06:41:31Z

Can you add a note in the CHANGELOG of the component?

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

by travisbot at 2012-05-26T08:12:40Z

This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1440435) (merged c7458733 into 9e95199).

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

by niklasf at 2012-05-26T08:14:41Z

@fabpot: Sorry, not sure how: Under 2.1.0 or in a new section? As the first or last entry of the list?

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

by stof at 2012-05-26T10:20:23Z

@niklasf the new interface should be mentioned in the changelog of the Routing component

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

by travisbot at 2012-05-26T10:30:06Z

This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1440837) (merged 34ea86a9 into 9e95199).

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

by niklasf at 2012-06-02T15:27:01Z

Ah ... so there were two pitfalls:

- PHPUnit clones the arguments of mocked functions. So they wouldn't equal.
- createGetResponseEventForUri() disables routing on purpose. So not using that helper, now.

Tests should be passing.

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

by travisbot at 2012-06-02T15:30:28Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1509054) (merged 7fab0118 into 1541fe2).
@fabpot fabpot merged commit 2277500 into symfony:master Jun 9, 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.

7 participants