Skip to content

Commit f41dfbe

Browse files
committed
AllowedFor wip
1 parent d6a0bcf commit f41dfbe

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
Lines changed: 21 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)