Skip to content

Primitive router, to simplify the understanding of the logic.

License

Notifications You must be signed in to change notification settings

Jagepard/Primate-Router

Repository files navigation

PHPunit Scrutinizer Code Quality Maintainability License: MIT

Primate-Router

Прмиитивный маршрутизатор, для упрощения понимания логики. | API

Использование:

use Primate\Router\Router;

$router = new Router();

Далее обязательно разбираем "REQUEST_URI"

$requestUri = explode('/', trim(parse_url($_SERVER["REQUEST_URI"])["path"], '/'));

После добавления всех маршрутов вызываем метод сопоставление маршрутов с данными запроса "REQUEST_URI"

$router->matchRoute($requestUri);

Добавление маршрутов:

В случае перехода по адресу /closure в браузере, в окне будет отображено "Hello World!", по умолчанию $_SERVER["REQUEST_METHOD"] === "GET"

$router->addRoute("/closure", function () {
    echo "Hello World!";
});

В случае перехода по адресу /closure/john в браузере, в окне будет отображено "Hello john!"

$router->addRoute("/closure/:name", function ($name) {
    echo "Hello $name!";
});

При изменении метода запроса необходимо также его указать 3 параметром при добавлении маршрута

$router->addRoute("/closure", function () {
    echo "Hello World!";
}, "POST");

About

Primitive router, to simplify the understanding of the logic.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages