amirkamizi/php-router

this is a simple router built during the php course

dev-master 2022-11-16 19:03 UTC

This package is not auto-updated.

Last update: 2025-06-27 05:48:07 UTC


README

This package was developed during PHP Course - beginned to advance

It's a router for PHP to handle the requests.

Support us

to support me for the package or the course you can contact info@amirkamizi.com

Installation

You can install the package via composer:

composer require amirkamizi/router

Usage

you need to have a .htaccess file to redired everything to index or any other file.

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php [QSA,L]

then inside that file you can use the router to handle the reuqies.

passing name of that file that is going to handle the request.

Router::handle("GET","/contact","contact.php");

or

Router::get("/contact","contact.php");

Or you can pass anonymous and predefined functions to handle the request

Router::handle("GET","/contact",function(){
    echo "contact me at info@amirkamizi.com";
});

or

function contactMe(){
    echo "contact me at info@amirkamizi.com";
}
Router::get("/contact","contactMe");

Testing

This was for learning purposes. Not tests has been written yet.

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Contribution guidelines will be written here or on a separate file like changelog. for now no contribution is accepted.

Security Vulnerabilities

Please contact me at info@amirkamizi.com to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.