adrienlucbert / php-router
Minimal router framework for PHP, inspired by ExpressJS.
Installs: 31
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/adrienlucbert/php-router
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2025-11-05 02:20:17 UTC
README
This project is a minimal router framework for PHP, inspired by ExpressJS.
Installation
Use composer to manage and dependencies and download PHP Router.
composer require adrienlucbert/php-router
Example
ℹ️ find more examples under
/examplesdirectory
⚠️ You may also use with a
.htaccessfile redirecting all requests to a single file. This file will be responsible for describing routes: we call itindex.phpfor the purpose of this example, but you may call it as you wish, just make sure the.htaccessfile redirects to it.
<?php // use composer autoload to include package files require __DIR__ . '/vendor/autoload.php'; // alias \PHPRouter\App class use \PHPRouter\App; // create an App object, against which you will then register routes $app = new App(); // register a new route to call when requested uri matches '/' in http method GET $app->get('/', function(&$req, callable $next) { // do whatever you want this route to do print_r($req); // execute next route matching the requested uri $next(); }); // execute application mountpoints according to the requested uri $app->execute();