# Route2 A simple routing system for PHP web applications. ### Features: - Define routes for specific HTTP methods (GET, POST, PUT, DELETE, etc.). - Apply middleware to routes or groups of routes. - Group routes under a common prefix for better organization. - Support for route parameters (e.g., `/user/$id`) and optional parameters (e.g., `/user/$id?`). ### Example: ```php // Setup the routing context. This method must be called before defining any routes Route2::setup(); // Define a GET route Route2::get('/home', function () { echo "Welcome to the homepage!"; }); // Define a route with a parameter Route2::get('/user/$id', function ($id) { echo "User ID: $id"; }); // Define a route with an optional parameter Route2::get('/user/$id?', function ($id = null) { echo $id ? "User ID: $id" : "No User ID provided."; }); // Defining middlewares Route2::before(function () { echo "Middleware executed before the route callback."; }); Route2::after(function () { echo "Middleware executed after the route callback."; }); // Define a route with a middleware attached to it Route2::post('/submit', function () { echo "Form submitted!"; }, function () { echo "Middleware executed before the callback."; }); // Group routes under a common prefix Route2::group('/admin', function () { // Middlewares defined here will not affect the routes outside this group Route2::before(function () { echo "Admin Middleware executed."; }); Route2::get('/dashboard', function () { echo "Admin Dashboard"; }); Route2::post('/settings', function () { echo "Admin Settings"; }); }); ``` # Installation ### Composer: Composer needs to know where to locate the package. Add the repository to your project by declaring it in the `composer.json` file. ```json { "repositories": [ { "type": "vcs", "url": "https://github.com/WilliamAAK/Route2" } ], "require": { "williamaak/route": "dev-master" } } ``` Fetch the package by running composer install ### Manual: Its all in a single file; include it in your project like so. ```php require '/YourPath/Route2.php' ``` # Usage To get started quickly you may copy this into your project. ### Classic mode Defualt PHP behavior ```php

Page not found!

``` ### FrankenPHP worker mode Boot your application once and keep it in memory by using [worker mode](https://frankenphp.dev/docs/worker/). Simply do what you would normally do but inside the handler. ```php

Page not found!