PHPackages                             easyroute/easyroute - 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. easyroute/easyroute

ActiveLibrary

easyroute/easyroute
===================

Fast, fully featured restful request router for PHP

v1.0.1(9y ago)238MITPHPPHP &gt;=5.5.0

Since Apr 7Pushed 9y ago2 watchersCompare

[ Source](https://github.com/alfonsmartinez/EasyRoute)[ Packagist](https://packagist.org/packages/easyroute/easyroute)[ Docs](https://github.com/alfonsmartinez/EasyRoute)[ RSS](/packages/easyroute-easyroute/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

EasyRoute - Fast request router for PHP
=======================================

[](#easyroute---fast-request-router-for-php)

[![Build Status](https://camo.githubusercontent.com/4cd90bfaa24dc4813337dcd6dceba4daead3406067b002ef497b923bcd1447f7/68747470733a2f2f6170692e7472617669732d63692e6f72672f616c666f6e736d617274696e657a2f45617379526f7574652e706e67)](http://travis-ci.org/alfonsmartinez/EasyRoute)[![Packagist](https://camo.githubusercontent.com/b0b2036987a70e49410be8ead691eadbf073a948a28b55bd6270310a58ac4839/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f65617379726f7574652f65617379726f7574652e7376673f6d61784167653d32353932303030)](https://packagist.org/packages/easyroute/easyroute)[![license](https://camo.githubusercontent.com/ee061e6c1798bd95fa104c910010a3119850b186c323a1c848b3abcb029dc764/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d6173686170652f6170697374617475732e7376673f6d61784167653d32353932303030)](#license)

Simple and extremely flexible PHP router class, with support for route parameters, restful, filters and reverse routing.
------------------------------------------------------------------------------------------------------------------------

[](#simple-and-extremely-flexible-php-router-class-with-support-for-route-parameters-restful-filters-and-reverse-routing)

Getting started
---------------

[](#getting-started)

You need PHP &gt;= 5.5 to use EasyRoute.

- [Install EasyRoute](#install)
- [Rewrite all requests to EasyRoute](#rewrite-requests)
- [Map your routes](#map-your-routes)
- [Match requests](#match-requests)

Install
-------

[](#install)

### System Requirements

[](#system-requirements)

You need PHP &gt;= 5.5.0 to use EasyRoute\\EasyRoute but the latest stable version of PHP is recommended.

### Composer

[](#composer)

EasyRoute is available on Packagist and can be installed using Composer:

```
composer require easyroute/easyroute

```

### Manually

[](#manually)

You may use your own autoloader as long as it follows PSR-0 or PSR-4 standards. Just put src directory contents in your vendor directory.

Rewrite requests
----------------

[](#rewrite-requests)

To use EasyRoute, you will need to rewrite all requests to a single file. There are various ways to go about this, but here are examples for Apache and Nginx.

### Apache .htaccess

[](#apache-htaccess)

```
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)$ index.php [NC,L]

```

### Nginx nginx.conf

[](#nginx-nginxconf)

```
server {
    listen 80;
    server_name mydevsite.dev;
    root /var/www/mydevsite/public;

    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        # With php5-fpm:
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
        fastcgi_intercept_errors on;
    }
}
```

Map your routes
---------------

[](#map-your-routes)

```
use EasyRoute\Router;

$router = new Router('/examples');

$router->filter('auth', function ($_requesturi) {
    //return 'hola auth';
    var_dump($_requesturi);
});

$router->get('/', function () {
    return 'hello world';
});

$router->get('/part/', function () {
    return 'hello world part';
})->setName('part');

$router->get('/part/{id:[0-9]+}/', function ($id) {
    return 'hello world part' . $id;
})->setName('partid');

$router->group(['before' => ['auth']], function (\EasyRoute\Router $router) {
    $router->get('/testbefore/', function () {
        return 'hello test before';
    });
});

$router->group(['prefix' => 'en'], function (\EasyRoute\Router $router) {

    $router->get('/', function () {
        return 'home with prefix en';
    })->setName('home');

});

$router->group(['prefix' => 'es'], function (\EasyRoute\Router $router) {

    $router->get('/', function () {
        return 'home with prefix es';
    })->setName('home');

    $router->group(['prefix' => 'admin'], function (Router $router) {
        $router->get('/', function () {
            return 'hola 2 prefix';
        })->setName('prefix2');
    });

});

$router->get('/home/', function () {
    return 'home without prefix';
})->setName('home');
```

Match requests
--------------

[](#match-requests)

```
$data = $router->getData();
$dispatcher = new \EasyRoute\Dispatcher($data);

$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();

try {
    echo $dispatcher->dispatchRequest($request->getMethod(), $request->getUri());
} catch (\EasyRoute\Exception\HttpRouteNotFoundException $e) {
    echo 'route not found';
} catch (\EasyRoute\Exception\HttpMethodNotAllowedException $e) {
    echo 'not method allowed';
} catch (\Exception $e) {
    echo 'error 500';
}
```

### Dispatch url

[](#dispatch-url)

```
$data = $router->getData();
$dispatcher = new \EasyRoute\Dispatcher($data);

$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();

echo $dispatcher->getUrlRequest('home', [], $request->getUri());
echo "\n";
echo $dispatcher->getUrlRequest('prefix2', [], $request->getUri());
echo "\n";
echo $dispatcher->getUrlRequest('partid', ['id' => 555], $request->getUri();
echo "\n";
```

TODO
----

[](#todo)

```
- add requestinterface optional (guzzle / psr7)
- default pregmatches
- add cache route collection
- add cache dispatcher

```

LICENSE
-------

[](#license)

The MIT License (MIT)

Copyright (c) 2016 alfonsmartinez

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

28

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity61

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

Total

4

Last Release

3632d ago

Major Versions

v0.0.2 → v1.0.02016-04-13

PHP version history (2 changes)v0.0.1PHP &gt;=5.6.0

v1.0.0PHP &gt;=5.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/0b44ac88cad6953194ed25f12b71f2909e7ca74e16c5877c5d1ab985b20b1dfe?d=identicon)[alf](/maintainers/alf)

---

Top Contributors

[![alfonsmartinez](https://avatars.githubusercontent.com/u/1842985?v=4)](https://github.com/alfonsmartinez "alfonsmartinez (26 commits)")

---

Tags

routerrouting

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[symfony/routing

Maps an HTTP request to a set of configuration variables

7.6k775.6M1.6k](/packages/symfony-routing)[nikic/fast-route

Fast request router for PHP

5.3k90.8M623](/packages/nikic-fast-route)[klein/klein

A lightning fast router for PHP

2.7k1.1M29](/packages/klein-klein)[altorouter/altorouter

A lightning fast router for PHP

1.3k3.4M67](/packages/altorouter-altorouter)[bramus/router

A lightweight and simple object oriented PHP Router

1.1k446.1k46](/packages/bramus-router)[aura/router

Powerful, flexible web routing for PSR-7 requests.

5021.5M65](/packages/aura-router)

PHPackages © 2026

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