codemonster-ru / router
Lightweight router for PHP applications
Installs: 26
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/codemonster-ru/router
Requires
- php: >=8.2
Requires (Dev)
- phpunit/phpunit: ^9.6 || ^10.5 || ^11.0 || ^12.0
README
A lightweight router for PHP applications.
๐ฆ Installation
composer require codemonster-ru/router
๐ Usage
use Codemonster\Router\Router; $router = new Router(); $router->get('/', fn() => 'Home Page'); $router->get('/about', fn() => 'About Us'); $result = $router->dispatch( $_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) ); if ($result === null) { http_response_code(404); echo 'Not Found'; } else { echo $result; }
โจ Features
- Simple route registration (
get
,post
,any
) - Support for callbacks,
[Controller::class, 'method']
controllers, andController@method
strings - Returns a pure result, without binding to a specific
Response
๐งช Testing
composer test