PHPackages                             redcatphp/route - 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. redcatphp/route

AbandonedArchivedLibrary[Framework](/categories/framework)

redcatphp/route
===============

Route - A mirco-framework for manage entry point of applications

v1.8.1(8y ago)38251LGPL-3.0+PHPPHP &gt;=5.4.0

Since Aug 20Pushed 7y ago2 watchersCompare

[ Source](https://github.com/redcatphp/route)[ Packagist](https://packagist.org/packages/redcatphp/route)[ Docs](http://redcatphp.com/route-url)[ RSS](/packages/redcatphp-route/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)DependenciesVersions (11)Used By (1)

**No longer actively maintained. I work now with NodeJS and I recommand you to take a look at [express](https://expressjs.com/)**

Route your application's requests
=================================

[](#route-your-applications-requests)

Route is a [micro-framework](https://en.wikipedia.org/wiki/Microframework) designed for manage requests with flexibility and simplicity.

FrontController
---------------

[](#frontcontroller)

This is a basic [front-controller](https://en.wikipedia.org/wiki/Front_Controller_pattern) class which you can extends to build the front map of your application. It's build with a router that will solve the request. Is implementing the [ArrayAccess](http://php.net/manual/en/class.arrayaccess.php) interface and *runFromGlobals* method which is used in the generic RedCat's *index.php*.
Extending:

```
class MyFrontOffice extends \\RedCat\\Route\\FrontOffice{
    function \_\_construct(Router $router,Di $di){
        parent::\_\_construct($router,$di);
        $this->map([
            ['backend/','new:RedCat\\Plugin\\FrontController\\Backoffice'],
            [['new:RedCat\\Route\\Match\\Extension','css|js|png|jpg|jpeg|gif'],'new:RedCat\\Plugin\\FrontController\\Synaptic'],
            [['new:RedCat\\Plugin\\RouteMatch\\ByTml'.($this->l10n?'L10n':''),'','template'],'new:RedCat\\Plugin\\Templix\\Templix'.($this->l10n?'L10n':'')],
        ]);
    }
    function run($path,$domain=null){
        if(!parent::run($path,$domain)){
            http\_response\_code(404);
            print "Page not found !";
            exit;
        }
        return true;
    }
}
            
```

And then, use it:

```
use RedCat\\Route\\Match\\Prefix;
use RedCat\\Route\\Match\\Suffix;
use RedCat\\Route\\Match\\Regex;
use RedCat\\Route\\Match\\Extension;

$f = new MyFrontOffice();
            
```

Append and prepend methods:

```
$this->append(new Prefix('test/'),function($path){
    print "My url start with 'test' followed by '$path'";
});
$this->prepend(new Prefix('test/more'),function($path){
    print "My url start with 'test/more' followed by '$path'";
});
$f->append(new Suffix('.stuff'),function($path){
    print "My url end with '.stuff' preceded by '$path'";
});
            
```

Z-index like api in third parameter (default is zero)
It will look first for ".stuff" matching, then "test/more", and finally "test/":

```
$this->append(new Prefix('test/'),function($path){
    print "My url start with 'test' followed by '$path'";
},2);
$this->prepend(new Prefix('test/more'),function($path){
    print "My url start with 'test/more' followed by '$path'";
},2);
$f->append(new Suffix('.stuff'),function($path){
    print "My url end with '.stuff' preceded by '$path'";
},1);
            
```

Parameters automatic wrap:

```
// test/more is a string, consequently it will be wrapped automaticaly by Prefix object
$this->prepend('test/more',function($path){
    print "My url start with 'test/more' followed by '$path'";
});

// string start with "/^" and end with "$/", consequently it will be wrapped automaticaly by Regex object
$this->append('/^blog/(\\w+)/(\\d+)$/',function($category, $id){
    // if url is blog/php/200 it will print "php:200"
    print $category.':'.$id;
});
            
```

Empty url handling:

```
$f->append('',function(){
    print 'You are on home page !';
});
            
```

Lazy loading *match*, array containing first element starting with "new:", the object will be instantiated only if is necessary (previous didn't match):

```
$f->append(['new:RedCat\\Route\\Match\\Suffix','.stuff'],function($path){
    print "My url end with '.stuff' preceded by '$path'";
});
            
```

Lazy loading *callback*, array containing first element or string starting with "new:", the object will be instantiated only if is necessary (matching):

```
// Class instanciation and method
$f->append('hello',[['new:MyModuleClass'],'methodName']);

// Class instanciation with construct params and method
$f->append('hello',[['new:MyModuleClass',$param1ForInstanciation,$param2ForInstanciation],'methodName']);

// Class instanciation and invokation
//   object will be invoked after instanciation using \_\_invoke magic method if exists
$f->append('hello','new:MyModuleClass');
            
```

Run

```
//manual url
$f->run('test/');

//automatic current url
$f->runFromGlobals();
            
```

Router
------

[](#router)

The router is the component which is used by *FrontController* to map, append and prepend pair of match to behaviour. It support the methods explained before in [*FrontController*](http://redcatphp.com/route#frontcontroller) except *runFromGlobals*.

Match
-----

[](#match)

The basic match components are distributed under the *RedCat\\Route\\Match* namespace but there is also some examples of specific match in the *RedCat\\Plugin\\RouteMatch* namespace. The only rule to make a *Match* object is that he have to be callable implementing \_\_invoke magic method. You can also use php [Closure](http://php.net/manual/en/class.closure.php) also called [anonymous function](http://php.net/manual/en/functions.anonymous.php).

Url
---

[](#url)

Url is a tiny helper for extract some simple components from Url.

```
$url = new Url;

\# http:// or https://
$url->getProtocolHref();

\# mydomain.com
$url->getServerHref();

\# output integer number of port if different from default (80 for http and 443 for https)
$url->getPortHref();

\# root-path-of-redcat/
$url->getSuffixHref();

\# http://mydomain.com/root-path-of-redcat/
$url->getBaseHref();

\# http://mydomain.com/root-path-of-redcat/current-path/
$url->getLocation();

\# http://mydomain.com/root-path-of-redcat/
$url->getSubdomainHref();

\# http://fr.mydomain.com/root-path-of-redcat/
$url->getSubdomainHref('fr');

\# if current subdomain contain 2 character it will output them
$url->getSubdomainLang();
            
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity64

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

Recently: every ~153 days

Total

10

Last Release

2967d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/085e64547ac1b32cc49f4f6ba5950c35f593f79d8523e2379869ab512eb8a725?d=identicon)[surikat](/maintainers/surikat)

---

Top Contributors

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

---

Tags

routedispatcherfront controllerMirco Framework

### Embed Badge

![Health badge](/badges/redcatphp-route/health.svg)

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

###  Alternatives

[pecee/simple-router

Simple, fast PHP router that is easy to get integrated and in almost any project. Heavily inspired by the Laravel router.

696214.6k17](/packages/pecee-simple-router)[izniburak/router

simple router class for php

23522.6k7](/packages/izniburak-router)[lesichkovm/laravel-advanced-route

Advanced route class for Laravel - restoring implicit controllers to the framework.

70140.7k1](/packages/lesichkovm-laravel-advanced-route)[cakephp/event

CakePHP event dispatcher library that helps implementing the observer pattern

23319.7k13](/packages/cakephp-event)[yiisoft/middleware-dispatcher

PSR-15 middleware dispatcher

17369.2k13](/packages/yiisoft-middleware-dispatcher)[ecoal95/php-router

Minimal routing library

271.0k1](/packages/ecoal95-php-router)

PHPackages © 2026

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