PHPackages                             pklink/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. [File &amp; Storage](/categories/file-storage)
4. /
5. pklink/file-router

AbandonedArchivedLibrary[File &amp; Storage](/categories/file-storage)

pklink/file-router
==================

Library for mapping files in a directory to routes

1.0.0(10y ago)030MITPHPPHP &gt;=5.6.0

Since Feb 19Pushed 10y ago1 watchersCompare

[ Source](https://github.com/pklink/file-router)[ Packagist](https://packagist.org/packages/pklink/file-router)[ Docs](https://github.com/pklink/file-router)[ RSS](/packages/pklink-file-router/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (7)Used By (0)

FileRouter
==========

[](#filerouter)

[![Build Status](https://camo.githubusercontent.com/d7887df604f92d2a19530541830d4e76e9cf5c8741b32af35fa5229d8251ef63/68747470733a2f2f7472617669732d63692e6f72672f706b6c696e6b2f66696c652d726f757465722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/pklink/file-router)[![Dependency Status](https://camo.githubusercontent.com/1839ad3345889854e159daebd10d600a1ac20712a73d5a492a755c49ad90083e/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3532383165333161363332626163613838653030303231312f62616467652e7376673f7374796c653d666c6174)](https://www.versioneye.com/user/projects/5281e31a632baca88e000211)

A library for mapping files in a directory to routes like `hello/world`

Usage
-----

[](#usage)

### Router for including PHP files

[](#router-for-including-php-files)

We have the following file structure:

```
.
├── example.php
└── includes
	├── hello
	│   └── world.php
    └── hello.php
```

And here is our `example.php`

```
// the source path for including files
$sourcePath = new SplFileInfo(__DIR__ . '/includes');

// create router
$router = new \FileRouter\Router\IncludeRouter($sourcePath);
```

Now you can load/include files in the `includes`-directory

```
$router->handleRoute('hello'); // include includes/hello.php
$router->handleRoute('hello/world'); // include includes/hello/world.php
```

Or like this:

```
$router->handleRoute($_GET['r']);
```

### Router for printing txt-files

[](#router-for-printing-txt-files)

We have the following file structure:

```
.
├── example.php
└── docs
	├── hello
	│   └── world.txt
    └── hello.txt
```

And here is our `example.php`

```
// the source path for including files
$sourcePath = new SplFileInfo(__DIR__ . '/docs');

// create router
$router = new \FileRouter\Router\OutputTxtRouter($sourcePath);
```

Now you can print/output files in the `docs`-directory

```
$router->handleRoute('hello'); // print includes/hello.txt
$router->handleRoute('hello/world'); // print includes/hello/world.txt
```

Advanced Usage
--------------

[](#advanced-usage)

### Write your own Router

[](#write-your-own-router)

It is no problem to write and add your own router. Implement the interface `\FileRouter\Router` or use the abtract implementation of `\FileRouter\Router\AbstractImpl`, so you only need to implement `Router::handleRoute()`

```
class CustomRouter extends \FileRouter\Router\AbstractRouter
{

	public function handleRoute($router)
	{
		/* @var \SplFileInfo $routingFile */
		$routingFile = $this->getFileByRoute($route);

		// do something
	}

}
```

Run Tests
---------

[](#run-tests)

You can use PHPUnit from the vendor-folder.

```
php composer.phar install --dev
php vendor/bin/phpunit tests/
```

License
-------

[](#license)

This package is licensed under the MIT License. See the LICENSE file for details.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~209 days

Recently: every ~261 days

Total

6

Last Release

3788d ago

Major Versions

0.3.0 → 1.0.02016-01-03

PHP version history (2 changes)0.1PHP &gt;=5.3.0

1.0.0PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/1c8c5e958e572c9805a2746a44c66ffd72fdfb22f1f5c7f0723a40afee9ec176?d=identicon)[pklink](/maintainers/pklink)

---

Top Contributors

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

---

Tags

filesystemroutingfile

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[league/flysystem

File storage abstraction for PHP

13.6k639.1M2.2k](/packages/league-flysystem)[league/flysystem-aws-s3-v3

AWS S3 filesystem adapter for Flysystem.

1.6k263.6M790](/packages/league-flysystem-aws-s3-v3)[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.8M123](/packages/knplabs-gaufrette)[knplabs/knp-gaufrette-bundle

Allows to easily use the Gaufrette library in a Symfony project

72428.6M91](/packages/knplabs-knp-gaufrette-bundle)[league/flysystem-local

Local filesystem adapter for Flysystem.

225231.8M39](/packages/league-flysystem-local)[league/flysystem-memory

In-memory filesystem adapter for Flysystem.

8533.6M194](/packages/league-flysystem-memory)

PHPackages © 2026

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