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

ActiveLibrary

racoon/router
=============

A basic extension of nikic/fast-route.

1.0.1(9y ago)04761proprietaryPHP

Since Jun 13Pushed 9y ago1 watchersCompare

[ Source](https://github.com/TomWright/RacoonRouter)[ Packagist](https://packagist.org/packages/racoon/router)[ RSS](/packages/racoon-router/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (3)Used By (1)

Racoon Router
=============

[](#racoon-router)

[![Build Status](https://camo.githubusercontent.com/67ccb9feccf38971121f0ab8edc0ef532b845f63c18eef89b52afb38a3dc8c31/68747470733a2f2f7472617669732d63692e6f72672f546f6d5772696768742f5261636f6f6e526f757465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/TomWright/RacoonRouter)[![Total Downloads](https://camo.githubusercontent.com/f06c6906e54585a1cddf2d2fe1e73011a722649c0ea6a15ddd2cc413531bf3f0/68747470733a2f2f706f7365722e707567782e6f72672f7261636f6f6e2f726f757465722f642f746f74616c2e737667)](https://packagist.org/packages/racoon/router)[![Latest Stable Version](https://camo.githubusercontent.com/195d66aac4abb8b63464358324d07ad374bc8d6f2c31444d59c8e1f29f889d51/68747470733a2f2f706f7365722e707567782e6f72672f7261636f6f6e2f726f757465722f762f737461626c652e737667)](https://packagist.org/packages/racoon/router)[![Latest Unstable Version](https://camo.githubusercontent.com/be25a566b3eac9b63f7ca15abf9084e58b35f6529f73b4154d26ae21e7b54f14/68747470733a2f2f706f7365722e707567782e6f72672f7261636f6f6e2f726f757465722f762f756e737461626c652e737667)](https://packagist.org/packages/racoon/router)[![License](https://camo.githubusercontent.com/df0aadda1aa1aace627b293569413e19ad2791a9117954c5e474c04aa1c259e7/68747470733a2f2f706f7365722e707567782e6f72672f7261636f6f6e2f726f757465722f6c6963656e73652e737667)](https://packagist.org/packages/racoon/router)

Routing
-------

[](#routing)

Racoon uses [nikic/fast-route](https://github.com/nikic/FastRoute) to deal with routing.

### Defining where routes are stored

[](#defining-where-routes-are-stored)

Routes need to be added in a routes file, which should be added to the `Router`, or defined in an anonymous function passed to the router.

```
$router->addRouteFile('/path/to/some_routes.php');

// Tells the router you are done adding routes so as it can process them.
$router->init();
```

If you want to store routes in multiple locations you can do it as follows.

```
$router
    ->addRouteFile('/path/to/some_routes.php')
    ->addRouteFile('/path/to/more_routes.php')
    ->addRouteFile('/path/to/even_more_routes.php');

// Tells the router you are done adding routes so as it can process them.
$router->init();
```

If you define multiple route locations, they will be included/added in the same order as you define them.

To define routes without storing them in a separate file you can do the following.

```
$router->addRouteCallable(function($r) {
    // Define your routes here as if they were in another file.
    // $r->addRoute(), $r->addGroup(), etc are all available.
});
```

### Setting up routes

[](#setting-up-routes)

Inside one of the route files that have been added to the router you need to define your routes in the following format.

```
$httpRequestMethod = ['GET', 'POST'];
$requestUri = '/users/list';
$handlerString = '\\MyApp\\Users@list';
$r->addRoute($httpRequestMethod, $requestUri, $handlerString);
```

#### Route Groups

[](#route-groups)

To make it easier to set up long urls multiple times you can use groups. The following code blocks give the same result.

```
$r->addRoute(['GET', 'POST'], '/users/list', '\\MyApp\\Users@list');
$r->addRoute(['GET', 'POST'], '/users/get', '\\MyApp\\Users@get');
$r->addRoute(['GET', 'POST'], '/users/update', '\\MyApp\\Users@update');
$r->addRoute(['GET', 'POST'], '/users/delete', '\\MyApp\\Users@delete');
```

```
$r->addGroup('/users', function () {
    $r->addRoute(['GET', 'POST'], '/list', '\\MyApp\\Users@list');
    $r->addRoute(['GET', 'POST'], '/get', '\\MyApp\\Users@get');
    $r->addRoute(['GET', 'POST'], '/update', '\\MyApp\\Users@update');
    $r->addRoute(['GET', 'POST'], '/delete', '\\MyApp\\Users@delete');
});
```

You can also use sub-groups. The following code blocks give the same result.

```
$r->addRoute(['GET', 'POST'], '/some/long/url/do-something', '\\MyApp\\Users@list');
```

```
$r->addGroup('/some', function ($r) {
    $r->addGroup('/long', function ($r) {
        $r->addGroup('/url', function ($r) {
            $r->addRoute(['GET', 'POST'], '/do-something', '\\MyApp\\Users@list');
        });
    });
});
```

#### HTTP Request Method

[](#http-request-method)

The HTTP Request Method(s) that the route should match. This can be any HTTP request type such as `GET` or `POST`.

Can be a `string` or an `array` of `string`s.

#### Request URI

[](#request-uri)

The request URI that the route should match.

You can define the request URI in multiple ways.

```
'/users/list'
'/users/get/{userId}'
'/users/get/{userId:\d+}'
```

For more information see the [FastRoute Route Docs](https://github.com/nikic/FastRoute#defining-routes)

Any wildcards/placeholders defined here will be passed into the Controller/Handler method.

#### Handler String

[](#handler-string)

The handler string defines the class and method that should be executed should the current request match a route.

The required format is `\MyApp\Users@list` where `\MyApp\Users` is the full class name including the namespace, and `list` is the method inside of that class which you want to be executed.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

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

Total

2

Last Release

3623d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/de2053f4238374bd541fc3fc5711e331c91f3279f7a332ee1c3f3db13a1829d1?d=identicon)[TomWright](/maintainers/TomWright)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[typo3/testing-framework

The TYPO3 testing framework provides base classes for unit, functional and acceptance testing.

675.0M775](/packages/typo3-testing-framework)[workerman/webman-framework

High performance HTTP Service Framework.

149314.9k256](/packages/workerman-webman-framework)[webmozarts/strict-phpunit

Enables type-safe comparisons of objects in PHPUnit

31252.7k5](/packages/webmozarts-strict-phpunit)

PHPackages © 2026

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