https://github.com/maxters-dev/router
A Simple PHP Router for PHP 8
https://github.com/maxters-dev/router
php router routing
Last synced: 14 days ago
JSON representation
A Simple PHP Router for PHP 8
- Host: GitHub
- URL: https://github.com/maxters-dev/router
- Owner: maxters-dev
- Created: 2022-05-29T14:48:20.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-06-02T02:56:42.000Z (over 3 years ago)
- Last Synced: 2024-04-20T17:09:09.742Z (almost 2 years ago)
- Topics: php, router, routing
- Language: PHP
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Maxters Router
A Simple PHP Router for PHP 8
Example:
```php
use Maxters\Router\Router;
use Maxters\Router\HttpVerbs;
use Maxters\Router\Exceptions\RouteNotFoundException;
$router = new Router;
$router->get('/', fn () => 'Home Page');
$router->get('/blog/{slug}', fn ($slug) => "Blog $slug");
$path = $_SERVER['PATH_INFO'] ?? '/';
$method = HttpVerbs::from($_SERVER['REQUEST_METHOD'] ?? 'GET');
try {
echo $router->execute($path, $method);
} catch (RouteNotFoundException $e) {
http_response_code(404);
echo 'Page not found';
}
```