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

ActiveLibrary

bistro/router
=============

A route engine for PHP &gt;= 5.3

1.0.2(13y ago)149MITPHPPHP &gt;=5.3

Since Apr 30Pushed 13y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (4)Used By (0)

Bisro: Router
=============

[](#bisro-router)

A stand-alone routing engine for PHP &gt; = 5.3.

Installation
------------

[](#installation)

Packagist all the way!

```
"require": {
	"bistro/router": "1.0.*"
}
```

Of course you can always [download a zip](https://github.com/Bistro/Router/archive/master.zip)of the source on GitHub.

Creating Routes
---------------

[](#creating-routes)

```
$router = new \Bistro\Router\Router;
$router->add('home', '/')->defaults(array(
	'controller' => 'welcome',
	'action' => 'view'
));
```

Checking For Matches
--------------------

[](#checking-for-matches)

```
$method = $_SERVER['REQUEST_METHOD'];
$uri = isset($_SEVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/';

$params = $router->match($method, $uri);
// $params = array('controller' => 'welcome', 'action' => 'view');
```

If you get an empty array back from `match()` signifies that there were no matches to the request. Probably 404 time!

Named Route Segements
---------------------

[](#named-route-segements)

You can supply named segements for your routes with :{name}.

```
$router->add('crud', '/:controller/:action/:id?')->defaults(array(
	'id' => null
));
```

You can put a ? at the end of a named segment to make this segment optional.

Adding Constraints
------------------

[](#adding-constraints)

If you want to add constraints to a named segment you can put a valid regular expression before the `:`

```
$router->add('id_only', '/:controller/user|post:action/\d+:id');
```

In this route the action must be either user or post and the id is an integer.

Method Based Routes
-------------------

[](#method-based-routes)

Only want to pick up certain request methods? Just use the helper methods

```
$router->post('login', '/login')->defaults(array('controller' => 'login', 'action' => 'process'));
```

The available helper methods are `get`, `post`, `put` and `delete`.

Wildcard
--------

[](#wildcard)

Want to pick up everything at the end of a url? Easy!

```
$router->add('wildcard', '/:controller/.*:wildcard')
```

Adding Request Method Defaults
------------------------------

[](#adding-request-method-defaults)

Building an api and want to add in different parameters for each request method?

```
$router->add('api', "/:controller/\d+:id?")
	->get(array('action' => 'read'))
	->post(array('action' => 'create'))
	->put(array('action' => 'update'))
	->delete(array('action' => 'delete'));
```

Reverse Routing
---------------

[](#reverse-routing)

Keep track of your urls in a sane matter with the built in reverse routing functionality.

Seriously... don't hand type urls into your application! This is much easier and allows for greater flexibility.

```
$router->add('reverse', '/blog/:year/:month/:day');

// Reverse Routing magic!
echo $router->url('reverse', array(
	'year' => 2013,
	'month' => 03,
	'day' => 31
));
// Output: /blog/2013/03/31
```

Sub-Directory Installation?
---------------------------

[](#sub-directory-installation)

If you have installed your app in a subdirectory you can add that information into the router and everything will still work as adverstised.

```
$router = new \Bistro\Router\Router('subdirectory');
```

License
-------

[](#license)

MIT

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

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

3

Last Release

4762d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/46fa0decb95ad8d80b65e1fbed54f3fa9ee6350f1c8a0f83335221a201effb59?d=identicon)[davewid](/maintainers/davewid)

---

Top Contributors

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

---

Tags

routesrouterroutingroute

### Embed Badge

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

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

###  Alternatives

[aura/router

Powerful, flexible web routing for PSR-7 requests.

5231.5M67](/packages/aura-router)[pecee/simple-router

Simple, fast PHP router that is easy to get integrated and in almost any project. Heavily inspired by the Laravel router.

696214.6k17](/packages/pecee-simple-router)[contributte/api-router

RESTful Router for your Apis in Nette Framework - created either directly or via attributes

20802.8k3](/packages/contributte-api-router)[coffeecode/router

A classic CoffeeCode Router is easy, fast and extremely uncomplicated. Create and manage your routes in minutes!

181111.1k5](/packages/coffeecode-router)[pmjones/auto-route

Automatically routes HTTP request to action classes.

20158.6k6](/packages/pmjones-auto-route)[miladrahimi/phprouter

A powerful, lightweight, and very fast HTTP URL router for PHP projects.

20832.6k2](/packages/miladrahimi-phprouter)

PHPackages © 2026

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