diff --git a/README.md b/README.md index 6349b8f..5ce45ec 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Route +# Route2 -A lightweight routing system for handling HTTP requests. +A simple routing system for PHP web applications. ### Features: - Define routes for specific HTTP methods (GET, POST, PUT, DELETE, etc.). @@ -10,46 +10,49 @@ A lightweight routing system for handling HTTP requests. ### Example: ```php +// Setup the routing context. This method must be called before defining any routes +Route2::setup(); + // Define a GET route -Route::get('/home', function () { +Route2::get('/home', function () { echo "Welcome to the homepage!"; }); // Define a route with a parameter -Route::get('/user/$id', function ($id) { +Route2::get('/user/$id', function ($id) { echo "User ID: $id"; }); // Define a route with an optional parameter -Route::get('/user/$id?', function ($id = null) { +Route2::get('/user/$id?', function ($id = null) { echo $id ? "User ID: $id" : "No User ID provided."; }); // Defining middlewares -Route::before(function () { +Route2::before(function () { echo "Middleware executed before the route callback."; }); -Route::after(function () { +Route2::after(function () { echo "Middleware executed after the route callback."; }); // Define a route with a middleware attached to it -Route::post('/submit', function () { +Route2::post('/submit', function () { echo "Form submitted!"; }, function () { echo "Middleware executed before the callback."; }); // Group routes under a common prefix -Route::group('/admin', function () { +Route2::group('/admin', function () { // Middlewares defined here will not affect the routes outside this group - Route::before(function () { + Route2::before(function () { echo "Admin Middleware executed."; }); - Route::get('/dashboard', function () { + Route2::get('/dashboard', function () { echo "Admin Dashboard"; }); - Route::post('/settings', function () { + Route2::post('/settings', function () { echo "Admin Settings"; }); }); @@ -65,7 +68,7 @@ Composer needs to know where to locate the package. Add the repository to your p "repositories": [ { "type": "vcs", - "url": "https://github.com/WilliamAAK/Route" + "url": "https://github.com/WilliamAAK/Route2" } ], "require": { @@ -82,29 +85,87 @@ Fetch the package by running Its all in a single file; include it in your project like so. ```php -require '/YourPath/Route.php' +require '/YourPath/Route2.php' ``` # Usage To get started quickly you may copy this into your project. -```php -use WilliamAAK\Http\Route; +### Classic mode -Route::get('/$world?', function($world = 'World') { +Defualt PHP behavior + +```php +

Page not found!

``` -The simplest way to access your routes is to put the file in your favorite folder and run it! E.g if you request `http://your.site/yourscript.php/your/route` the route will be automatically converted to `/your/route` +### FrankenPHP worker mode -# Rewrite requests +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!

+ =8.1.0"