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

ActiveLibrary[Framework](/categories/framework)

fyre/router
===========

A URL routing library.

v8.0.3(9mo ago)0248↓77.8%4MITPHP

Since Dec 26Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/elusivecodes/FyreRouter)[ Packagist](https://packagist.org/packages/fyre/router)[ RSS](/packages/fyre-router/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (10)Dependencies (10)Versions (54)Used By (4)

FyreRouter
==========

[](#fyrerouter)

**FyreRouter** is a free, open-source URI routing library for *PHP*.

Table Of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Basic Usage](#basic-usage)
- [Methods](#methods)
- [Routes](#routes)
    - [Closure](#closure)
    - [Controller](#controller)
    - [Redirect](#redirect)
- [Middleware](#middleware)
    - [Substitute Bindings](#substitute-bindings)

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

[](#installation)

**Using Composer**

```
composer require fyre/router

```

In PHP:

```
use Fyre\Router\Router;
```

Basic Usage
-----------

[](#basic-usage)

- `$container` is a [*Container*](https://github.com/elusivecodes/FyreContainer).
- `$modelRegistry` is a [*ModelRegistry*](https://github.com/elusivecodes/FyreORM).
- `$config` is a [*Config*](https://github.com/elusivecodes/FyreConfig).

```
$router = new Router($container, $modelRegistry, $config);
```

The base URI will be resolved from the "*App.baseUri*" key in the [*Config*](https://github.com/elusivecodes/FyreConfig).

**Autoloading**

It is recommended to bind the *Router* to the [*Container*](https://github.com/elusivecodes/FyreContainer) as a singleton.

```
$container->singleton(Router::class);
```

Any dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).

```
$router = $container->use(Router::class);
```

Methods
-------

[](#methods)

**Clear**

Clear all routes and aliases.

```
$router->clear();
```

**Connect**

Connect a route.

- `$path` is a string representing the route path, and can include placeholders (that will be passed to the destination).
- `$destination` can be either a string representing the destination, an array containing the class name and method or a *Closure*.
- `$options` is an array containing configuration options.
    - `as` is a string representing the route alias, and will default to *null*.
    - `middleware` is an array of middleware to be applied to the route, and will default to *\[\]*.
    - `method` is an array of strings representing the matching methods, and will default to *\[\]*.
    - `placeholders` is an array of regular expression placeholders, and will default to *\[\]*.
    - `redirect` is a boolean indicating whether the route is a redirect, and will default to *false*.

```
$route = $router->connect($path, $destination, $options);
```

You can generate the following helper methods to connect specific routes.

```
$router->delete($path, $destination, $options);
$router->get($path, $destination, $options);
$router->patch($path, $destination, $options);
$router->post($path, $destination, $options);
$router->put($path, $destination, $options);
$router->redirect($path, $destination, $options);
```

See the [Routes](#routes) section for supported path and destination formats.

You can also pass additional arguments to the middleware by appending a colon followed by a comma-separated list of arguments to the alias string. You can use route placeholders as arguments by referencing the route placeholder surrounded by curly braces.

```
$router->get('test/{id}', 'test', ['middleware' => 'alias:test,{id}']);
```

**Get Base Uri**

Get the base uri.

```
$baseUri = $router->getBaseUri();
```

**Group**

Create a group of routes.

- `$options` is an array containing the group options.
    - `prefix` is a string representing the route group path prefix, and will default to *null*.
    - `as` is a string representing the route group alias prefix, and will default to *null*.
    - `middleware` is an array of middleware to be applied to the route group, and will default to *\[\]*.
    - `placeholders` is an array of regular expression placeholders, and will default to *\[\]*.
- `$callback` is a *Closure* with the *Router* as the first argument.

```
$router->group($options, $callback);
```

**Load Route**

Load a route.

- `$request` is a [*ServerRequest*](https://github.com/elusivecodes/FyreServer#server-requests).

```
$request = $router->loadRoute($request);
```

This method will return a [*ServerRequest*](https://github.com/elusivecodes/FyreServer#server-requests), with the `route` parameter set to the loaded route.

**Url**

Generate a URL for a named route.

- `$name` is a string representing the route alias.
- `$arguments` is an array containing the route arguments, where the key is the placeholder name.
    - `?` is an array containing route query parameters.
    - `#` is a string representing the fragment component of the URI.
- `$options` is an array containing the route options.
    - `fullBase` is a boolean indicating whether to use the full base URI and will default to *false*.

```
$url = $router->url($name, $arguments, $options)
```

Routes
------

[](#routes)

All routes extend the `Fyre\Router\Route` class, and include the following methods.

**Check Route**

Check if the route matches a test method and path.

- `$method` is a string representing the method to test.
- `$path` is a string representing the path to test.

```
$checkRoute = $route->checkRoute($method, $pth);
```

**Get Arguments**

Get the route arguments.

```
$arguments = $route->getArguments();
```

**Get Binding Fields**

Get the route binding fields.

```
$bindingFields = $route->getBindingFields();
```

**Get Destination**

Get the route destination.

```
$destination = $route->getDestination();
```

**Get Middleware**

Get the route middleware.

```
$middleware = $route->getMiddleware();
```

**Get Path**

Get the route path.

```
$path = $route->getPath();
```

**Get Placeholders**

Get the route placeholders.

```
$placeholders = $route->getPlaceholders();
```

**Handle**

Handle the route.

- `$request` is a [*ServerRequest*](https://github.com/elusivecodes/FyreServer#server-requests).
- `$response` is a [*ClientResponse*](https://github.com/elusivecodes/FyreServer#client-responses).

```
$response = $route->handle($request, $response);
```

This method will return a [*ClientResponse*](https://github.com/elusivecodes/FyreServer#client-responses).

**Set Middleware**

Set the route middleware.

- `$middleware` is an array containing the route middleware.

```
$route->setMiddleware($middleware);
```

**Set Placeholder**

Set a route placeholder.

- `$placeholder` is a string representing the route placeholder.
- `$regex` is a string representing the placeholder regular expression.

```
$route->setPlaceholder($placeholder, $regex);
```

### Closure

[](#closure)

```
use Fyre\Router\Routes\ClosureRoute;
```

- `$container` is a [*Container*](https://github.com/elusivecodes/FyreContainer).
- `$destination` is a *Closure*.
- `$path` is a string representing the route path, and will default to "".
- `$options` is an array containing route options.
    - `middleware` is an array of middleware to be applied to the route, and will default to *\[\]*.
    - `method` is an array of strings representing the matching methods, and will default to *\[\]*.
    - `placeholders` is an array of regular expression placeholders, and will default to *\[\]*.

```
$route = new ClosureRoute($container, $destination, $path, $options);
```

The `$path` and `$destination` can be expressed in the following formats:

```
$router->get('posts', function(): string {
    return view('Posts.index');
});

$router->get('posts/{post}', function(Post $post): string {
    return view('Posts.view', ['post' => $post]);
});
```

Route parameter entity binding is handled by the [Substitute Bindings](#substitute-bindings) middleware.

### Controller

[](#controller)

```
use Fyre\Router\Routes\ControllerRoute;
```

- `$container` is a [*Container*](https://github.com/elusivecodes/FyreContainer).
- `$destination` is an array containing the controller class name and method.
- `$path` is a string representing the route path, and will default to "".
- `$options` is an array containing route options.
    - `middleware` is an array of middleware to be applied to the route, and will default to *\[\]*.
    - `method` is an array of strings representing the matching methods, and will default to *\[\]*.
    - `placeholders` is an array of regular expression placeholders, and will default to *\[\]*.

```
$route = new ControllerRoute($container, $destination, $path, $options);
```

The `$path` and `$destination` can be expressed in the following formats:

```
$router->get('posts', [Posts::class]); // defaults to index method
$router->get('posts/{post}', [Posts::class, 'view']);
```

Route parameter entity binding is handled by the [Substitute Bindings](#substitute-bindings) middleware.

**Get Action**

Get the route controller action.

```
$action = $route->getAction();
```

**Get Controller**

Get the route controller class name.

```
$controller = $route->getController();
```

### Redirect

[](#redirect)

```
use Fyre\Router\Routes\RedirectRoute;
```

- `$container` is a [*Container*](https://github.com/elusivecodes/FyreContainer).
- `$destination` is a string representing the destination.
- `$path` is a string representing the route path, and will default to "".
- `$options` is an array containing route options.
    - `middleware` is an array of middleware to be applied to the route, and will default to *\[\]*.
    - `method` is an array of strings representing the matching methods, and will default to *\[\]*.
    - `placeholders` is an array of regular expression placeholders, and will default to *\[\]*.

```
$route = new RedirectRoute($container, $destination, $path, $options);
```

The `$path` and `$destination` can be expressed in the following formats:

```
$router->redirect('test', 'https://test.com/');
$router->redirect('test/{id}', 'https://test.com/{id}');
```

Middleware
----------

[](#middleware)

```
use Fyre\Router\Middleware\RouterMiddleware;
```

- `$container` is a [*Container*](https://github.com/elusivecodes/FyreContainer).
- `$middlewareRegistry` is a [*MiddlewareRegistry*](https://github.com/elusivecodes/FyreMiddleware).
- `$router` is a *Router*.

```
$middleware = new RouterMiddleware($container, $middlewareRegistry, $router);
```

Any dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).

```
$middleware = $container->use(RouterMiddleware::class);
```

**Handle**

Handle a [*ServerRequest*](https://github.com/elusivecodes/FyreServer#server-requests).

- `$request` is a [*ServerRequest*](https://github.com/elusivecodes/FyreServer#server-requests).
- `$next` is a *Closure*.

```
$response = $middleware->handle($request, $next);
```

This method will return a [*ClientResponse*](https://github.com/elusivecodes/FyreServer#client-responses).

### Substitute Bindings

[](#substitute-bindings)

```
use Fyre\Router\Middleware\SubstituteBindingsMiddleware;
```

This middleware will automatically resolve entities from route placeholders based on the parameter types of the route destination.

- `$container` is a [*Container*](https://github.com/elusivecodes/FyreContainer).
- `$middlewareRegistry` is a [*MiddlewareRegistry*](https://github.com/elusivecodes/FyreMiddleware).
- `$entityLocator` is an [*EntityLocator*](https://github.com/elusivecodes/FyreEntity).

```
$middleware = new SubstituteBindingsMiddleware($container, $middlewareRegistry, $entityLocator);
```

Any dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).

```
$middleware = $container->use(SubstituteBindingsMiddleware::class);
```

**Handle**

Handle a [*ServerRequest*](https://github.com/elusivecodes/FyreServer#server-requests).

- `$request` is a [*ServerRequest*](https://github.com/elusivecodes/FyreServer#server-requests).
- `$next` is a *Closure*.

```
$response = $middleware->handle($request, $next);
```

This method will return a [*ClientResponse*](https://github.com/elusivecodes/FyreServer#client-responses).

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance58

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity63

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

Recently: every ~20 days

Total

53

Last Release

276d ago

Major Versions

v3.0.1 → v4.02023-08-09

v4.0.5 → v5.02024-06-07

v5.2.0 → v6.02024-10-11

v6.1.0 → v7.02024-11-27

v7.1.11 → v8.02025-07-03

### Community

Maintainers

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

---

Top Contributors

[![elusivecodes](https://avatars.githubusercontent.com/u/18050480?v=4)](https://github.com/elusivecodes "elusivecodes (44 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[pinguo/php-msf

Pinguo Micro Service Framework For PHP

1.7k4.2k](/packages/pinguo-php-msf)[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)
