PHPackages                             terrydjony/routeria - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. terrydjony/routeria

ActiveLibrary[HTTP &amp; Networking](/categories/http)

terrydjony/routeria
===================

A simple fast yet powerful PHP router

2.0.0(9y ago)018MITPHPPHP &gt;=5.3

Since Jul 6Pushed 9y ago1 watchersCompare

[ Source](https://github.com/terryds/routeria)[ Packagist](https://packagist.org/packages/terrydjony/routeria)[ RSS](/packages/terrydjony-routeria/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

Routeria
========

[](#routeria)

Routeria is a lightweight and easy-to-use routing component.

Installing
----------

[](#installing)

Routeria installation using Composer

```
composer require terrydjony/routeria ~2.0

```

Usage
-----

[](#usage)

The installed Routeria and all of the components is in the `vendor` folder.
In order to use it, you just need to require the autoload.
And, you need to load the namespace using `use` keyword.

```
require_once __DIR__ . '/vendor/autoload.php';
```

### Configuration (.htaccess)

[](#configuration-htaccess)

Before using Routeria, you need to turn your rewrite engine on and add rules so any requests to non-existing directory or filename will be rewritten to index.php.

```
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

```

### Simple Callback Routing

[](#simple-callback-routing)

For a simple callback route, you just need to use `Routeria` class which belongs to the `Routeria` namespace.
The Request component of Symfony HttpFoundation is required to tell the request path to the router.

```
use Symfony\Component\HttpFoundation\Request;
use Routeria\Routeria;

$request = Request::createFromGlobals();
$router = new Routeria;
$router->get('/', function() { echo 'Hello World';});

$router->route($request->getPathInfo(), $request->getMethod());
```

Don't forget to write line `->route($request->getPathInfo(), $request->getMethod());` to make it work

### Using Named Parameters

[](#using-named-parameters)

```
use Symfony\Component\HttpFoundation\Request;
use Routeria\Routeria;

$request = Request::createFromGlobals();
$router = new Routeria;
$callback = function($fname, $lname) {
  echo "Hello $fname $lname. Nice to meet ya!";
};
$router->get('/greet/{fname:alpha}/{lname:alpha}', $callback);

$router->route($request->getPathInfo(), $request->getMethod());
```

The order of parameters in the callback doesn't matter.
You just need to specify all the necessary variables.

There are six placeholders available,
`INT` for integers (regex: \[0-9\]+)
`ALPHA` for alphabets (regex: \[a-zA-Z\_-\]+)
`ALNUM` for alphanumeric characters (regex: \[a-zA-Z0-9\_-\]+)
`HEX` for hexadecimals (regex: \[0-9A-F\]+)
`ALL` for all characters (regex: .+)
`WORD` is an alias for `ALPHA`

### Routing with specific HTTP Method

[](#routing-with-specific-http-method)

You can also perform other http methods routing easily. (even the custom one)

```
use Symfony\Component\HttpFoundation\Request;
use Routeria\Routeria;

$request = Request::createFromGlobals();
$router = new Routeria;
$router->get('/', function() { echo 'HTTP METHOD : GET';});
$router->post('/', function() { echo 'HTTP METHOD : POST';});
$router->put('/', function() { echo 'HTTP METHOD : PUT';});
$router->delete('/', function() { echo 'HTTP METHOD : DELETE';});
$router->add('/', function() { echo 'HTTP METHOD : CUSTOM';}, 'CUSTOM');

$router->route($request->getPathInfo(), $request->getMethod());
```

Different method, different route.

### Dispatch Controller

[](#dispatch-controller)

You can also dispatch a controller using Routeria.

```
use Symfony\Component\HttpFoundation\Request;
use Routeria\Routeria;

class User {
  public function getInfo($id, $name) {
    echo 'Hello ' . $name . ' ID: ' . $id;
  }
}

$request = Request::createFromGlobals();
$router = new Routeria;
$router->get('/user/{name:alpha}/{id:int}', 'User::getInfo');
$router->route($request->getPathInfo(), $request->getMethod());
```

If you go to '/user/terry/35', the router will dispatch the getInfo method so it prints 'Hello terry ID: 35'.
Don't forget to specify the namespace if the class has.

### Converting arguments

[](#converting-arguments)

```
use Symfony\Component\HttpFoundation\Request;
use Routeria\Routeria;

$request = Request::createFromGlobals();
$router = new Routeria;
$router->get('/posts/{title:alpha}', function($title) { echo ''.$title.'';})
    ->convert(function($title) {
      return ucwords(str_replace('-', ' ', $title));
    });
$router->route($request->getPathInfo(), $request->getMethod());
```

The converter in this example changes all hypens into spaces in the title argument.
So, if you go to '/posts/lorem-ipsum-dolor-sit-amet', it will print `lorem ipsum dolor sit amet`.
Notice that the argument 'lorem-ipsum-dolor-sit-amet' has been converted into 'lorem ipsum dolor sit amet' before the callback fires.

### Custom route collection

[](#custom-route-collection)

You can define your own route collection by implementing `RouteProviderInterface`.

```
use Symfony\Component\HttpFoundation\Request;
use Routeria\Routeria;
use Routeria\RouteCollection;
use Routeria\ControllerRoute;
use Routeria\RouteProviderInterface;

class BlogCollection implements RouteProviderInterface {
  public function register(RouteCollection $collection) {
    $blogRoutes = array(
      'index' => new ControllerRoute('/','Blog::index','GET'),
      'post' => new ControllerRoute('/{id:int}/{title:alnum}','Blog::showPost','GET'),
      'page' => new ControllerRoute('/page/{title:alpha}','Blog::showPage','GET')
      );

    $collection->addRoutes($blogRoutes);
  }
}

$request = Request::createFromGlobals();
$router = new Routeria;

$collection = new BlogCollection;
$router->register($collection);
$router->route($request->getPathInfo(), $request->getMethod());
```

You need your own blog controller to make it work.

Contribute to this library
--------------------------

[](#contribute-to-this-library)

Please contribute to this project by forking it, make good commits and then perform a pull request.
Thanks for your support.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 85.7% 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 ~315 days

Total

3

Last Release

3338d ago

Major Versions

1.x-dev → 2.0.02016-06-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/227af899f51765827a4a539ba2aa577d5167d46f0170a3bdb0e0f3d0806604e8?d=identicon)[terryds](/maintainers/terryds)

---

Top Contributors

[![littlepixel123](https://avatars.githubusercontent.com/u/185886589?v=4)](https://github.com/littlepixel123 "littlepixel123 (30 commits)")[![openclaw-instance001](https://avatars.githubusercontent.com/u/263087710?v=4)](https://github.com/openclaw-instance001 "openclaw-instance001 (4 commits)")[![terryds](https://avatars.githubusercontent.com/u/11571395?v=4)](https://github.com/terryds "terryds (1 commits)")

---

Tags

routerroutingURL Router

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[symfony/routing

Maps an HTTP request to a set of configuration variables

7.6k789.4M1.8k](/packages/symfony-routing)[nikic/fast-route

Fast request router for PHP

5.3k92.4M668](/packages/nikic-fast-route)[altorouter/altorouter

A lightning fast router for PHP

1.3k3.4M68](/packages/altorouter-altorouter)[aura/router

Powerful, flexible web routing for PSR-7 requests.

5231.5M67](/packages/aura-router)[aplus/routing

Aplus Framework Routing Library

2491.6M3](/packages/aplus-routing)[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)
