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 9mo agoCompare

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

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

16

—

LowBetter than 5% of packages

Maintenance42

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

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://www.gravatar.com/avatar/06097c6331cdec0a85129b866f47e82de3ddf1e84b949378f77a09a76a41d8eb?d=identicon)[gortonsd](/maintainers/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/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M532](/packages/laravel-passport)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

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

1.9k36.7M259](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

712181.8M596](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)[laravel/pail

Easily delve into your Laravel application's log files directly from the command line.

91545.3M590](/packages/laravel-pail)

PHPackages © 2026

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