File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Nette \Application \Attributes ;
6
+
7
+ use Attribute ;
8
+
9
+
10
+ #[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_CLASS )]
11
+ class AllowedFor
12
+ {
13
+ public function __construct (
14
+ public ?bool $ httpGet = null ,
15
+ public ?bool $ httpPost = null ,
16
+ public ?bool $ forward = null ,
17
+ public ?array $ actions = null ,
18
+ public ?bool $ crossOrigin = null ,
19
+ ) {
20
+ }
21
+ }
Original file line number Diff line number Diff line change @@ -134,6 +134,13 @@ public function checkRequirements($element): void
134
134
) {
135
135
$ this ->getPresenter ()->detectedCsrf ();
136
136
}
137
+
138
+ if ($ attrs = $ element ->getAttributes (Nette \Application \Attributes \AllowedFor::class)) {
139
+ $ method = strtolower ($ this ->getPresenter ()->getRequest ()->getMethod ());
140
+ if (empty ($ attrs [0 ]->newInstance ()->$ method )) {
141
+ throw new Nette \Application \BadRequestException ("Method ' $ method' is not allowed. " );
142
+ }
143
+ }
137
144
}
138
145
139
146
You can’t perform that action at this time.
0 commit comments