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

ActivePackage

lefodeurcou/crazy-router
========================

A fast router with great possibilities

1.0.0(4y ago)45MITPHPPHP &gt;=8.0

Since May 31Pushed 4y ago3 watchersCompare

[ Source](https://github.com/LeFodeurCou/crazy-router)[ Packagist](https://packagist.org/packages/lefodeurcou/crazy-router)[ RSS](/packages/lefodeurcou-crazy-router/feed)WikiDiscussions master Synced 1mo ago

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

Crazy-Router
============

[](#crazy-router)

🐘 A php based router. Simple and fast.
--------------------------------------

[](#-a-php-based-router-simple-and-fast)

> Crazy-Router is just a router.

It is designed to be as simple as possible and as fast as possible too.

---

🔌 Installation
--------------

[](#-installation)

### Prerequisite

[](#prerequisite)

PHP &gt;= 8.0 Composer &gt;= 2.0

All requests must be redirected to your index.php (see Nginx or Apache configuration).

### Composer

[](#composer)

`composer init`

`composer require lefodeurcou/crazy-router`

---

💻 Usage
-------

[](#-usage)

### Features

[](#features)

#### Add how many routes you want

[](#add-how-many-routes-you-want)

```
public function addRoute(
		string $method,
		string $route,
		callable $callable,
		array $patterns = [],
		string $name = null
	)

```

> For the moment, this method is only a side effect method.

- **method** is http method represented by constants :
    - Crazy\\Router::GET
    - Crazy\\Router::POST
    - Crazy\\Router::PUT
    - Crazy\\Router::PATCH
    - Crazy\\Router::DELETE
- **route** is the path after the domain name like `/`, `/path` or `/path/for/the/truth`Routes can be parametrized like that : `/user/{id}` where `{id}` is an unknown value that can be getted back in callable (see below).
- **callable** is the function or the method that will be called if the route match the URL. Can be like :
    - `funtion($params) {}` or `function($params) use ($someVariable) {}`
    - `'functionName'`
    - `[$objectInstance, 'methodName']`The callable must take one parameter : `$params` that contain all unknown values from the parametrized route. To access these values you must use `$params` as associative array with keys that correspond to the route parameters, like that (see above at **route**): ```
         if (isset($params['id']))
         	echo $params['id'];

        ```
- **patterns** is an array that have to contain one pattern for each route parameter, like that : ```
     [
     	'[0-9]+',
     ]

    ```

    If there is more patterns than parameters, they will be ingored. If there is less patterns than parameters, route will be ignored. > In php you can have a comma for last input of an array. It's ok.
- **name** is a string that allow you to retrive the route if you crawl the routes array given by `getAllRoutes` method. It's the less usefull parameter for the moment, but in a next version it could be used to trigger the callable of a named route trougth an other route, by example.

#### Get all routes with ...

[](#get-all-routes-with-)

```
public function getAllRoutes()

```

Return an array that contains all route added earlier. Obviously 😎

#### Run, for a long time

[](#run-for-a-long-time)

```
public function run(callable $default = null)

```

Run the router, then it try to match a route with current URL. If it do, it run a corresponding callable. If it don't, it run `$default` callable if it's provided. That's all.

### Examples

[](#examples)

#### Simple boilerplate

[](#simple-boilerplate)

```

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

use Crazy\Router;

$router = new Crazy\Router();

$router->addRoute(Crazy\Router::GET, '/', function () {echo 'Example';});

$router->run();

```

#### With function declared before, and one parameter

[](#with-function-declared-before-and-one-parameter)

```

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

use Crazy\Router;

$router = new Crazy\Router();

function example ($params)
{
	if (isset($params['id']))
    	echo $params['id'];
}

$router->addRoute(Crazy\Router::GET, '/user/{id}', 'example', [
	'[0-9]+',
]);

$router->run();

```

#### With a method from a class

[](#with-a-method-from-a-class)

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

use Crazy\Router;

$router = new Crazy\Router();

class demo
{
	public function example() {
		echo 'Example';
	}
}

$router->addRoute(Crazy\Router::GET, '/', [new demo(), 'example'], [], 'Demo route');

$router->run();

```

---

🔧 Devlopment
------------

[](#-devlopment)

Unix environment is recommended and more again a linux distribution.

There is two bash script for units tests and benchmarks tests.

Except these, you can use what you want.

### Units Tests

[](#units-tests)

It use PHPUnit for it.

There is a bash script `unit` to launch tests.

### Benchmarks

[](#benchmarks)

It use PHPBench for it.

There is a bash script `bench` to launch tests.

🔐 License
---------

[](#-license)

MIT

---

📢 Last word
-----------

[](#-last-word)

Don't forget, be crazy 💥💥💥

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity56

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1803d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f44800343b4f9117eb5a847f84ee17bc5a9c4ead99f5fbf45569b2bd519bf9e7?d=identicon)[Le Fodeur Cou](/maintainers/Le%20Fodeur%20Cou)

---

Top Contributors

[![LeFodeurCou](https://avatars.githubusercontent.com/u/84274589?v=4)](https://github.com/LeFodeurCou "LeFodeurCou (22 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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