@@ -28,7 +28,12 @@ options are used for matching:
28
28
* ``ip `` or ``ips ``: netmasks are also supported (can be a comma-separated string)
29
29
* ``port ``: an integer
30
30
* ``host ``: a regular expression
31
- * ``methods ``: one or many methods
31
+ * ``methods ``: one or many HTTP methods
32
+ * ``request_matcher ``: a service implementing ``RequestMatcherInterface ``
33
+
34
+ .. versionadded :: 6.1
35
+
36
+ The ``request_matcher `` option was introduced in Symfony 6.1.
32
37
33
38
Take the following ``access_control `` entries as an example:
34
39
@@ -52,6 +57,9 @@ Take the following ``access_control`` entries as an example:
52
57
- { path: '^/admin', roles: ROLE_USER_IP, ips: '%env(TRUSTED_IPS)%' }
53
58
- { path: '^/admin', roles: ROLE_USER_IP, ips: [127.0.0.1, ::1, '%env(TRUSTED_IPS)%'] }
54
59
60
+ # for custom matching needs, use a request matcher service
61
+ - { roles: ROLE_USER, request_matcher: App\Security\RequestMatcher\MyRequestMatcher }
62
+
55
63
.. code-block :: xml
56
64
57
65
<!-- config/packages/security.xml -->
@@ -82,6 +90,9 @@ Take the following ``access_control`` entries as an example:
82
90
<ip >::1</ip >
83
91
<ip >%env(TRUSTED_IPS)%</ip >
84
92
</rule >
93
+
94
+ <!-- for custom matching needs, use a request matcher service -->
95
+ <rule role =" ROLE_USER" request-matcher =" App\Security\RequestMatcher\MyRequestMatcher" />
85
96
</config >
86
97
</srv : container >
87
98
@@ -127,6 +138,12 @@ Take the following ``access_control`` entries as an example:
127
138
->roles(['ROLE_USER_IP'])
128
139
->ips(['127.0.0.1', '::1', env('TRUSTED_IPS')])
129
140
;
141
+
142
+ // for custom matching needs, use a request matcher service
143
+ $security->accessControl()
144
+ ->roles(['ROLE_USER'])
145
+ ->requestMatcher('App\Security\RequestMatcher\MyRequestMatcher')
146
+ ;
130
147
};
131
148
132
149
For each incoming request, Symfony will decide which ``access_control ``
0 commit comments