Skip to content

Commit af03d73

Browse files
committed
Method wip
1 parent 5790d91 commit af03d73

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 Method
12+
{
13+
public function __construct(
14+
public bool $get = false,
15+
public bool $post = false,
16+
public bool $forward = true,
17+
) {
18+
}
19+
}

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\Method::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)