Initial commit

This commit is contained in:
2024-01-14 07:40:38 +01:00
commit 548d376e96
5 changed files with 302 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
<?php
namespace NetteUtils\Routing;
use Nette\Application\Routers\Route;
use Nette\Http\IRequest;
/**
* Extended Nette Route with capability to validate request method
*
* @author Jan Pavlíček <jan@pavlicek.dev>
*/
class RestRoute extends Route
{
/**
* List of HTTP methods that will match with this route
* @var array
*/
protected $allowedMethods = ['GET', 'POST', 'OPTIONS'];
public function __construct($methods, $mask, $metadata = [], $flags = 0)
{
if ($methods) {
$this->allowedMethods = array_merge(explode('|', $methods), ['OPTIONS']);
}
parent::__construct($mask, $metadata, $flags);
}
/**
* Maps HTTP request to a Request object. Does not match, if methods are defined and request
* does not match one of them.
*
* @return Nette\Application\Request|NULL
*/
public function match(IRequest $httpRequest) : ?array
{
if (!in_array($httpRequest->getMethod(), $this->allowedMethods)) {
return null;
}
return parent::match($httpRequest);
}
}