presprog / kirby-route-attributes
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 4
Forks: 0
Open Issues: 0
Type:kirby-plugin
Requires
- php: ^8.0
- getkirby/composer-installer: ^1.2
README
Load routes from site/routes
and annotate metadata with PHP 8 attributes.
No more business logic in your config files 🎉
Usage
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.
Installation
Composer
composer require presprog/kirby-route-attributes
Download
Download and copy this repository to /site/plugins/route-attributes
.
Git submodule
git submodule add https://github.com/presprog/kirby-route-attributes.git site/plugins/route-attributes
License
MIT
Credits
Designed and built with ☕ and ❤ by Present Progressive