kryptamine / groot
PHP 8 attributes based router adapter
Installs: 19
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/kryptamine/groot
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