fahrradkrucken/sf-router

There is no license information available for the latest version (v1.0.0) of this package.

Simple, single-file, dependency-free PHP router.

v1.0.0 2020-03-15 12:45 UTC

This package is auto-updated.

Last update: 2025-03-15 23:42:50 UTC


README

Info

This is the simple router, implemented in one file, that could be used through traditional composer-dependency or through require statement.

Installation

  • Through Composer: composer require fahrradkrucken/sf-router.
  • As a separate file: require('path/to/sf-router.php').

Features

Basically, it allows us to (almost) do everything we usually do with routers:

  • Add GET/POST/PUT/PATCH/DELETE routes (or several request methods at once);
  • Add route groups;
  • Add callbacks to routes/route-groups as well as add before/after actions (callbacks);
  • Set custom URI and REQUEST_METHOD (as FastRoute allows us to do);
  • Set simple named params inside your route, smth like
    my-api/v2/user/{user_id}/actions/{action_id}/view.

What it can't do for you:

  • Handle your route's callback;
  • Get you the GET and POST request parameters.

So the only thing it does is takes your URI/REQUEST_METHOD and returns correct route, based on list of routes, provided by you.

Usage

See the demo.php file inside this repo to see how to use it.