Skip to content

Commit

Permalink
AllowedFor wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 5, 2023
1 parent c1e4457 commit e3a690a
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 @@ -129,6 +129,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 e3a690a

Please sign in to comment.