Skip to content

Commit c19ebdc

Browse files
committed
AllowedFor wip
1 parent e32ebcf commit c19ebdc

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
}

src/Application/UI/Component.php

+7
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ public function checkRequirements($element): void
134134
) {
135135
$this->getPresenter()->detectedCsrf();
136136
}
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+
}
137144
}
138145

139146

0 commit comments

Comments
 (0)