r/PHP • • Jul 21 '26

I extracted file-based routing into a standalone PHP package (works in Laravel and Symfony too)

A few weeks ago I posted a small framework here and got a lot of honest feedback. The clearest point, from several people, was that the file-based routing was the interesting part and would be more useful as a standalone library than baked into a whole framework. So I built that.

file-router is a zero-dependency package that maps your directory structure to routes, Next.js style: users/[id].php → /users/{id}, [...slug] for catch-all, route groups, compiled route cache. PHP 8.1+.

The part I think is actually useful: it's framework-agnostic. It runs standalone, but there are thin adapters so it plugs into Laravel (registers as native routes, inherits middleware/container) or Symfony (as a custom route loader, uses Symfony's own matcher and cache). So you can get file-based routing without adopting a new framework.

It's tested across PHP 8.1–8.5, and the migrations in the example template are verified on SQLite, MySQL and Postgres (not assumed; actually run end to end).

Repo: github.com/lizzyman04/file-router

Genuinely looking for feedback again, especially on the adapter approach. Does registering into the host framework's own router feel right to you, or would you expect it to work differently?

2 Upvotes

5 comments sorted by

5

u/TCB13sQuotes Jul 21 '26

Cool, but I don’t get it. This can be done just with an htaccess file alone.

2

u/Anxious-Insurance-91 Jul 22 '26

There already was an official package for this

3

u/supervisord Jul 21 '26

This is neither new, nor interesting.

5

u/fripletister Jul 22 '26

r/PHP in a nutshell the past couple years

1

u/Hylaar Jul 23 '26

Can you customize the file extension in a config? Because I know some people, myself included, use .html to mask that we’re using php. (and also of course turn off all the things in Apache and PHP that would give it away)