Skip to content

Commit ed6c69e

Browse files
[HttpFoundation] Mention HeaderRequestMatcher and
`QueryParameterRequestMatcher`
1 parent a5b0693 commit ed6c69e

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

components/http_foundation.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,56 @@ use the ``isPrivateIp()`` method from the
379379
$isPrivate = IpUtils::isPrivateIp($ipv6);
380380
// $isPrivate = false
381381

382+
Matching a Request Against a Set Rules
383+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
384+
385+
If you need to match a request against a set of rules, you can use
386+
request matchers. The HttpFoundation component provides many matchers
387+
to be used:
388+
389+
* :class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\AttributesRequestMatcher`
390+
* :class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\ExpressionRequestMatcher`
391+
* :class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\HeaderRequestMatcher`
392+
* :class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\HostRequestMatcher`
393+
* :class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\IpsRequestMatcher`
394+
* :class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\IsJsonMatcher`
395+
* :class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\MethodRequestMatcher`
396+
* :class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\PathRequestMatcher`
397+
* :class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\PortRequestMatcher`
398+
* :class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\QueryParameterRequestMatcher`
399+
* :class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\SchemeRequestMatcher`
400+
401+
You can either use them directly or combine them using the
402+
:class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\ChainRequestMatcher`
403+
class::
404+
405+
use Symfony\Component\HttpFoundation\RequestMatcher\ChainRequestMatcher;
406+
use Symfony\Component\HttpFoundation\RequestMatcher\HostRequestMatcher;
407+
use Symfony\Component\HttpFoundation\RequestMatcher\PathRequestMatcher;
408+
use Symfony\Component\HttpFoundation\RequestMatcher\SchemeRequestMatcher;
409+
410+
// use only one criteria to match the request
411+
$schemeMatcher = new SchemeRequestMatcher('https');
412+
if ($schemeMatcher->matches($request)) {
413+
// ...
414+
}
415+
416+
// use a set of criteria to match the request
417+
$matcher = new ChainRequestMatcher([
418+
new HostRequestMatcher('example.com'),
419+
new PathRequestMatcher('/admin'),
420+
]);
421+
422+
if ($matcher->matches($request)) {
423+
// ...
424+
}
425+
426+
.. versionadded:: 7.1
427+
428+
The :class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\HeaderRequestMatcher`
429+
and :class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\QueryParameterRequestMatcher`
430+
were introduced in Symfony 7.1.
431+
382432
Accessing other Data
383433
~~~~~~~~~~~~~~~~~~~~
384434

0 commit comments

Comments
 (0)