Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit977eeda

Browse files
committed
minor#19509 [HttpFoundation] Mention Request Matchers (alexandre-daubois)
This PR was merged into the 6.4 branch.Discussion----------[HttpFoundation] Mention Request MatchersThat's required for#19508Commits-------cfbdd7a [HttpFoundation] Mention Request Matchers
2 parentsc018641 +cfbdd7a commit977eeda

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

‎components/http_foundation.rst‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,48 @@ use the ``isPrivateIp()`` method from the
396396

397397
The ``isPrivateIp()`` method was introduced in Symfony 6.3.
398398

399+
Matching a Request Against a Set Rules
400+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
401+
402+
If you need to match a request against a set of rules, you can use
403+
request matchers. The HttpFoundation component provides many matchers
404+
to be used:
405+
406+
*:class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\AttributesRequestMatcher`
407+
*:class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\ExpressionRequestMatcher`
408+
*:class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\HostRequestMatcher`
409+
*:class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\IpsRequestMatcher`
410+
*:class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\IsJsonMatcher`
411+
*:class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\MethodRequestMatcher`
412+
*:class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\PathRequestMatcher`
413+
*:class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\PortRequestMatcher`
414+
*:class:`Symfony\\Component\\HttpFoundation\\RequestMatcher\\SchemeRequestMatcher`
415+
416+
You can either use them directly or combine them using the
417+
:class:`Symfony\\Component\\HttpFoundation\\ChainRequestMatcher`
418+
class::
419+
420+
use Symfony\Component\HttpFoundation\ChainRequestMatcher;
421+
use Symfony\Component\HttpFoundation\RequestMatcher\HostRequestMatcher;
422+
use Symfony\Component\HttpFoundation\RequestMatcher\PathRequestMatcher;
423+
use Symfony\Component\HttpFoundation\RequestMatcher\SchemeRequestMatcher;
424+
425+
// use only one criteria to match the request
426+
$schemeMatcher = new SchemeRequestMatcher('https');
427+
if ($schemeMatcher->matches($request)) {
428+
// ...
429+
}
430+
431+
// use a set of criteria to match the request
432+
$matcher = new ChainRequestMatcher([
433+
new HostRequestMatcher('example.com'),
434+
new PathRequestMatcher('/admin'),
435+
]);
436+
437+
if ($matcher->matches($request)) {
438+
// ...
439+
}
440+
399441
Accessing other Data
400442
~~~~~~~~~~~~~~~~~~~~
401443

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp