{"id":36248949,"url":"https://github.com/corpusphp/router","last_synced_at":"2026-05-04T13:03:43.340Z","repository":{"id":18105053,"uuid":"21173772","full_name":"CorpusPHP/Router","owner":"CorpusPHP","description":"Simple HTTP and CLI Router for PHP","archived":false,"fork":false,"pushed_at":"2025-12-02T00:50:54.000Z","size":98,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-11T12:34:46.786Z","etag":null,"topics":["httprouter"],"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/CorpusPHP.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2014-06-24T17:13:15.000Z","updated_at":"2025-11-24T22:39:01.000Z","dependencies_parsed_at":"2025-09-02T22:10:03.807Z","dependency_job_id":"3415b9e0-9e98-471f-acea-536336b1495a","html_url":"https://github.com/CorpusPHP/Router","commit_stats":{"total_commits":69,"total_committers":4,"mean_commits":17.25,"dds":0.6231884057971014,"last_synced_commit":"36427c8f5091f921a09fa261ccdf007976043d85"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/CorpusPHP/Router","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CorpusPHP%2FRouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CorpusPHP%2FRouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CorpusPHP%2FRouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CorpusPHP%2FRouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CorpusPHP","download_url":"https://codeload.github.com/CorpusPHP/Router/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CorpusPHP%2FRouter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32608311,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-04T10:08:07.713Z","status":"ssl_error","status_checked_at":"2026-05-04T10:08:02.005Z","response_time":58,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["httprouter"],"created_at":"2026-01-11T06:56:33.772Z","updated_at":"2026-05-04T13:03:43.335Z","avatar_url":"https://github.com/CorpusPHP.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Corpus Router\n\n[![Latest Stable Version](https://poser.pugx.org/corpus/router/version)](https://packagist.org/packages/corpus/router)\n[![License](https://poser.pugx.org/corpus/router/license)](https://packagist.org/packages/corpus/router)\n[![ci.yml](https://github.com/CorpusPHP/Router/actions/workflows/ci.yml/badge.svg?)](https://github.com/CorpusPHP/Router/actions/workflows/ci.yml)\n\n\nA Simple Collection of Routers\n\n## Requirements\n\n- **php**: \u003e=8.1\n\n## Installing\n\nInstall the latest version with:\n\n```bash\ncomposer require 'corpus/router'\n```\n\n## Usage\n\n### HttpRouter\n\n```php\n\u003c?php\n\nrequire __DIR__ . '/../vendor/autoload.php';\n\n// $_SERVER =\u003e ['REQUEST_METHOD' =\u003e [ 'method' =\u003e 'POST' ]]\n$router = new \\Corpus\\Router\\HttpRouter('\\\\Corpus\\\\Controllers', $_SERVER);\n\n$route = $router-\u003ematch('test/controller:action');\n\n// $route =\n//\t[\n//\t\t'controller' =\u003e '\\\\Corpus\\\\Controllers\\\\test\\\\controller',\n//\t\t'action'     =\u003e 'action',\n//\t\t'options'    =\u003e [],\n//\t\t'request'    =\u003e [ 'method' =\u003e 'POST' ],\n//\t]\n\n// ----------------\n\n$route = $router-\u003ematch('test/controller?query=whatwhat');\n\n// $route =\n//\t[\n//\t\t'controller' =\u003e '\\\\Corpus\\\\Controllers\\\\test\\\\controller',\n//\t\t'action'     =\u003e NULL,\n//\t\t'options'    =\u003e [ 'query'  =\u003e 'whatwhat' ],\n//\t\t'request'    =\u003e [ 'method' =\u003e 'POST' ],\n//\t]\n\n// ----------------\n\n$route = $router-\u003ematch($_SERVER['REQUEST_URI']);\n\n// $route = Current Request\n\n// ----------------\n\n$url = $router-\u003egenerate('myNamespace\\\\admin', 'index');\n\n// $url = '/myNamespace/admin:index'\n\n// ----------------\n\n$url = $router-\u003egenerate('\\\\Corpus\\\\Controllers\\\\myNamespace\\\\admin', 'index');\n\n// $url = '/myNamespace/admin:index'\n\n// ----------------\n\ntry {\n\t$url = $router-\u003egenerate('\\\\Invalid\\\\Absolute\\\\Controller', 'index');\n}catch (\\Corpus\\Router\\Exceptions\\NonRoutableException $e) {\n\t$url = 'fail';\n}\n\n// $url = 'fail'\n\n```\n\n## Documentation\n\n### Class: \\Corpus\\Router\\HttpRouter\n\n```php\n\u003c?php\nnamespace Corpus\\Router;\n\nclass HttpRouter {\n\tpublic const ACTION = 'action';\n\tpublic const CONTROLLER = 'controller';\n\tpublic const OPTIONS = 'options';\n}\n```\n\n#### Method: HttpRouter-\u003e__construct\n\n```php\nfunction __construct(string $rootNamespace [, array $server = []])\n```\n\n##### Parameters:\n\n- ***array*** `$server` - The $_SERVER array - optional\n\n---\n\n#### Method: HttpRouter-\u003ematch\n\n```php\nfunction match(string $path) : ?array\n```\n\nMatch given path to a route array.  \n  \nA non-null route is not guaranteed to _exist_ - just to be well formed.  \nIt is up the implementations dispatch mechanism to decide it the route exists  \n  \nThe returned route array the the a shape of  \n  \n```php  \n[  \n    // The controller action. Definition varies by router.  \n    RouterInterface:ACTION     =\u003e 'action',  \n  \n    // An expected class name based on given rules. Not guaranteed to exist.  \n    RouterInterface:CONTROLLER =\u003e '\\Controller\\www\\index',  \n  \n    // Router specific but akin to $_GET - may contain additional options  \n    RouterInterface:OPTIONS    =\u003e ['key' =\u003e 'value'],  \n]  \n```\n\nMatch given path to a route array.  \n  \nA non-null route is not guaranteed to _exist_ - just to be well formed.  \nIt is up the implementations dispatch mechanism to decide it the route exists  \n  \nThe returned route array the the a shape of  \n  \n```php  \n[  \n    // The controller action. Definition varies by router.  \n    RouterInterface:ACTION     =\u003e 'action',  \n  \n    // An expected class name based on given rules. Not guaranteed to exist.  \n    RouterInterface:CONTROLLER =\u003e '\\Controller\\www\\index',  \n  \n    // Router specific but akin to $_GET - may contain additional options  \n    RouterInterface:OPTIONS    =\u003e ['key' =\u003e 'value'],  \n]  \n```\n\n##### Parameters:\n\n- ***string*** `$path` - The path to match against including query string ala `foo/bar.html?param=woo`\n\n##### Returns:\n\n- ***array*** | ***null*** - route array or null on failure to route\n\n---\n\n#### Method: HttpRouter-\u003egenerate\n\n```php\nfunction generate($controller [, ?string $action = null [, array $options = []]]) : string\n```\n\nGenerate a URL for the given controller, action and options\n\n##### Parameters:\n\n- ***object*** | ***string*** `$controller` - Instance or Relative 'admin\\index' or absolute '\\Controllers\\www\\admin\\index'\n\n**Throws**: `\\Corpus\\Router\\Exceptions\\NonRoutableException`\n\n---\n\n#### Method: HttpRouter-\u003egetNamespace\n\n```php\nfunction getNamespace() : string\n```\n\n##### Returns:\n\n- ***string*** - The canonical namespace prefix\n\n### Class: \\Corpus\\Router\\CliRouter\n\n```php\n\u003c?php\nnamespace Corpus\\Router;\n\nclass CliRouter {\n\tpublic const ARGUMENTS = 'arguments';\n\tpublic const ACTION = 'action';\n\tpublic const CONTROLLER = 'controller';\n\tpublic const OPTIONS = 'options';\n}\n```\n\n#### Method: CliRouter-\u003e__construct\n\n```php\nfunction __construct($rootNamespace [, array $arguments = []])\n```\n\n##### Parameters:\n\n- ***string*** `$rootNamespace` - The namespace prefix the controllers will be under\n\n---\n\n#### Method: CliRouter-\u003ematch\n\n```php\nfunction match(string $path) : ?array\n```\n\nMatch given path to a route array.  \n  \nA non-null route is not guaranteed to _exist_ - just to be well formed.  \nIt is up the implementations dispatch mechanism to decide it the route exists  \n  \nThe returned route array the the a shape of  \n  \n```php  \n[  \n    // The controller action. Definition varies by router.  \n    RouterInterface:ACTION     =\u003e 'action',  \n  \n    // An expected class name based on given rules. Not guaranteed to exist.  \n    RouterInterface:CONTROLLER =\u003e '\\Controller\\www\\index',  \n  \n    // Router specific but akin to $_GET - may contain additional options  \n    RouterInterface:OPTIONS    =\u003e ['key' =\u003e 'value'],  \n]  \n```\n\n##### Parameters:\n\n- ***string*** `$path` - The path to match against including query string ala `foo/bar.html?param=woo`\n\n##### Returns:\n\n- ***array*** | ***null*** - route array or null on failure to route\n\n---\n\n#### Method: CliRouter-\u003egetNamespace\n\n```php\nfunction getNamespace() : string\n```\n\n##### Returns:\n\n- ***string*** - The canonical namespace prefix","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorpusphp%2Frouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcorpusphp%2Frouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorpusphp%2Frouter/lists"}