Skip to content

Commit

Permalink
AllowedFor wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Feb 8, 2024
1 parent 5d9dfad commit 929a242
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Application/Attributes/AllowedFor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Nette\Application\Attributes;

use Attribute;


#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_CLASS)]
class AllowedFor
{
public function __construct(
public ?bool $httpGet = null,
public ?bool $httpPost = null,
public ?bool $forward = null,
public ?array $actions = null,
public ?bool $crossOrigin = null,
) {
}
}
7 changes: 7 additions & 0 deletions src/Application/UI/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ public function checkRequirements($element): void
) {
$this->getPresenter()->detectedCsrf();
}

if ($attrs = $element->getAttributes(Nette\Application\Attributes\AllowedFor::class)) {
$method = strtolower($this->getPresenter()->getRequest()->getMethod());
if (empty($attrs[0]->newInstance()->$method)) {
throw new Nette\Application\BadRequestException("Method '$method' is not allowed.");
}
}
}


Expand Down

0 comments on commit 929a242

Please sign in to comment.