PHPackages                             greg-md/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. greg-md/php-router

ActiveLibrary[Framework](/categories/framework)

greg-md/php-router
==================

A powerful routing for PHP.

14222[1 PRs](https://github.com/greg-md/php-router/pulls)PHPCI failing

Since Jul 23Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/greg-md/php-router)[ Packagist](https://packagist.org/packages/greg-md/php-router)[ RSS](/packages/greg-md-php-router/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (2)Used By (0)

Greg PHP Routing
================

[](#greg-php-routing)

[![StyleCI](https://camo.githubusercontent.com/27c478cf83560342ae17692065aa6e85409485cf26eae3001087add73e545cf1/68747470733a2f2f7374796c6563692e696f2f7265706f732f37303038303132382f736869656c643f7374796c653d666c6174)](https://styleci.io/repos/70080128)[![Build Status](https://camo.githubusercontent.com/49cd61900d3b93649eb2685c4dad364e97ec466876666680fbf83fc808bfc15e/68747470733a2f2f7472617669732d63692e6f72672f677265672d6d642f7068702d726f757465722e737667)](https://travis-ci.org/greg-md/php-router)[![Total Downloads](https://camo.githubusercontent.com/4461bcb5525e2d8d0f9ee8358b718c51190aa471bf450642b072a036af0772a6/68747470733a2f2f706f7365722e707567782e6f72672f677265672d6d642f7068702d726f757465722f642f746f74616c2e737667)](https://packagist.org/packages/greg-md/php-router)[![Latest Stable Version](https://camo.githubusercontent.com/cc288fc93019fa7f954769945809dd12eaf5ef2702ae7867174c7d294afa3dce/68747470733a2f2f706f7365722e707567782e6f72672f677265672d6d642f7068702d726f757465722f762f737461626c652e737667)](https://packagist.org/packages/greg-md/php-router)[![Latest Unstable Version](https://camo.githubusercontent.com/79e10ad4cd3676054252946c53e6eac06e9b65276cd7b5d453bd0aa59efeba30/68747470733a2f2f706f7365722e707567782e6f72672f677265672d6d642f7068702d726f757465722f762f756e737461626c652e737667)](https://packagist.org/packages/greg-md/php-router)[![License](https://camo.githubusercontent.com/de0290502614bf781f71f47c9846f5c050b3047846b2b225352e05fcb6e87564/68747470733a2f2f706f7365722e707567782e6f72672f677265672d6d642f7068702d726f757465722f6c6963656e73652e737667)](https://packagist.org/packages/greg-md/php-router)

A powerful routing for PHP.

Table of Contents:
==================

[](#table-of-contents)

- [Requirements](#requirements)
- [How It Works](#how-it-works)
- [Routing Schema](#routing-schema)
- [Router](#router)
- [Group Route](#group-route)
- [Request Route](#request-route)
- [Hidden Route](#hidden-route)
- [License](#license)
- [Huuuge Quote](#huuuge-quote)

Requirements
============

[](#requirements)

- PHP Version `^7.1`

How It Works
============

[](#how-it-works)

**First of all**, you have to initialize a Router:

```
$router = new \Greg\Routing\Router();
```

**Then**, set up some routes:

```
$router->any('/', function() {
    return 'Hello World!';
}, 'home');

$router->get('/page/{page}.html', function($page) {
    return "Hello on page {$page}!";
}, 'page');

$router->post('/user/{id#uint}', 'UsersController@save', 'user.save');
```

> If you set an action like `Controller@action`, when dispatching it will instantiate the `UsersController` and call the `save` public method.

**Now**, you can dispatch URLs path:

```
echo $router->dispatch('/'); // result: Hello World!

// Initialize "UsersController" and execute "save" method.
echo $router->dispatch('/user/1', 'POST');
```

**and**, get URLs for them:

```
$router->url('home'); // result: /

$router->url('home', ['foo' => 'bar']); // result: /?foo=bar

$router->url('user.save', ['id' => 1]); // result: /user/id

$router->url('user.save', ['id' => 1, 'debug' => true]); // result: /user/id?debug=true
```

**Optionally**, you can add a dispatcher to manage actions.

Let say you want to add the `Action` suffix to action names:

```
$router->setDispatcher(function ($action) {
    if (is_callable($action)) {
        return $action;
    }

    return $action . 'Action';
});
```

**Also**, you can inverse the control of the controllers.

Let say you want instantiate the controller with some custom data, or use some external IoC interface and run the `init` method if exists.

```
$router->setIoc(function ($controllerName) {
    // Let say you already have an IoC container.
    global $iocContainer;

    $controller = $iocContainer->load($controllerName);

    if (method_exists($controller, 'init')) {
        $controller->init();
    }

    return $controller;
});
```

Routing Schema
==============

[](#routing-schema)

Routing schema supports **parameters** and **optional segments**.

**Parameter** format is `{[:][#][|]}?`.

`` - Parameter name;
`` - Default value;
`` - Parameter type. Supports `int`, `uint`, `boolean`(or `bool`);
`` - Parameter regex;
`?` - Question mark from the end determine if the parameter should be optional.

> Only `` is required in the parameter.

**Optional segment** format is `[]`. Is working recursively.

`` - Any [routing schema](#routing-schema).

> It is very useful when you want to use the same action with different routing schema.

### Example

[](#example)

Let say we have a page with all articles of the same type, including pagination. The route for this page will be:

```
$router->get('/articles/{type:lifestyle|[a-z0-9-]+}[/page-{page:1#uint}]', 'ArticlesController@type', 'articles.type');
```

`type` parameter is required in the route. Default value is `lifestyle` and should consist of **letters, numbers and dashes**.

`page` parameter is required in its segment, but the segment entirely is optional. Default value is `1` and should consist of **unsigned integers**. If the parameter will not be set or will be the same as default value, the entire segment will be excluded from the URL path.

```
echo $router->url('articles.type'); // result: /articles/lifestyle

echo $router->url('articles.type', ['type' => 'travel']); // result: /articles/travel

echo $router->url('articles.type', ['type' => 'travel', 'page' => 1]); // result: /articles/travel

echo $router->url('articles.type', ['type' => 'travel', 'page' => 2]); // result: /articles/travel/page-2
```

As you can see, there are no more URLs where you can get duplicated content, which is best for SEO. In this way, you can easily create good user friendly URLs.

Router
======

[](#router)

Below you can find a list of **supported methods**.

- [url](#url) - Fetch an URL of a route;
- [dispatch](#dispatch) - Dispatch an URL path;
- [any](#any) - Create a route for any request method;
- [request](#request) - Create a route for a specific request method;
    - [get](#request) - Create a GET route;
    - [head](#request) - Create a HEAD route;
    - [post](#request) - Create a POST route;
    - [put](#request) - Create a PUT route;
    - [delete](#request) - Create a DELETE route;
    - [connect](#request) - Create a CONNECT route;
    - [options](#request) - Create a OPTIONS route;
    - [trace](#request) - Create a TRACE route;
    - [patch](#request) - Create a PATCH route;
- [hidden](#hidden) - Create a hidden route. You can not dispatch it, but you can generate URLs from it;
- [group](#group) - Create a group of routes;
- [find](#find) - Find a route by name;
- [bind](#bind) - Set an input/output binder for a parameter;
- [bindStrategy](#bindstrategy) - Set an input/output binder for a parameter, using strategy;
- [bindIn](#bindin) - Set an input binder for a parameter;
- [bindInStrategy](#bindinstrategy) - Set an input binder for a parameter, using strategy;
- [binderIn](#binderin) - Get the input binder of a parameter;
- [bindInParam](#bindinparam) - Bind an input parameter;
- [bindOut](#bindout) - Set an output binder for a parameter;
- [bindOutStrategy](#bindoutstrategy) - Set an output binder for a parameter, using strategy;
- [binderOut](#binderout) - Get the output binder of a parameter;
- [bindOutParam](#bindoutparam) - Bind an output parameter;
- [pattern](#pattern) - Set a parameter pattern;
- [type](#type) - Set a parameter type;
- [getPattern](#getpattern) - Get a parameter pattern;
- [setDispatcher](#setdispatcher) - Set an action dispatcher;
- [getDispatcher](#getdispatcher) - Get the actions dispatcher;
- [setIoc](#setioc) - Set an inversion of control for controllers;
- [getIoc](#getioc) - Get the inversion of control;
- [setNamespace](#setnamespace) - Set a namespace;
- [getNamespace](#getnamespace) - Get the namespace;
- [setErrorAction](#seterroraction) - Set an error action;
- [getErrorAction](#geterroraction) - Get the error action;
- [setHost](#sethost) - Set a host;
- [getHost](#gethost) - Get the host.

url
---

[](#url)

Get the URL of a route.

```
url(string $name, array $params = []): string
```

*Example:*

```
$router->get('/page/{page}.html', function($page) {
    return "Hello on page {$page}!";
}, 'page');

$router->url('page', ['page' => 'terms']); // result: /page/terms.html

$router->url('page', ['page' => 'terms', 'foo' => 'bar']); // result: /page/terms.html?foo=bar
```

dispatch
--------

[](#dispatch)

Dispatch an URL path.

```
dispatch(string $name, array $params = []): string
```

*Example:*

```
echo $router->dispatch('/'); // Dispatch any route

echo $router->dispatch('/user/1', 'POST'); // Dispatch a POST route
```

Group Route
===========

[](#group-route)

**Magic methods:**

- [\_\_construct](#__construct)

Below you can find a list of **supported methods**.

- [match](#match) - Match a path against routes;
- [schema](#schema) - Get the schema;
- [schemaInfo](#schemaInfo) - Get information about schema;
- [setParent](#setParent) - Set parent routing;
- [getParent](#getParent) - Get parent routing;
- [path](#path) - Generate the path;
- [any](#any) - Create a route for any request method;
- [request](#request) - Create a route for a specific request method;
    - [get](#request) - Create a GET route;
    - [head](#request) - Create a HEAD route;
    - [post](#request) - Create a POST route;
    - [put](#request) - Create a PUT route;
    - [delete](#request) - Create a DELETE route;
    - [connect](#request) - Create a CONNECT route;
    - [options](#request) - Create a OPTIONS route;
    - [trace](#request) - Create a TRACE route;
    - [patch](#request) - Create a PATCH route;
- [hidden](#hidden) - Create a hidden route. You can not dispatch it, but you can generate URLs from it;
- [group](#group) - Create a group of routes;
- [find](#find) - Find a route by name;
- [bind](#bind) - Set an input/output binder for a parameter;
- [bindStrategy](#bindstrategy) - Set an input/output binder for a parameter, using strategy;
- [bindIn](#bindin) - Set an input binder for a parameter;
- [bindInStrategy](#bindinstrategy) - Set an input binder for a parameter, using strategy;
- [binderIn](#binderin) - Get the input binder of a parameter;
- [bindInParam](#bindinparam) - Bind an input parameter;
- [bindOut](#bindout) - Set an output binder for a parameter;
- [bindOutStrategy](#bindoutstrategy) - Set an output binder for a parameter, using strategy;
- [binderOut](#binderout) - Get the output binder of a parameter;
- [bindOutParam](#bindoutparam) - Bind an output parameter;
- [pattern](#pattern) - Set a parameter pattern;
- [type](#type) - Set a parameter type;
- [getPattern](#getpattern) - Get a parameter pattern;
- [setDispatcher](#setdispatcher) - Set an action dispatcher;
- [getDispatcher](#getdispatcher) - Get the actions dispatcher;
- [setIoc](#setioc) - Set an inversion of control for controllers;
- [getIoc](#getioc) - Get the inversion of control;
- [setNamespace](#setnamespace) - Set a namespace;
- [getNamespace](#getnamespace) - Get the namespace;
- [setErrorAction](#seterroraction) - Set an error action;
- [getErrorAction](#geterroraction) - Get the error action;
- [setHost](#sethost) - Set a host;
- [getHost](#gethost) - Get the host.

\_\_construct
-------------

[](#__construct)

Initialize the route group.

```
__construct(string $schema)
```

*Example:*

```
$group = new \Greg\Routing\GroupRoute('/api/v1');

$group->get('/user');
```

match
-----

[](#match)

Match a path against routes.

```
match(string $path, ?string $method = null, \Greg\Routing\RouteStrategy &$route = null, \Greg\Routing\RouteData &$data = null): bool
```

*Example:*

```
if ($group->match('/', 'GET', $route, $data)) {
    echo $route->exec($data);
}
```

Request Route
=============

[](#request-route)

**Magic methods:**

- [\_\_construct](#__construct)

Below you can find a list of **supported methods**.

- [match](#match) - Match a path against routes;
- [exec](#exec) - Execute the route;
- [url](#url) - Fetch an URL for the route;
- [where](#where) - Set a parameter pattern. Alias of [pattern](#pattern);
- [whereIs](#whereis) - Set a parameter type. Alias of [type](#type);
- [schema](#schema) - Get the schema;
- [schemaInfo](#schemaInfo) - Get information about schema;
- [setParent](#setParent) - Set parent routing;
- [getParent](#getParent) - Get parent routing;
- [path](#path) - Generate the path;
- [bind](#bind) - Set an input/output binder for a parameter;
- [bindStrategy](#bindstrategy) - Set an input/output binder for a parameter, using strategy;
- [bindIn](#bindin) - Set an input binder for a parameter;
- [bindInStrategy](#bindinstrategy) - Set an input binder for a parameter, using strategy;
- [binderIn](#binderin) - Get the input binder of a parameter;
- [bindInParam](#bindinparam) - Bind an input parameter;
- [bindOut](#bindout) - Set an output binder for a parameter;
- [bindOutStrategy](#bindoutstrategy) - Set an output binder for a parameter, using strategy;
- [binderOut](#binderout) - Get the output binder of a parameter;
- [bindOutParam](#bindoutparam) - Bind an output parameter;
- [pattern](#pattern) - Set a parameter pattern;
- [type](#type) - Set a parameter type;
- [getPattern](#getpattern) - Get a parameter pattern;
- [setDispatcher](#setdispatcher) - Set an action dispatcher;
- [getDispatcher](#getdispatcher) - Get the actions dispatcher;
- [setIoc](#setioc) - Set an inversion of control for controllers;
- [getIoc](#getioc) - Get the inversion of control;
- [setErrorAction](#seterroraction) - Set an error action;
- [getErrorAction](#geterroraction) - Get the error action;
- [setHost](#sethost) - Set a host;
- [getHost](#gethost) - Get the host.

\_\_construct
-------------

[](#__construct-1)

Initialize the request route.

```
__construct(string $schema, $action)
```

*Example:*

```
$route = new \Greg\Routing\RequestRoute('/users', 'UsersController@index');

$route->exec();
```

match
-----

[](#match-1)

Match a path against route.

```
match(string $path, RouteData &$data = null): bool
```

*Example:*

```
if ($route->match('/', $data)) {
    print_r($data->params());
}
```

exec
----

[](#exec)

Execute the route.

```
exec(RouteData $data): string
```

*Example:*

```
$route->exec(new RouteData('/', ['foo' => 'bar']));
```

url
---

[](#url-1)

Fetch an URL for the route.

```
url(array $params = []): string
```

*Example:*

```
$url = $route->url(['foo' => 'bar']);
```

Hidden Route
============

[](#hidden-route)

**Magic methods:**

- [\_\_construct](#__construct)

Below you can find a list of **supported methods**.

- [url](#url) - Fetch an URL for the route;
- [schema](#schema) - Get the schema;
- [schemaInfo](#schemaInfo) - Get information about schema;
- [setParent](#setParent) - Set parent routing;
- [getParent](#getParent) - Get parent routing;
- [path](#path) - Generate the path;
- [bindOut](#bindout) - Set an output binder for a parameter;
- [bindOutStrategy](#bindoutstrategy) - Set an output binder for a parameter, using strategy;
- [binderOut](#binderout) - Get the output binder of a parameter;
- [bindOutParam](#bindoutparam) - Bind an output parameter;
- [setHost](#sethost) - Set a host;
- [getHost](#gethost) - Get the host.

\_\_construct
-------------

[](#__construct-2)

Initialize the request route.

```
__construct(string $schema)
```

*Example:*

```
$route = new \Greg\Routing\HiddenRoute('/users');

$route->exec();
```

Routing Abstract
================

[](#routing-abstract)

any
---

[](#any)

Create a route for any request method.

```
any(string $schema, $action, ?string $name = null): \Greg\Routing\RequestRoute
```

request
-------

[](#request)

Create a route for a specific request method.

```
request(string $schema, $action, ?string $name = null, ?string $method = null): \Greg\Routing\RequestRoute
```

You can also create a specific request method by calling the method name directly. Available types are: `GET`, `HEAD`, `POST`, `PUT`, `DELETE`, `CONNECT`, `OPTIONS`, `TRACE`, `PATCH`.

```
[get|head|post|put|delete|connect|options|trace|patch](string $schema, $action, ?string $name = null): \Greg\Routing\RequestRoute
```

*Example:*

```
$router->get('/users', 'UsersController@index', 'users');

$router->post('/users/add', 'UsersController@add', 'users.add');
```

hidden
------

[](#hidden)

Create a hidden route. You can not dispatch it, but you can generate URLs from it.

```
hidden(string $schema, string $name): \Greg\Routing\HiddenRoute
```

*Example:*

```
$router->hidden('/catalog/{name}', 'partner.catalog')->setHost('mypartner.com');

$router->url('partner.catalog', ['name' => 'cars']); // result: http://mypartner.com/catalog/cars
```

group
-----

[](#group)

Create a group of routes.

```
group(string $schema, ?string $prefix, callable(\Greg\Routing\GroupRoute $route): void $callable): \Greg\Routing\GroupRoute
```

*Example:*

```
$router->group('/api', 'api.', function (\Greg\Routing\GroupRoute $group) {
    $group->group('/v1', 'v1.', function (\Greg\Routing\GroupRoute $group) {
        $group->any('/users', 'UsersController@index', 'users');
    });

    $group->group('/v2', 'v2.', function (\Greg\Routing\GroupRoute $group) {
        $group->any('/users', 'UsersController@index', 'users');

        $group->any('/clients', 'ClientsController@index', 'clients');
    });
});

$router->url('api.v1.users'); // result: /api/v1/users

$router->url('api.v1.clients'); // throws: \Greg\Routing\RoutingException

$router->url('api.v2.clients'); // result: /api/v2/clients
```

find
----

[](#find)

Find a route by name.

```
find(string $name): ?\Greg\Routing\FetchRouteStrategy
```

*Example:*

```
$route = $router->find('users.save');

$route->url(['foo' => 'bar']);
```

setNamespace
------------

[](#setnamespace)

Set a namespace.

```
setNamespace(string $namespace): $this
```

*Example:*

```
$router->setNamespace('Http');
```

getNamespace
------------

[](#getnamespace)

Get the namespace.

```
getNamespace(): string
```

BindTrait
=========

[](#bindtrait)

bind
----

[](#bind)

Set an input/output binder for a parameter.

```
bind(string $name, callable(mixed $value): mixed $callableIn, ?callable(mixed $value): mixed $callableOut = null): $this
```

*Example:*

```
$this->bind('id', function($id) {
    $user = (object) ['id' => $id];

    return $user;
}, function($user) {
    return $user->id;
});
```

bindStrategy
------------

[](#bindstrategy)

Set an input/output binder for a parameter, using strategy.

```
bindStrategy(string $name, \Greg\Routing\BindInOutStrategy $strategy): $this
```

*Example:*

```
$this->bindStrategy('id', new class implements BindInOutStrategy {
    public function input($id)
    {
        $user = (object) ['id' => $id];

        return $user;
    }

    public function output($user)
    {
        return $user->id;
    }
});
```

BindInTrait
===========

[](#bindintrait)

bindIn
------

[](#bindin)

Set an input binder for a parameter.

```
bindIn($name, callable(mixed $value): mixed $callable): $this
```

*Example:*

```
$this->bindIn('id', function($id) {
    $user = (object) ['id' => $id];

    return $user;
});
```

bindInStrategy
--------------

[](#bindinstrategy)

Set an input binder for a parameter, using strategy.

```
bindInStrategy($name, \Greg\Routing\BindInStrategy $strategy): $this
```

*Example:*

```
$this->bindInStrategy('id', new class implements \Greg\Routing\BindInStrategy {
    public function input($id)
    {
        $user = (object) ['id' => $id];

        return $user;
    }
});
```

binderIn
--------

[](#binderin)

Get the input binder of a parameter.

```
binderIn(string $name): \Greg\Routing\BindInStrategy|callable
```

*Example:*

```
$binder = $router->binderIn('id');

if (is_callable($binder)) {
    $user = $binder(1);
} else {
    $user = $binder->input(1);
}
```

bindInParam
-----------

[](#bindinparam)

Bind an input parameter.

```
bindInParam(string $name, $value): mixed
```

*Example:*

```
$user = $router->bindInParam('id', 1);
```

BindOutTrait
============

[](#bindouttrait)

bindOut
-------

[](#bindout)

Set an output binder for a parameter.

```
bindOut($name, callable(mixed $value): mixed $callable): $this
```

*Example:*

```
$this->bindOut('id', function($user) {
    return $user->id;
});
```

bindOutStrategy
---------------

[](#bindoutstrategy)

Set an output binder for a parameter, using strategy.

```
bindOutStrategy($name, \Greg\Routing\BindOutStrategy $strategy): $this
```

*Example:*

```
$this->bindOutStrategy('id', new class implements \Greg\Routing\BindOutStrategy {
    public function output($user)
    {
        return $user->id;
    }
});
```

binderOut
---------

[](#binderout)

Get the output binder of a parameter.

```
binderOut(string $name): \Greg\Routing\BindOutStrategy|callable
```

*Example:*

```
$binder = $router->binderOut('id');

if (is_callable($binder)) {
    $id = $binder($user);
} else {
    $id = $binder->output($user);
}
```

bindOutParam
------------

[](#bindoutparam)

Bind an output parameter.

```
bindOutParam(string $name, $value): mixed
```

*Example:*

```
$user = $router->bindOutParam('id', 1);
```

DispatcherTrait
===============

[](#dispatchertrait)

setDispatcher
-------------

[](#setdispatcher)

Set an action dispatcher.

```
setDispatcher(callable(mixed $action): mixed $callable): $this
```

*Example:*

Let say you want to add the `Action` suffix to action names:

```
$router->setDispatcher(function ($action) {
    if (is_callable($action)) {
        return $action;
    }

    return $action . 'Action';
});
```

getDispatcher
-------------

[](#getdispatcher)

Get the actions dispatcher.

```
getDispatcher(): callable
```

setIoc
------

[](#setioc)

Set an inversion of control for controllers.

```
setIoc(callable(string $controllerName): object $callable): $this
```

*Example:*

Let say you want instantiate the controller with some custom data, or use some external IoC interface and run the `init` method if exists.

```
$router->setIoc(function ($controllerName) {
    // Let say you already have an IoC container.
    global $iocContainer;

    $controller = $iocContainer->load($controllerName);

    if (method_exists($controller, 'init')) {
        $controller->init();
    }

    return $controller;
});
```

getIoc
------

[](#getioc)

Get the inversion of control.

```
getIoc(): callable
```

ErrorActionTrait
================

[](#erroractiontrait)

setErrorAction
--------------

[](#seterroraction)

Set error action.

```
setErrorAction($action): $this
```

*Example:*

```
$router->setErrorAction(function() {
    return 'Ooops! Something has gone wrong.'
});
```

getErrorAction
--------------

[](#geterroraction)

Get error action.

```
getErrorAction(): mixed
```

HostTrait
=========

[](#hosttrait)

setHost
-------

[](#sethost)

Set a host.

```
setHost(string $host): $this
```

*Example:*

```
$router->setHost('example.com');
```

getHost
-------

[](#gethost)

Get the host.

```
getHost(): string
```

RoutingTrait
============

[](#routingtrait)

schema
------

[](#schema)

Get the schema.

```
schema(): ?string
```

schemaInfo
----------

[](#schemainfo)

Get information about schema.

```
schemaInfo(): ['regex', 'params']
```

setParent
---------

[](#setparent)

Set parent routing.

```
setParent(RoutesAbstract $parent): $this
```

getParent
---------

[](#getparent)

Get parent routing.

```
getParent(): RoutesAbstract
```

path
----

[](#path)

Generate the path.

```
path(array $params = []): array
```

PatternsTrait
=============

[](#patternstrait)

pattern
-------

[](#pattern)

Set a parameter pattern.

```
pattern(string $name, string $regex): $this
```

type
----

[](#type)

Set a parameter type pattern.

```
type(string $name, string $type): $this
```

getPattern
----------

[](#getpattern)

Get parameter pattern.

```
getPattern(string $name): ?string
```

License
=======

[](#license)

MIT © [Grigorii Duca](http://greg.md)

Huuuge Quote
============

[](#huuuge-quote)

[![I fear not the man who has practiced 10,000 programming languages once, but I fear the man who has practiced one programming language 10,000 times. #horrorsquad](https://camo.githubusercontent.com/73fc580403a8367b075fff0a0d7439dc0dc095dd3124b22757522675c1308df8/687474703a2f2f677265672e6d642f6875757567652d71756f74652d66622e6a7067)](https://camo.githubusercontent.com/73fc580403a8367b075fff0a0d7439dc0dc095dd3124b22757522675c1308df8/687474703a2f2f677265672e6d642f6875757567652d71756f74652d66622e6a7067)

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance49

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity39

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/85a6700372326d0546fcff3eb2c3f27daa711273bdd5d6fdda875a7d2f02af85?d=identicon)[greg-md](/maintainers/greg-md)

---

Top Contributors

[![greg-md](https://avatars.githubusercontent.com/u/10551984?v=4)](https://github.com/greg-md "greg-md (2 commits)")

---

Tags

greg-mdgreg-phpphpphp-routerrouterroutingweb-artisans

### Embed Badge

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

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

###  Alternatives

[laravel/dusk

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

1.9k39.6M293](/packages/laravel-dusk)[nineinchnick/edatatables

Grid widget for the Yii Framework, wrapper for the DataTables jQuery plugin

173.2k](/packages/nineinchnick-edatatables)[link-cloud/fast-hyperf

LinkCloud Fast Hyperf

241.2k1](/packages/link-cloud-fast-hyperf)

PHPackages © 2026

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