PHPackages                             igorcrevar/icrouter - 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. igorcrevar/icrouter

ActiveLibrary[Framework](/categories/framework)

igorcrevar/icrouter
===================

Different approach for standard routing problem. Matching tree based.

05PHP

Since Apr 16Pushed 11y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

\#icRouter Different approach for standard routing problem. Instead of using regular expressions, matching tree is built.

This library will not work with older versions of PHP. Minimal version is 5.3

Usage
-----

[](#usage)

#### Usings

[](#usings)

```
use IgorCrevar\icRouter\Router;
use IgorCrevar\icRouter\Route;
use IgorCrevar\icRouter\Interfaces\DefImpl\DefaultNodeBuilder;
```

#### Create router

[](#create-router)

```
$router = new Router(new DefaultNodeBuilder());
```

#### Add some routes

[](#add-some-routes)

```
$router->setRoutes([
    new Route('simple', '/simple',
              array('module' => 'simple')),
    new Route('simple_param', '/param/:a',
              array('module' => 'simple_param', 'a' => 10),
              array('a' => '\d+')), // a is integer
    new Route('two_params', '/param/hello/:a/some/:b',
              array('module' => 'two_params', 'a' => 10, 'onemore' => 'time')),
    new Route('two_params_any', '/home/hello/:a/:b/*',
              array('module' => 'two_params_any', 'a' => 10, 'b' => '10'),
              array('b' => '[01]+')), // b is string / number of 0' and 1'
    new Route('complex_param', '/complex/id_:id',
              array('module' => 'complex_param'),
              array('id' => '\d+')),
    new Route('home', '/*',
              array('module' => 'home')),
]);
```

#### Build route tree

[](#build-route-tree)

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

#### Match

[](#match)

```
$result = $router->match('/a/b/c/d/e');
```

$result will be array of matching parameters (key value pairs) if route exists otherwise false is returned

#### Generate

[](#generate)

```
$result = $router->generate('two_params', array('b' => 'aabb'));
```

First parameter is route name, second is parameters (key value pairs) array

#### Route constructor parameters

[](#route-constructor-parameters)

- name of route
- patterns: Examples:
    1. /acount/:id/\* - provides functionality for additional parameters
    2. /account/:id/:action
    3. /account/id\_:id Parameter is specified with /:\[A-Za-z0-9\]+/ Only one parameter is allowed per route segment
- optional default parameters for route (key - value pairs)
- optional regex for parameters in pattern Examples:
    1. array('id' =&gt; '\\d+') - id is integer
    2. array('type' =&gt; 'car|boat|plane') - type is either car or boat or plane

Tip
---

[](#tip)

For production, because $router-&gt;build() is expensive you should cache already built router (APC, serializing, etc...)

Unit Testing
------------

[](#unit-testing)

Go to base dir and execute:

```
phpunit test/RouterTest.php

```

TODO
----

[](#todo)

perfomance banchmark beetween this library and some
regular expression routing library like one from symfony framework or similar.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

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/ec9cfc0b3879322cbfc088c50b8f337e90b34f76b4c50963a17ad03475dcc234?d=identicon)[igorcrevar](/maintainers/igorcrevar)

---

Top Contributors

[![igorcrevar](https://avatars.githubusercontent.com/u/729576?v=4)](https://github.com/igorcrevar "igorcrevar (6 commits)")

### Embed Badge

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

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

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M192](/packages/laravel-telescope)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

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

1.9k36.7M259](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M596](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)

PHPackages © 2026

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