PHPackages                             lizzyman04/file-router - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. lizzyman04/file-router

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

lizzyman04/file-router
======================

Next.js-style file-based routing for PHP. Zero dependencies, framework-agnostic.

00PHPCI passing

Since Jun 18Pushed todayCompare

[ Source](https://github.com/lizzyman04/file-router)[ Packagist](https://packagist.org/packages/lizzyman04/file-router)[ RSS](/packages/lizzyman04-file-router/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

file-router
===========

[](#file-router)

Next.js-style **file-based routing** for PHP. The directory structure *is* the route table — no separate route file to keep in sync. Zero runtime dependencies, framework-agnostic, PHP 8.1+.

Extracted from [Fluxor](https://github.com/lizzyman04/fluxor) so it can be used standalone or dropped into any stack.

Install
-------

[](#install)

```
composer require lizzyman04/file-router
```

Routing conventions
-------------------

[](#routing-conventions)

File on diskURL patternParams`index.php``/`—`about.php``/about`—`users/[id].php``/users/{id}``id``posts/[id]/comments.php``/posts/{id}/comments``id``files/[...slug].php``/files/{slug:*}` (catch-all)`slug` (rest of path)`(admin)/dashboard.php``/dashboard`group folder strippedMatching is specificity-ordered: **static &gt; dynamic &gt; catch-all**, so `/users/me` beats `/users/[id]`.

Standalone usage
----------------

[](#standalone-usage)

```
use FileRouter\FileRouter;

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

$match = $router->match($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);

if ($match === null) {
    http_response_code(404);
} elseif ($match->isMethodNotAllowed()) {
    http_response_code(405);
    header('Allow: ' . implode(', ', $match->allowedMethods));
} else {
    // $match->file   — the route file to include/dispatch
    // $match->params — e.g. ['id' => '42'] for /users/42
    (function (string $__file, array $params) {
        include $__file;
    })($match->file, $match->params);
}
```

PSR-7
-----

[](#psr-7)

`match()` takes a method and a path string, so any PSR-7 request adapts in one line:

```
$match = $router->match(
    $request->getMethod(),
    $request->getUri()->getPath()
);
```

Options
-------

[](#options)

```
$router = new FileRouter(__DIR__ . '/routes', [
    // Where compiled routes are cached. Omit for no caching (compile per request).
    'cacheDir' => __DIR__ . '/var/cache',
    'cache'    => true,

    // How route files declare their HTTP methods. Default: Flow syntax.
    'methodExtractor' => new \FileRouter\Extractor\FlowMethodExtractor(),
]);

$router->clearCache(); // invalidate the compiled table
```

### Method extractors

[](#method-extractors)

A route file can serve several HTTP methods; how that's declared is pluggable via the `MethodExtractor` interface.

- **`FlowMethodExtractor`** (default) — reads `Flow::GET()`, `Flow::POST()`, … declarations (Fluxor style). `Flow::ANY()` expands to all methods. No dependency on Fluxor; it only reads the file's text.
- **`FixedMethodExtractor`** — every route file serves the same fixed set of methods (e.g. you dispatch by method inside the file).
- **Custom** — implement `MethodExtractor::extract(string $file): array`.

Framework adapters
------------------

[](#framework-adapters)

- Laravel — tracked in [fluxor#3](https://github.com/lizzyman04/fluxor/issues/3)
- Symfony — tracked in [fluxor#5](https://github.com/lizzyman04/fluxor/issues/5)

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

MIT

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance65

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/130801183?v=4)[Arlindo Abdul](/maintainers/lizzyman04)[@lizzyman04](https://github.com/lizzyman04)

---

Top Contributors

[![lizzyman04](https://avatars.githubusercontent.com/u/130801183?v=4)](https://github.com/lizzyman04 "lizzyman04 (4 commits)")

### Embed Badge

![Health badge](/badges/lizzyman04-file-router/health.svg)

```
[![Health](https://phpackages.com/badges/lizzyman04-file-router/health.svg)](https://phpackages.com/packages/lizzyman04-file-router)
```

###  Alternatives

[santigarcor/laravel-vuetable

Vuetable laravel backend package

2750.3k](/packages/santigarcor-laravel-vuetable)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
