PHPackages                             gortonsd/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. [Framework](/categories/framework)
4. /
5. gortonsd/router

ActiveLibrary[Framework](/categories/framework)

gortonsd/router
===============

A lightweight PHP router library with automatic controller discovery, route registration via docblock annotations, and intelligent route caching

01PHP

Since Aug 20Pushed 10mo agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

gortonsd/router
===============

[](#gortonsdrouter)

PHP Router Library

Overview
--------

[](#overview)

Router is a lightweight PHP router class that automatically discovers controllers, registers routes using docblock annotations, and caches routes for fast lookup. Designed for easy integration into your own projects or for use by other developers.

Features
--------

[](#features)

- Automatic controller discovery in a specified folder
- Route registration via `@url` docblock annotation
- Supports HTTP methods: `get`, `post` (extendable)
- File-based route caching with configurable minimum cache age
- Simple API for dispatching requests

Controller Requirements
-----------------------

[](#controller-requirements)

- Each controller must have a docblock with `@url /path`
- Implement methods named `get()`, `post()`, etc. for HTTP actions

Example:

```
/**
 * @url /example
 */
class ExampleController {
	public function get() {
		echo "GET: Hello from ExampleController!";
	}
	public function post() {
		echo "POST: You posted to ExampleController!";
	}
}
```

Usage
-----

[](#usage)

```
require_once 'vendor/autoload.php';

use gortonsd\Router\Router;

$router = new Router();
$router->loadControllers(3600); // Optional: set minimum cache age to 1 hour (3600 seconds)
$router->run($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
```

Route Caching
-------------

[](#route-caching)

- Routes are cached to a file (`routes.cache`) for fast lookup.
- Cache is rebuilt if any controller changes and the cache file is older than the minimum age.
- You can adjust the minimum cache age by passing a value (in seconds) to `loadControllers()`.

Installation
------------

[](#installation)

### Via Composer (Recommended)

[](#via-composer-recommended)

```
composer require gortonsd/router
```

### Manual Installation

[](#manual-installation)

Copy the `src/Router.php` file and your controllers into your project. Use Composer's autoload or require the files manually.

License
-------

[](#license)

MIT

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity14

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/133211967?v=4)[Gorton Software Development](/maintainers/gortonsd)[@gortonsd](https://github.com/gortonsd)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k39.6M297](/packages/laravel-dusk)[nineinchnick/edatatables

Grid widget for the Yii Framework, wrapper for the DataTables jQuery plugin

173.2k](/packages/nineinchnick-edatatables)[link-cloud/fast-hyperf

LinkCloud Fast Hyperf

241.2k1](/packages/link-cloud-fast-hyperf)

PHPackages © 2026

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