File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
Expand file tree Collapse file tree 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 @@ -132,6 +132,13 @@ public function checkRequirements($element): void
132132 ) {
133133 $ this ->getPresenter ()->detectedCsrf ();
134134 }
135+
136+ if ($ attrs = $ element ->getAttributes (Nette \Application \Attributes \AllowedFor::class)) {
137+ $ method = strtolower ($ this ->getPresenter ()->getRequest ()->getMethod ());
138+ if (empty ($ attrs [0 ]->newInstance ()->$ method )) {
139+ throw new Nette \Application \BadRequestException ("Method ' $ method' is not allowed. " );
140+ }
141+ }
135142 }
136143
137144
You can’t perform that action at this time.
0 commit comments