kryptamine / groot
PHP 8 attributes based router adapter
0.0.1
2021-09-26 12:15 UTC
Requires
- php: ^8.0
Requires (Dev)
- phpunit/phpunit: ^9.5
README
This package is an adapter that provides the ability to integrate PHP 8 attributes with any router you'd prefer to use.
use Kryptamine\Groot\Attributes\Get; use Kryptamine\Groot\Attributes\Post; use Kryptamine\Groot\Attributes\Controller; #[Controller('users')] class UserController { #[Get('/')] public function getUsers(): void { } #[Get('/{id:\d+}')] public function getUser(int $id): void { } #[Post('/')] public function saveUser(): void { } ... }
Installation
- Install the package via composer:
composer require kryptamine/groot
- Use a supported adapter or implement your own
Usage example
namespace Kryptamine\Groot; use Kryptamine\Groot\Router; use Bramus\Router\Router as BramusRouter; use Kryptamine\Groot\Adapters\BramusRouterAdapter; require 'vendor/autoload.php'; $bramusRouter = new BramusRouter(); $router = new Router(BramusRouterAdapter::fromBramusRouter($bramusRouter), [ UserController::class, ]); $router->register(); $bramusRouter->run();
Supported Adapters
To create your own adapter, you should implement RouteRegistrarAdapterInterface