{"id":24402283,"url":"https://github.com/p810/router","last_synced_at":"2025-07-23T12:07:26.641Z","repository":{"id":57034847,"uuid":"54674851","full_name":"p810/router","owner":"p810","description":"Respond to any requested URI in your application through a single point of entry.","archived":false,"fork":false,"pushed_at":"2018-07-24T20:20:28.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-20T00:59:40.156Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/p810.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-24T21:17:40.000Z","updated_at":"2018-07-20T21:45:28.000Z","dependencies_parsed_at":"2022-08-23T20:50:38.255Z","dependency_job_id":null,"html_url":"https://github.com/p810/router","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p810%2Frouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p810%2Frouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p810%2Frouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p810%2Frouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/p810","download_url":"https://codeload.github.com/p810/router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243359071,"owners_count":20278126,"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","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":[],"created_at":"2025-01-20T00:59:51.545Z","updated_at":"2025-03-13T07:20:20.065Z","avatar_url":"https://github.com/p810.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Router\n\n\u003e Respond to any requested URI in your application through a single point of entry.\n\n## Installation\n\n```\ncomposer require p810/router\n```\n\n## Usage\n\nA route is any URI that you wish for your application to respond to. Routes must be contained within an instance of `RouteCollection`. The route may be checked against `RouteCollection::match()`, which will either throw an exception (`UnmatchedRouteException`) or call the specified callback.\n\nNote that in order to use this, you must configure your Web server to direct requests to the script where this code is placed (e.g., `.htaccess` for Apache).\n\n### Loading controllers\n\nYou may set a default namespace from which to load classes by calling `Collection::setControllerNamespace()`. Just tell it which namespace is the base of your controllers.\n\n```php\n$router-\u003esetControllerNamespace('MyApp\\\\Controllers\\\\');\n```\n\n### Dynamic routes\n\nYou may pass arguments into your route by using one of the following tokens.\n\n| Token  |        Match        |\n| -----  | ------------------- |\n| {int}  | Any integer (0-9).  |\n| {word} | A word (a-zA-Z 0-9).|\n\nYou may specify that a token is optional by prefixing the closing brace with a question mark, like so: `{token?}`\n\n### Example\n\n```php\n\u003c?php\n\nrequire_once dirname(__FILE__) . '/vendor/autoload.php';\n\n/**\n * Create a collection and register a route to it.\n */\n\nuse p810\\Router\\UnmatchedRouteException;\nuse p810\\Router\\Collection as RouteCollection;\n\n$router = new RouteCollection;\n\n$router-\u003eregister('/', function () {\n    return 'Hello world!'; \n});\n\n$router-\u003eregister('/{word}', function ($name) {\n    return sprintf('Hello %s, how are you today?', $name); \n});\n\n\n/**\n * Attempt to match the route based on the current URI.\n *\n * The returned result will then be output.\n */\n\ntry {\n    $result = $router-\u003ematch( $_SERVER['REQUEST_URI'] );\n} catch (UnmatchedRouteException $e) {\n    http_response_code(404);\n\n    $result = 'The requested resource could not be found!';\n}\n\nprint $result;\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp810%2Frouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fp810%2Frouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp810%2Frouter/lists"}