blank-framework/file-path-router

Package for the Blank Framework FilePathRouter

2.0.0 2024-07-31 05:56 UTC

This package is auto-updated.

Last update: 2024-08-31 06:14:01 UTC


README

FilePathRouter is a simple routing package that maps a path such as /blog/posts to the directory /blog/posts. If that directory exists, it executes the index.php file inside.

Usage

To start, instantiate the FilePathRouter class and pass the absolute path to the directory where your routes will be located. If it is in the root of your project directory is could be like the code snippet below:

$router = new FilePathRouter(__DIR__ . '/routes');

To route your requests, get the requested path for example /blog and pass it into the function routeRequest as shown below:

$router->routeRequest('/blog');

Directory Structure and Routing

FilePathRouter's routing mechanism is dependent on your project's directory structure. The home route (/) is mapped to the index.php file in the /routes directory. To create a new path, such as /blog, simply create a directory named blog within /routes. Place an index.php file in this new directory, and this file will be executed whenever the /blog path is requested.

Exceptions

If the routes path you provided in the constructor does not exist, the router will throw a RoutesPathNotFoundException. If the requested route could not be found, the router will throw a RouteNotFoundException.