PHPackages                             davidfricker/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. davidfricker/router

ActiveLibrary[Framework](/categories/framework)

davidfricker/router
===================

Lightweight PHP OOP web request routing system

5(9y ago)1291MITPHPPHP ^5.3.3 || ^7.0

Since Feb 7Pushed 9y ago1 watchersCompare

[ Source](https://github.com/DavidFricker/web-request-routing)[ Packagist](https://packagist.org/packages/davidfricker/router)[ RSS](/packages/davidfricker-router/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)DependenciesVersions (6)Used By (0)

Web request routing
===================

[](#web-request-routing)

A standalone lightweight web request routing system.

Install
-------

[](#install)

### Using composer

[](#using-composer)

`composer require DavidFricker/Router`

### Non composer

[](#non-composer)

This package is PSR-4 compliant so creating your own autoloader should easy if you do not wish to use composer.

Usage example
-------------

[](#usage-example)

Before any requests can be routed they must be defined and stored within a RouteContainer object.

```
use DavidFricker\Router\Capsule\RouteContainer;

$RouteContainer = DavidFricker\Router\Capsule\RouteContainer::init();
```

### Create a static route

[](#create-a-static-route)

The following line will create a static route. Static routes are those without any dynamic components that require parsing. The first argument is the URI the client should navigate to. The second argument is the HTTP method they should use to request the. The third argument can be an anonymous function or a string that identifies a method of a given class.

#### Directing to a class member

[](#directing-to-a-class-member)

```
// the method, in this instance `getPage`, should accept a $Request object as its single parameter
$RouteContainer->set('/dashboard', RouteContainer::HTTP_METHOD_GET, 'getPage@Namespace\Vendor\Package\Controller\Dashboard');
```

#### Directing to an anonymous function

[](#directing-to-an-anonymous-function)

```
$RouteContainer->set('/dashboard', RouteContainer::HTTP_METHOD_GET, function($Request){
  echo 'Welcome to your dashboard';
});
```

### Create a dynamic route

[](#create-a-dynamic-route)

Dynamic routes are defined in the same fashion as their static counterparts. However, in the defined route any parts that are surrounded by curly braces will be parsed and passed to the called function through the `Request` object. An example of format and usage can be seen below.

```
$RouteContainer->set('/confirm/{token}/complete', RouteContainer::HTTP_METHOD_GET, function($Request){
  echo 'Token: ' . $Request->getParsedUrlParameters('token');
});
```

Request class reference
-----------------------

[](#request-class-reference)

#### getMethod

[](#getmethod)

Getter method for the HTTP request method returns `string` HTTP request method

#### getUrlElements

[](#geturlelements)

Fetch a single part of the path or all in the form of an array. To fetch all parts in an array supply no arguments. To fetch a single part supply the numeric index of the expected position of the part starting from zero. The path elements are split around '/'.

For example, the `Request` object for the URI `/path/to/page` would return the string 'to' when calling `getUrlElements(1)`.

#### getParameters

[](#getparameters)

Fetch parameters sent with the request. This method acts similarly to the $\_REQUEST array. To fetch all parameters in an array supply no arguments. To fetch a single value supply the parameter key (in the same way you would fetch a value from the $\_POST or $\_GET arrays).

#### getParsedUrlParameters

[](#getparsedurlparameters)

Fetch parsed elements of the request path. Returns the parsed value from the request URI using the request route. For example, if the template route path were 'path/to/article/{article\_id}', the requested URI were 'path/to/article/4455', then the array \[article\_id =&gt; 4455\] would be passed to this method. This would then be accessible by the following method call `getParsedUrlParameters('article_id')`

Bugs
----

[](#bugs)

Bug reports welcome, please included details to reproduce the bugs. Commits are also very welcome for bug fixes, features, or refactoring.

License
-------

[](#license)

Released under the MIT license.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

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 ~17 days

Total

5

Last Release

3310d ago

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M190](/packages/laravel-telescope)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[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.7M256](/packages/laravel-dusk)[laravel/prompts

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

708181.8M591](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

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

PHPackages © 2026

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