php-http / message

HTTP Message related tools
http://php-http.org
MIT License
1.3k stars 42 forks source link

Add request matcher #32

Closed joelwurtz closed 8 years ago

joelwurtz commented 8 years ago

See https://github.com/php-http/client-common/pull/13

sagikazarmark commented 8 years ago

Other possible matchers to add:

sagikazarmark commented 8 years ago

LGTM :+1:

joelwurtz commented 8 years ago

Other matchers for another PR when we need it :)

dbu commented 8 years ago

i like the symfony approach to this better, actually: https://github.com/symfony/symfony/blob/582f4753a343f230fbe18b4e9a0747d48351ddfb/src/Symfony/Component/HttpFoundation/RequestMatcher.php

if we have a separate matcher for each part of the request, we build huge object trees. i don't know if anybody ported the symfony request matcher to PSR-7 yet, if not this library could be a good place for it. though it might be worth to have it stand alone as it could be useful even when not using anything else from PHP-HTTP.

sagikazarmark commented 8 years ago

I don't see a reason why the regex one could not live together with the one you linked.

The message library is not dedicated to PHP-HTTP packages (but rather to PSR-7 as a utility package), so IMO we can have it in here. There aren't any heavy dependencies. (BTW: We should ask the FIG if they want a http-message-utils repo, similarly to cache-utils.)

But I am not against separating it to be standalone. (One reason against it: makes it harder to use it INSIDE message. For example I would use it the Matching authentication)

dbu commented 8 years ago

agreed, lets keep it inside message then. good idea to ask fig - if we contribute parts of this to their world we can then depend on those parts from message without worries and still rely on it.

my unhappiness with the RegexRequestMatcher is that it is only matching one thing, instead of ip, host, path, method and so on like the symfony one. if we add the full matcher, the regex matcher becomes redundant. the name is a bit unclear too, its a RegexUriRequestMatcher, not regex for host, path or method...

joelwurtz commented 8 years ago

my unhappiness with the RegexRequestMatcher is that it is only matching one thing

It's just a first implementation to have a simple example, as i'm only interested in the interface for the moment, will certainly write other implementations at a latter time :)

It can be renamed if you want, also didn't want a too long name, but yeah RegexUriRequestMatcher may be cleaner.