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
{
}
...
}
- Install the package via composer:
composer require kryptamine/groot
- Use a supported adapter or implement your own
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();
To create your own adapter, you should implement RouteRegistrarAdapterInterface