# Route2 🛣️ A simple routing system for PHP web applications. ### Features: - **Simplicity**: Easily map URLs to specific callback functions. - **Parameters**: Flexible URL handling with parameters (e.g., `/user/$id`). - **Middleware**: Register functions to execute **before** and **after** routes. - **Grouping**: Organize related routes and apply group-specific middleware. - **Lightweight**: A single-file, no-frills routing solution with zero dependencies. ### Example: ```php // Initialize the router. 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"; }); }); ``` ## Installing ### 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/route2": "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' ``` ## Using Route2 To get started quickly you may copy this into your project. ### Classic mode ```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!