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

ActiveLibrary[Framework](/categories/framework)

ecfectus/router
===============

PHP 7 Router implementation on top of fast route

121PHP

Since Nov 24Pushed 9y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Ecfectus Router
===============

[](#ecfectus-router)

[![Build Status](https://camo.githubusercontent.com/3cfc1a66bcfb067d45eb77f033ef6277193e45ec0c237d6e7abf25b1e6563f27/68747470733a2f2f7472617669732d63692e6f72672f65636665637475732f726f757465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ecfectus/router)

PHP 7 Router implementation.

The ecfectus router is a lean, fast and cachable PHP router with no dependencies.

The router has been made lean by not needing any knowledge of a request, it is quite simply a pattern matcher, which matches a path pattern against a route.

Usage
-----

[](#usage)

```
$router = new \Ecfectus\Router\Router();

/**
 * Basic Requests
 */

//get requests
$router->get('/url')
    ->setHandler('Class@method');

//post requests
$router->post('/url')
    ->setHandler('Class@method');

//put requests
$router->put('/url')
    ->setHandler('Class@method');

//patch requests
$router->patch('/url')
    ->setHandler('Class@method');

//delete requests
$router->delete('/url')
    ->setHandler('Class@method');

/**
 * Route Params
 */

//args and optional args
$router->get('/url/{arg}/{optionalarg?}')
    ->setHandler('Class@method');

//only matches number
$router->get('/url/{arg:number}')
    ->setHandler('Class@method');

//only matches words
$router->get('/url/{arg:word}')
    ->setHandler('Class@method');

//only matches alpha numeric + dashs
$router->get('/url/{arg:alphanumdash}')
    ->setHandler('Class@method');

//only matches slugs
$router->get('/url/{arg:slug}')
    ->setHandler('Class@method');

//only matches uuids
$router->get('/url/{arg:uuid}')
    ->setHandler('Class@method');

/**
 * Named Routes
 */

$router->get('/url')
    ->setName('routename')
    ->setHandler('Class@method');

/**
 * Domain Routes
 */

$router->get('/url')
    ->setDomain('domain.com')
    ->setHandler('Class@method');

// domain placeholders
$router->get('/url')
    ->setDomain('{subdomain}.domain.com')
    ->setHandler('Class@method');

/**
 * Grouped routes
 */

$router->group([
        'path' => '/api',
        'name' => 'api',
        'domain' => 'domain.com'
    ], function($r){

        $r->get('/users') // becomes domain.com/api/users
            ->setName('users') // becomes api.users
            ->setHandler('Class@method');

        //groups can be nested
    });

/**
 * Prepare Router before matching
 */
try{
    $router->prepare();
}catch( Exception $e){

}

/**
 * Match routes
 */
try{

    $route = $router->match('hello.domain.com/url', 'GET'); // $path, $method = 'GET|POST|PUT|PATCH|DELETE'

    $values = $route->getValues(); // ['subdomain' => 'hello']

}catch( \Ecfectus\Router\NotFoundException $e){
    //no route matched
}catch( \Ecfectus\Router\MethodNotAllowedException $e){
    //route matched but method not allowed
}catch( \Exception $e){

}
```

Cached Router
-------------

[](#cached-router)

By using the cached router you can export the compiled router and restore the instance from a file, bypassing the compile process and increasing performance.

```
$router = \Ecfectus\Router\CachedRouter::create('routes.php');

if(!$router->isCached()){

    //add routes here

    try{
        //prepare and export the router to the file.
        $router->prepare();
        $router->export();
    }catch( Exception $e){

    }
}

try{

    $route = $router->match('hello.domain.com/url', 'GET'); // $path, $method = 'GET|POST|PUT|PATCH|DELETE'

    $values = $route->getValues(); // ['subdomain' => 'hello']

}catch( \Ecfectus\Router\NotFoundException $e){
    //no route matched
}catch( \Ecfectus\Router\MethodNotAllowedException $e){
    //route matched but method not allowed
}catch( \Exception $e){

}
```

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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/0b8fdb3cf22dac46100ad95eddb94f98b2a7a5002b29c4d2f812113f2867ff35?d=identicon)[leemason](/maintainers/leemason)

---

Top Contributors

[![leemason](https://avatars.githubusercontent.com/u/1238646?v=4)](https://github.com/leemason "leemason (22 commits)")

### Embed Badge

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

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

###  Alternatives

[laravel/dusk

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

1.9k39.6M290](/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)
