{"id":20731080,"url":"https://github.com/greg-md/php-router","last_synced_at":"2025-10-07T22:32:41.833Z","repository":{"id":62512570,"uuid":"70080128","full_name":"greg-md/php-router","owner":"greg-md","description":"A powerful routing for PHP.","archived":false,"fork":false,"pushed_at":"2019-07-23T22:13:01.000Z","size":88,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T10:21:46.774Z","etag":null,"topics":["greg-md","greg-php","php","php-router","router","routing","web-artisans"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/greg-md.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-05T16:53:08.000Z","updated_at":"2019-07-23T22:13:02.000Z","dependencies_parsed_at":"2022-11-02T12:47:27.565Z","dependency_job_id":null,"html_url":"https://github.com/greg-md/php-router","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/greg-md/php-router","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greg-md%2Fphp-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greg-md%2Fphp-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greg-md%2Fphp-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greg-md%2Fphp-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/greg-md","download_url":"https://codeload.github.com/greg-md/php-router/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greg-md%2Fphp-router/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267414096,"owners_count":24083550,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["greg-md","greg-php","php","php-router","router","routing","web-artisans"],"created_at":"2024-11-17T05:13:38.932Z","updated_at":"2025-10-07T22:32:36.791Z","avatar_url":"https://github.com/greg-md.png","language":"PHP","readme":"# Greg PHP Routing\n\n[![StyleCI](https://styleci.io/repos/70080128/shield?style=flat)](https://styleci.io/repos/70080128)\n[![Build Status](https://travis-ci.org/greg-md/php-router.svg)](https://travis-ci.org/greg-md/php-router)\n[![Total Downloads](https://poser.pugx.org/greg-md/php-router/d/total.svg)](https://packagist.org/packages/greg-md/php-router)\n[![Latest Stable Version](https://poser.pugx.org/greg-md/php-router/v/stable.svg)](https://packagist.org/packages/greg-md/php-router)\n[![Latest Unstable Version](https://poser.pugx.org/greg-md/php-router/v/unstable.svg)](https://packagist.org/packages/greg-md/php-router)\n[![License](https://poser.pugx.org/greg-md/php-router/license.svg)](https://packagist.org/packages/greg-md/php-router)\n\nA powerful routing for PHP.\n\n# Table of Contents:\n\n* [Requirements](#requirements)\n* [How It Works](#how-it-works)\n* [Routing Schema](#routing-schema)\n* [Router](#router)\n* [Group Route](#group-route)\n* [Request Route](#request-route)\n* [Hidden Route](#hidden-route)\n* [License](#license)\n* [Huuuge Quote](#huuuge-quote)\n\n# Requirements\n\n* PHP Version `^7.1`\n\n# How It Works\n\n**First of all**, you have to initialize a Router:\n\n```php\n$router = new \\Greg\\Routing\\Router();\n```\n\n**Then**, set up some routes:\n\n```php\n$router-\u003eany('/', function() {\n    return 'Hello World!';\n}, 'home');\n\n$router-\u003eget('/page/{page}.html', function($page) {\n    return \"Hello on page {$page}!\";\n}, 'page');\n\n$router-\u003epost('/user/{id#uint}', 'UsersController@save', 'user.save');\n```\n\n\u003e If you set an action like `Controller@action`, when dispatching it will instantiate the `UsersController` and call the `save` public method.\n\n**Now**, you can dispatch URLs path:\n\n```php\necho $router-\u003edispatch('/'); // result: Hello World!\n\n// Initialize \"UsersController\" and execute \"save\" method.\necho $router-\u003edispatch('/user/1', 'POST');\n```\n\n**and**, get URLs for them:\n\n```php\n$router-\u003eurl('home'); // result: /\n\n$router-\u003eurl('home', ['foo' =\u003e 'bar']); // result: /?foo=bar\n\n$router-\u003eurl('user.save', ['id' =\u003e 1]); // result: /user/id\n\n$router-\u003eurl('user.save', ['id' =\u003e 1, 'debug' =\u003e true]); // result: /user/id?debug=true\n```\n\n**Optionally**, you can add a dispatcher to manage actions.\n\nLet say you want to add the `Action` suffix to action names:\n\n```php\n$router-\u003esetDispatcher(function ($action) {\n    if (is_callable($action)) {\n        return $action;\n    }\n\n    return $action . 'Action';\n});\n```\n\n**Also**, you can inverse the control of the controllers.\n\nLet say you want instantiate the controller with some custom data,\nor use some external IoC interface and run the `init` method if exists.\n\n```php\n$router-\u003esetIoc(function ($controllerName) {\n    // Let say you already have an IoC container.\n    global $iocContainer;\n\n    $controller = $iocContainer-\u003eload($controllerName);\n\n    if (method_exists($controller, 'init')) {\n        $controller-\u003einit();\n    }\n\n    return $controller;\n});\n```\n\n# Routing Schema\n\nRouting schema supports **parameters** and **optional segments**.\n\n**Parameter** format is `{\u003cname\u003e[:\u003cdefault\u003e][#\u003ctype\u003e][|\u003cregex\u003e]}?`.\n\n`\u003cname\u003e` - Parameter name;  \n`\u003cdefault\u003e` - Default value;  \n`\u003ctype\u003e` - Parameter type. Supports `int`, `uint`, `boolean`(or `bool`);  \n`\u003cregex\u003e` - Parameter regex;  \n`?` - Question mark from the end determine if the parameter should be optional.\n\n\u003e Only `\u003cname\u003e` is required in the parameter.\n\n**Optional segment** format is `[\u003cschema\u003e]`. Is working recursively.\n\n`\u003cschema\u003e` - Any [routing schema](#routing-schema).\n\n\u003e It is very useful when you want to use the same action with different routing schema.\n\n### Example\n\nLet say we have a page with all articles of the same type, including pagination. The route for this page will be:\n\n```php\n$router-\u003eget('/articles/{type:lifestyle|[a-z0-9-]+}[/page-{page:1#uint}]', 'ArticlesController@type', 'articles.type');\n```\n\n`type` parameter is required in the route. Default value is `lifestyle` and should consist of **letters, numbers and dashes**.\n\n`page` parameter is required in its segment, but the segment entirely is optional. Default value is `1` and should consist of **unsigned integers**.\nIf the parameter will not be set or will be the same as default value, the entire segment will be excluded from the URL path.\n\n```php\necho $router-\u003eurl('articles.type'); // result: /articles/lifestyle\n\necho $router-\u003eurl('articles.type', ['type' =\u003e 'travel']); // result: /articles/travel\n\necho $router-\u003eurl('articles.type', ['type' =\u003e 'travel', 'page' =\u003e 1]); // result: /articles/travel\n\necho $router-\u003eurl('articles.type', ['type' =\u003e 'travel', 'page' =\u003e 2]); // result: /articles/travel/page-2\n```\n\nAs you can see, there are no more URLs where you can get duplicated content, which is best for SEO.\nIn this way, you can easily create good user friendly URLs.\n\n# Router\n\nBelow you can find a list of **supported methods**.\n\n* [url](#url) - Fetch an URL of a route;\n* [dispatch](#dispatch) - Dispatch an URL path;\n* [any](#any) - Create a route for any request method;\n* [request](#request) - Create a route for a specific request method;\n    * [get](#request) - Create a GET route;\n    * [head](#request) - Create a HEAD route;\n    * [post](#request) - Create a POST route;\n    * [put](#request) - Create a PUT route;\n    * [delete](#request) - Create a DELETE route;\n    * [connect](#request) - Create a CONNECT route;\n    * [options](#request) - Create a OPTIONS route;\n    * [trace](#request) - Create a TRACE route;\n    * [patch](#request) - Create a PATCH route;\n* [hidden](#hidden) - Create a hidden route. You can not dispatch it, but you can generate URLs from it;\n* [group](#group) - Create a group of routes;\n* [find](#find) - Find a route by name;\n* [bind](#bind) - Set an input/output binder for a parameter;\n* [bindStrategy](#bindstrategy) - Set an input/output binder for a parameter, using strategy;\n* [bindIn](#bindin) - Set an input binder for a parameter;\n* [bindInStrategy](#bindinstrategy) - Set an input binder for a parameter, using strategy;\n* [binderIn](#binderin) - Get the input binder of a parameter;\n* [bindInParam](#bindinparam) - Bind an input parameter;\n* [bindOut](#bindout) - Set an output binder for a parameter;\n* [bindOutStrategy](#bindoutstrategy) - Set an output binder for a parameter, using strategy;\n* [binderOut](#binderout) - Get the output binder of a parameter;\n* [bindOutParam](#bindoutparam) - Bind an output parameter;\n* [pattern](#pattern) - Set a parameter pattern;\n* [type](#type) - Set a parameter type;\n* [getPattern](#getpattern) - Get a parameter pattern;\n* [setDispatcher](#setdispatcher) - Set an action dispatcher;\n* [getDispatcher](#getdispatcher) - Get the actions dispatcher;\n* [setIoc](#setioc) - Set an inversion of control for controllers;\n* [getIoc](#getioc) - Get the inversion of control;\n* [setNamespace](#setnamespace) - Set a namespace;\n* [getNamespace](#getnamespace) - Get the namespace;\n* [setErrorAction](#seterroraction) - Set an error action;\n* [getErrorAction](#geterroraction) - Get the error action;\n* [setHost](#sethost) - Set a host;\n* [getHost](#gethost) - Get the host.\n\n## url\n\nGet the URL of a route.\n\n```php\nurl(string $name, array $params = []): string\n```\n\n_Example:_\n\n```php\n$router-\u003eget('/page/{page}.html', function($page) {\n    return \"Hello on page {$page}!\";\n}, 'page');\n\n$router-\u003eurl('page', ['page' =\u003e 'terms']); // result: /page/terms.html\n\n$router-\u003eurl('page', ['page' =\u003e 'terms', 'foo' =\u003e 'bar']); // result: /page/terms.html?foo=bar\n```\n\n## dispatch\n\nDispatch an URL path.\n\n```php\ndispatch(string $name, array $params = []): string\n```\n\n_Example:_\n\n```php\necho $router-\u003edispatch('/'); // Dispatch any route\n\necho $router-\u003edispatch('/user/1', 'POST'); // Dispatch a POST route\n```\n\n# Group Route\n\n**Magic methods:**\n* [__construct](#__construct)\n\nBelow you can find a list of **supported methods**.\n\n* [match](#match) - Match a path against routes;\n* [schema](#schema) - Get the schema;\n* [schemaInfo](#schemaInfo) - Get information about schema;\n* [setParent](#setParent) - Set parent routing;\n* [getParent](#getParent) - Get parent routing;\n* [path](#path) - Generate the path;\n* [any](#any) - Create a route for any request method;\n* [request](#request) - Create a route for a specific request method;\n    * [get](#request) - Create a GET route;\n    * [head](#request) - Create a HEAD route;\n    * [post](#request) - Create a POST route;\n    * [put](#request) - Create a PUT route;\n    * [delete](#request) - Create a DELETE route;\n    * [connect](#request) - Create a CONNECT route;\n    * [options](#request) - Create a OPTIONS route;\n    * [trace](#request) - Create a TRACE route;\n    * [patch](#request) - Create a PATCH route;\n* [hidden](#hidden) - Create a hidden route. You can not dispatch it, but you can generate URLs from it;\n* [group](#group) - Create a group of routes;\n* [find](#find) - Find a route by name;\n* [bind](#bind) - Set an input/output binder for a parameter;\n* [bindStrategy](#bindstrategy) - Set an input/output binder for a parameter, using strategy;\n* [bindIn](#bindin) - Set an input binder for a parameter;\n* [bindInStrategy](#bindinstrategy) - Set an input binder for a parameter, using strategy;\n* [binderIn](#binderin) - Get the input binder of a parameter;\n* [bindInParam](#bindinparam) - Bind an input parameter;\n* [bindOut](#bindout) - Set an output binder for a parameter;\n* [bindOutStrategy](#bindoutstrategy) - Set an output binder for a parameter, using strategy;\n* [binderOut](#binderout) - Get the output binder of a parameter;\n* [bindOutParam](#bindoutparam) - Bind an output parameter;\n* [pattern](#pattern) - Set a parameter pattern;\n* [type](#type) - Set a parameter type;\n* [getPattern](#getpattern) - Get a parameter pattern;\n* [setDispatcher](#setdispatcher) - Set an action dispatcher;\n* [getDispatcher](#getdispatcher) - Get the actions dispatcher;\n* [setIoc](#setioc) - Set an inversion of control for controllers;\n* [getIoc](#getioc) - Get the inversion of control;\n* [setNamespace](#setnamespace) - Set a namespace;\n* [getNamespace](#getnamespace) - Get the namespace;\n* [setErrorAction](#seterroraction) - Set an error action;\n* [getErrorAction](#geterroraction) - Get the error action;\n* [setHost](#sethost) - Set a host;\n* [getHost](#gethost) - Get the host.\n\n## __construct\n\nInitialize the route group.\n\n```php\n__construct(string $schema)\n```\n\n_Example:_\n\n```php\n$group = new \\Greg\\Routing\\GroupRoute('/api/v1');\n\n$group-\u003eget('/user');\n```\n\n## match\n\nMatch a path against routes.\n\n```php\nmatch(string $path, ?string $method = null, \\Greg\\Routing\\RouteStrategy \u0026$route = null, \\Greg\\Routing\\RouteData \u0026$data = null): bool\n```\n\n_Example:_\n\n```php\nif ($group-\u003ematch('/', 'GET', $route, $data)) {\n    echo $route-\u003eexec($data);\n}\n```\n\n# Request Route\n\n**Magic methods:**\n* [__construct](#__construct)\n\nBelow you can find a list of **supported methods**.\n\n* [match](#match) - Match a path against routes;\n* [exec](#exec) - Execute the route;\n* [url](#url) - Fetch an URL for the route;\n* [where](#where) - Set a parameter pattern. Alias of [pattern](#pattern);\n* [whereIs](#whereis) - Set a parameter type. Alias of [type](#type);\n* [schema](#schema) - Get the schema;\n* [schemaInfo](#schemaInfo) - Get information about schema;\n* [setParent](#setParent) - Set parent routing;\n* [getParent](#getParent) - Get parent routing;\n* [path](#path) - Generate the path;\n* [bind](#bind) - Set an input/output binder for a parameter;\n* [bindStrategy](#bindstrategy) - Set an input/output binder for a parameter, using strategy;\n* [bindIn](#bindin) - Set an input binder for a parameter;\n* [bindInStrategy](#bindinstrategy) - Set an input binder for a parameter, using strategy;\n* [binderIn](#binderin) - Get the input binder of a parameter;\n* [bindInParam](#bindinparam) - Bind an input parameter;\n* [bindOut](#bindout) - Set an output binder for a parameter;\n* [bindOutStrategy](#bindoutstrategy) - Set an output binder for a parameter, using strategy;\n* [binderOut](#binderout) - Get the output binder of a parameter;\n* [bindOutParam](#bindoutparam) - Bind an output parameter;\n* [pattern](#pattern) - Set a parameter pattern;\n* [type](#type) - Set a parameter type;\n* [getPattern](#getpattern) - Get a parameter pattern;\n* [setDispatcher](#setdispatcher) - Set an action dispatcher;\n* [getDispatcher](#getdispatcher) - Get the actions dispatcher;\n* [setIoc](#setioc) - Set an inversion of control for controllers;\n* [getIoc](#getioc) - Get the inversion of control;\n* [setErrorAction](#seterroraction) - Set an error action;\n* [getErrorAction](#geterroraction) - Get the error action;\n* [setHost](#sethost) - Set a host;\n* [getHost](#gethost) - Get the host.\n\n## __construct\n\nInitialize the request route.\n\n```php\n__construct(string $schema, $action)\n```\n\n_Example:_\n\n```php\n$route = new \\Greg\\Routing\\RequestRoute('/users', 'UsersController@index');\n\n$route-\u003eexec();\n```\n\n## match\n\nMatch a path against route.\n\n```php\nmatch(string $path, RouteData \u0026$data = null): bool\n```\n\n_Example:_\n\n```php\nif ($route-\u003ematch('/', $data)) {\n    print_r($data-\u003eparams());\n}\n```\n\n## exec\n\nExecute the route.\n\n```php\nexec(RouteData $data): string\n```\n\n_Example:_\n\n```php\n$route-\u003eexec(new RouteData('/', ['foo' =\u003e 'bar']));\n```\n\n## url\n\nFetch an URL for the route.\n\n```php\nurl(array $params = []): string\n```\n\n_Example:_\n\n```php\n$url = $route-\u003eurl(['foo' =\u003e 'bar']);\n```\n\n# Hidden Route\n\n**Magic methods:**\n* [__construct](#__construct)\n\nBelow you can find a list of **supported methods**.\n\n* [url](#url) - Fetch an URL for the route;\n* [schema](#schema) - Get the schema;\n* [schemaInfo](#schemaInfo) - Get information about schema;\n* [setParent](#setParent) - Set parent routing;\n* [getParent](#getParent) - Get parent routing;\n* [path](#path) - Generate the path;\n* [bindOut](#bindout) - Set an output binder for a parameter;\n* [bindOutStrategy](#bindoutstrategy) - Set an output binder for a parameter, using strategy;\n* [binderOut](#binderout) - Get the output binder of a parameter;\n* [bindOutParam](#bindoutparam) - Bind an output parameter;\n* [setHost](#sethost) - Set a host;\n* [getHost](#gethost) - Get the host.\n\n## __construct\n\nInitialize the request route.\n\n```php\n__construct(string $schema)\n```\n\n_Example:_\n\n```php\n$route = new \\Greg\\Routing\\HiddenRoute('/users');\n\n$route-\u003eexec();\n```\n\n# Routing Abstract\n\n## any\n\nCreate a route for any request method.\n\n```php\nany(string $schema, $action, ?string $name = null): \\Greg\\Routing\\RequestRoute\n```\n\n## request\n\nCreate a route for a specific request method.\n\n```php\nrequest(string $schema, $action, ?string $name = null, ?string $method = null): \\Greg\\Routing\\RequestRoute\n```\n\nYou can also create a specific request method by calling the method name directly.\nAvailable types are: `GET`, `HEAD`, `POST`, `PUT`, `DELETE`, `CONNECT`, `OPTIONS`, `TRACE`, `PATCH`.\n\n```php\n[get|head|post|put|delete|connect|options|trace|patch](string $schema, $action, ?string $name = null): \\Greg\\Routing\\RequestRoute\n```\n\n_Example:_\n\n```php\n$router-\u003eget('/users', 'UsersController@index', 'users');\n\n$router-\u003epost('/users/add', 'UsersController@add', 'users.add');\n```\n\n## hidden\n\nCreate a hidden route. You can not dispatch it, but you can generate URLs from it.\n\n```php\nhidden(string $schema, string $name): \\Greg\\Routing\\HiddenRoute\n```\n\n_Example:_\n\n```php\n$router-\u003ehidden('/catalog/{name}', 'partner.catalog')-\u003esetHost('mypartner.com');\n\n$router-\u003eurl('partner.catalog', ['name' =\u003e 'cars']); // result: http://mypartner.com/catalog/cars\n```\n\n## group\n\nCreate a group of routes.\n\n```php\ngroup(string $schema, ?string $prefix, callable(\\Greg\\Routing\\GroupRoute $route): void $callable): \\Greg\\Routing\\GroupRoute\n```\n\n_Example:_\n\n```php\n$router-\u003egroup('/api', 'api.', function (\\Greg\\Routing\\GroupRoute $group) {\n    $group-\u003egroup('/v1', 'v1.', function (\\Greg\\Routing\\GroupRoute $group) {\n        $group-\u003eany('/users', 'UsersController@index', 'users');\n    });\n\n    $group-\u003egroup('/v2', 'v2.', function (\\Greg\\Routing\\GroupRoute $group) {\n        $group-\u003eany('/users', 'UsersController@index', 'users');\n        \n        $group-\u003eany('/clients', 'ClientsController@index', 'clients');\n    });\n});\n\n$router-\u003eurl('api.v1.users'); // result: /api/v1/users\n\n$router-\u003eurl('api.v1.clients'); // throws: \\Greg\\Routing\\RoutingException\n\n$router-\u003eurl('api.v2.clients'); // result: /api/v2/clients\n```\n\n## find\n\nFind a route by name.\n\n```php\nfind(string $name): ?\\Greg\\Routing\\FetchRouteStrategy\n```\n\n_Example:_\n\n```php\n$route = $router-\u003efind('users.save');\n\n$route-\u003eurl(['foo' =\u003e 'bar']);\n```\n\n## setNamespace\n\nSet a namespace.\n\n```php\nsetNamespace(string $namespace): $this\n```\n\n_Example:_\n\n```php\n$router-\u003esetNamespace('Http');\n```\n\n## getNamespace\n\nGet the namespace.\n\n```php\ngetNamespace(): string\n```\n\n# BindTrait\n\n## bind\n\nSet an input/output binder for a parameter.\n\n```php\nbind(string $name, callable(mixed $value): mixed $callableIn, ?callable(mixed $value): mixed $callableOut = null): $this\n```\n\n_Example:_\n\n```php\n$this-\u003ebind('id', function($id) {\n    $user = (object) ['id' =\u003e $id];\n\n    return $user;\n}, function($user) {\n    return $user-\u003eid;\n});\n```\n\n## bindStrategy\n\nSet an input/output binder for a parameter, using strategy.\n\n```php\nbindStrategy(string $name, \\Greg\\Routing\\BindInOutStrategy $strategy): $this\n```\n\n_Example:_\n\n```php\n$this-\u003ebindStrategy('id', new class implements BindInOutStrategy {\n    public function input($id)\n    {\n        $user = (object) ['id' =\u003e $id];\n\n        return $user;\n    }\n\n    public function output($user)\n    {\n        return $user-\u003eid;\n    }\n});\n```\n\n# BindInTrait\n\n## bindIn\n\nSet an input binder for a parameter.\n\n```php\nbindIn($name, callable(mixed $value): mixed $callable): $this\n```\n\n_Example:_\n\n```php\n$this-\u003ebindIn('id', function($id) {\n    $user = (object) ['id' =\u003e $id];\n\n    return $user;\n});\n```\n\n## bindInStrategy\n\nSet an input binder for a parameter, using strategy.\n\n```php\nbindInStrategy($name, \\Greg\\Routing\\BindInStrategy $strategy): $this\n```\n\n_Example:_\n\n```php\n$this-\u003ebindInStrategy('id', new class implements \\Greg\\Routing\\BindInStrategy {\n    public function input($id)\n    {\n        $user = (object) ['id' =\u003e $id];\n\n        return $user;\n    }\n});\n```\n\n## binderIn\n\nGet the input binder of a parameter.\n\n```php\nbinderIn(string $name): \\Greg\\Routing\\BindInStrategy|callable\n```\n\n_Example:_\n\n```php\n$binder = $router-\u003ebinderIn('id');\n\nif (is_callable($binder)) {\n    $user = $binder(1);\n} else {\n    $user = $binder-\u003einput(1);\n}\n```\n\n## bindInParam\n\nBind an input parameter.\n\n```php\nbindInParam(string $name, $value): mixed\n```\n\n_Example:_\n\n```php\n$user = $router-\u003ebindInParam('id', 1);\n```\n\n# BindOutTrait\n\n## bindOut\n\nSet an output binder for a parameter.\n\n```php\nbindOut($name, callable(mixed $value): mixed $callable): $this\n```\n\n_Example:_\n\n```php\n$this-\u003ebindOut('id', function($user) {\n    return $user-\u003eid;\n});\n```\n\n## bindOutStrategy\n\nSet an output binder for a parameter, using strategy.\n\n```php\nbindOutStrategy($name, \\Greg\\Routing\\BindOutStrategy $strategy): $this\n```\n\n_Example:_\n\n```php\n$this-\u003ebindOutStrategy('id', new class implements \\Greg\\Routing\\BindOutStrategy {\n    public function output($user)\n    {\n        return $user-\u003eid;\n    }\n});\n```\n\n## binderOut\n\nGet the output binder of a parameter.\n\n```php\nbinderOut(string $name): \\Greg\\Routing\\BindOutStrategy|callable\n```\n\n_Example:_\n\n```php\n$binder = $router-\u003ebinderOut('id');\n\nif (is_callable($binder)) {\n    $id = $binder($user);\n} else {\n    $id = $binder-\u003eoutput($user);\n}\n```\n\n## bindOutParam\n\nBind an output parameter.\n\n```php\nbindOutParam(string $name, $value): mixed\n```\n\n_Example:_\n\n```php\n$user = $router-\u003ebindOutParam('id', 1);\n```\n\n# DispatcherTrait\n\n## setDispatcher\n\nSet an action dispatcher.\n\n```php\nsetDispatcher(callable(mixed $action): mixed $callable): $this\n```\n\n_Example:_\n\nLet say you want to add the `Action` suffix to action names:\n\n```php\n$router-\u003esetDispatcher(function ($action) {\n    if (is_callable($action)) {\n        return $action;\n    }\n\n    return $action . 'Action';\n});\n```\n\n## getDispatcher\n\nGet the actions dispatcher.\n\n```php\ngetDispatcher(): callable\n```\n\n## setIoc\n\nSet an inversion of control for controllers.\n\n```php\nsetIoc(callable(string $controllerName): object $callable): $this\n```\n\n_Example:_\n\nLet say you want instantiate the controller with some custom data,\nor use some external IoC interface and run the `init` method if exists.\n\n```php\n$router-\u003esetIoc(function ($controllerName) {\n    // Let say you already have an IoC container.\n    global $iocContainer;\n\n    $controller = $iocContainer-\u003eload($controllerName);\n\n    if (method_exists($controller, 'init')) {\n        $controller-\u003einit();\n    }\n\n    return $controller;\n});\n```\n\n## getIoc\n\nGet the inversion of control.\n\n```php\ngetIoc(): callable\n```\n\n# ErrorActionTrait\n\n## setErrorAction\n\nSet error action.\n\n```php\nsetErrorAction($action): $this\n```\n\n_Example:_\n\n```php\n$router-\u003esetErrorAction(function() {\n    return 'Ooops! Something has gone wrong.'\n});\n```\n\n## getErrorAction\n\nGet error action.\n\n```php\ngetErrorAction(): mixed\n```\n\n# HostTrait\n\n## setHost\n\nSet a host.\n\n```php\nsetHost(string $host): $this\n```\n\n_Example:_\n\n```php\n$router-\u003esetHost('example.com');\n```\n\n## getHost\n\nGet the host.\n\n```php\ngetHost(): string\n```\n\n# RoutingTrait\n\n## schema\n\nGet the schema.\n\n```php\nschema(): ?string\n```\n\n## schemaInfo\n\nGet information about schema.\n\n```php\nschemaInfo(): ['regex', 'params']\n```\n\n## setParent\n\nSet parent routing.\n\n```php\nsetParent(RoutesAbstract $parent): $this\n```\n\n## getParent\n\nGet parent routing.\n\n```php\ngetParent(): RoutesAbstract\n```\n\n## path\n\nGenerate the path.\n\n```php\npath(array $params = []): array\n```\n\n# PatternsTrait\n\n## pattern\n\nSet a parameter pattern.\n\n```php\npattern(string $name, string $regex): $this\n```\n\n## type\n\nSet a parameter type pattern.\n\n```php\ntype(string $name, string $type): $this\n```\n\n## getPattern\n\nGet parameter pattern.\n\n```php\ngetPattern(string $name): ?string\n```\n\n# License\n\nMIT © [Grigorii Duca](http://greg.md)\n\n# Huuuge Quote\n\n![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](http://greg.md/huuuge-quote-fb.jpg)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreg-md%2Fphp-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgreg-md%2Fphp-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreg-md%2Fphp-router/lists"}