Skip to content

codemonster-ru/router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

codemonster-ru/router

Latest Version on Packagist Total Downloads License Tests

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, and Controller@method strings
  • Returns a pure result, without binding to a specific Response

🧪 Testing

composer test

👨‍💻 Author

Kirill Kolesnikov

📜 License

MIT