PHPackages                             richardandrade/php\_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. richardandrade/php\_router

ActiveLibrary[Framework](/categories/framework)

richardandrade/php\_router
==========================

A simple router for managing your app routes

07PHP

Since Jun 30Pushed 2y ago1 watchersCompare

[ Source](https://github.com/richardandradeb/php_router)[ Packagist](https://packagist.org/packages/richardandrade/php_router)[ RSS](/packages/richardandrade-php-router/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

php\_router
===========

[](#php_router)

Simple php router library for managing your APIs/Apps routes.

This library is only meant for study purposes or small projects.

How to install it
=================

[](#how-to-install-it)

```
composer require richardandrade/php_router

```

How to use it
=============

[](#how-to-use-it)

1. In your Front Controller, you'll need to instanciate the Router Class with your source (or app) namespace as a param:

```
use RichardAndrade\PhpRouter;

$router = new Router('app\example\\');

```

2. After initializing the class you'll then need to define your application routes, I recommend creating a new file like 'routes.php' and then including it in your Front Controller:

```
include_once('routes.php');

```

```
//in 'routes.php' file

$router->setRoute([
      'path' => '/home', //Route path
      'methods' => ['GET'], //Here you'll need to define the allowed HTTP Methods as an array (e.g ['GET','POST','PUT'])
      'controller' => 'MyController' //The name of the controller responsible for this route
]);

```

3. Finally, after defining your routes and including the file in the Front Controller, call the following method to start the router:

```
$router->run();

```

The final result (index file) should be something like:

```
use RichardAndrade\PhpRouter;

$router = new Router('app\example\\');

include_once('routes.php');

$router->run();

```

Defining dynamic routes
=======================

[](#defining-dynamic-routes)

With this library you'll also be able to define dynamic routes. With this type of route your application will receive any params that you defined in the request URI.

```
//routes such as 'myapp.com/article/1', where '1' could be the article ID, can be configured as shown bellow

$router->setRoute([
      'path' => '/article/{id}', //in this case I used 'id', this will be the key name for the 'params' associative array
      'methods' => ['GET'],
      'controller' => 'ArticlesController'
]);

//after that, your controller will be able to receive the defined params

class ArticlesController {
  public funtion __construct(array $params)
  {
  }
}

//the 'params' variable will provide, in this example, ['id' => '1']

```

extra: setting headers
======================

[](#extra-setting-headers)

This library also provides a simple way to define the response headers inside your controllers:

```
use RichardAndrade\PhpRouter;

class ArticlesController {
    public function example()
    {
        Router::setHeaders([
              'Content-type' => 'application/xml',
              'Access-Control-Allow-Origin' => 'https://myapp.com'
        ]);
    }
}

```

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity22

Early-stage or recently created project

 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/285293c407ea76fc877c713abf40d33e3e0485503227a72e60ab13a39120d084?d=identicon)[richardandradeb](/maintainers/richardandradeb)

---

Top Contributors

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

### Embed Badge

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

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

###  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)
