2025-03-26 17:20:17 +00:00
2023-03-23 08:13:57 +00:00
2025-03-26 17:20:17 +00:00
2023-03-21 21:41:02 +01:00
2025-03-26 17:01:15 +00:00
2025-03-26 16:21:37 +00:00

Route

Minimalistic Web Application Router

Installation

Composer

Composer needs to know where to locate the package. Add the repository to your project by declaring it in the composer.json file.

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://git.willy.club/WillySoft/Route"
        }
    ],
    "require": {
        "willysoft/route": "dev-master"
    }
}

Fetch the package by running

composer install

Manual

Its all in a single file; include it in your project like so

require '/change_this/Route.php'

Usage

See example.php

Access directly

The simplest way to access your routes. Put your file in the folder you like and it will automatically account for it.

Examples

ENTRYPOINT = /index.php
/index.php                    -> /
/index.php/                   -> /
/                             -> /
/index.php/somepath           -> /somepath

ENTRYPOINT = /your_root/index.php
/your_root/index.php          -> /
/your_root/index.php/         -> /
/your_root/                   -> /
/your_root/index.php/somepath -> /somepath

Rewrite requests

The more sexy way of doing it. Suitable for production.

ENTRYPOINT = /index.php
/         -> /
/somepath -> /somepath

NGINX

With PHP already configured, add this to the server block of your configuration to make requests that don't match a file on your server to be sent to your front controller and begin routing.

location / {
    try_files $uri $uri/ /index.php?$query_string;
}
Description
Minimal PHP Router
Readme WTFPL 56 KiB
Languages
PHP 100%