Load routes from site/routes and annotate metadata with PHP 8 attributes.
No more business logic in your config files 🎉
After installing, create a new folder site/routes. Then
create a new file for each route you want to add. The filename does not matter,
but every file must return a function, that is annotated with the provided
PHP 8 attributes:
// site/routes/my-awesome-route.php
<?php
use Kirby\Http\Response;
use PresProg\RouteAttributes\Attributes\Get;
return #[Get('/foo/(:all)')] function ($all) {
return new Response("<h1>$all</h1>", null, 200);
};The following attributes are included:
All these attributes share the same base Route attribute, which you also may use directly too:
// site/routes/my-awesome-route.php
<?php
use Kirby\Http\Response;
use PresProg\RouteAttributes\Attributes\Route;
return #[Route('/foo/(:all)', 'GET')] function ($all) {
return new Response("<h1>$all</h1>", null, 200);
};When developing in debug mode, the files will always be read from disk.
Whendebug is false, the loaded routes will be read once and then cached.
Make sure to clear the plugin cache after deployment, when you have made
changes to the routes.
composer require presprog/kirby-route-attributes
Download and copy this repository to /site/plugins/route-attributes.
git submodule add https://github.com/presprog/kirby-route-attributes.git site/plugins/route-attributes
MIT
Designed and built with ☕ and ❤ by Present Progressive