Docs: Update

This commit is contained in:
William 2025-04-16 18:01:15 +02:00
parent d34738f094
commit 3c72d72789
2 changed files with 21 additions and 19 deletions

View File

@ -1,16 +1,17 @@
# Route2
# 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?`).
- **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
// Setup the routing context. This method must be called before defining any routes
// Initialize the router. This method must be called before defining any routes
Route2::setup();
// Define a GET route
@ -58,7 +59,7 @@ Route2::group('/admin', function () {
});
```
# Installation
## Installing
### Composer:
@ -88,14 +89,12 @@ Its all in a single file; include it in your project like so.
require '/YourPath/Route2.php'
```
# Usage
## Using Route2
To get started quickly you may copy this into your project.
### Classic mode
Defualt PHP behavior
```php
<?php
@ -161,17 +160,19 @@ for ($nbRequests = 0; !$maxRequests || $nbRequests < $maxRequests; ++$nbRequests
}
```
# Accessing your routes
## Accessing your routes
The simplest way to access your routes is to put the file in your 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`
The simplest way to access your routes is to put the file in your folder and run it.
# Rewriting requests
For example if you request ```http://your.site/yourscript.php/your/route``` the route will be automatically adjust to `/your/route`.
## Rewriting requests
Want to hide that pesky script name (e.g `index.php`) from the URL?
### FrankenPHP:
It is recommended that you use FrankenPHP the modern PHP app server. This behavior is enabled by default.
It is recommended that you use [FrankenPHP](https://frankenphp.dev); modern PHP app server. This behavior is enabled by default.
### NGINX:

View File

@ -8,14 +8,15 @@ use InvalidArgumentException;
* 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?`).
* - **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
* // Setup the routing context. This method must be called before defining any routes
* // Initialize the router. This method must be called before defining any routes
* Route2::setup();
*
* // Define a GET route