{"id":20089915,"url":"https://github.com/bugadani/routy","last_synced_at":"2025-10-17T01:17:07.078Z","repository":{"id":62497996,"uuid":"46424958","full_name":"bugadani/Routy","owner":"bugadani","description":"A PHP request router","archived":false,"fork":false,"pushed_at":"2016-02-15T08:30:34.000Z","size":28,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-13T02:43:17.465Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bugadani.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":"2015-11-18T14:44:05.000Z","updated_at":"2016-02-03T10:59:17.000Z","dependencies_parsed_at":"2022-11-02T12:00:32.790Z","dependency_job_id":null,"html_url":"https://github.com/bugadani/Routy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugadani%2FRouty","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugadani%2FRouty/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugadani%2FRouty/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugadani%2FRouty/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bugadani","download_url":"https://codeload.github.com/bugadani/Routy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241525430,"owners_count":19976709,"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":"2024-11-13T16:20:45.101Z","updated_at":"2025-10-17T01:17:02.043Z","avatar_url":"https://github.com/bugadani.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Routy\n=============\n\nRouty is a request routing library for PHP. It is designed to be simple to use.\n\nBasic usage\n-----------\n\nThe `Router` class is the central element of the library that provides a simple API for most of the simple use-cases.\nDefining a route is as easy as calling the method with the same name as the route's HTTP method and passing the path as a parameter.\n\n    $router = new Routy\\Router();\n    $router-\u003eget('this/path');\n\nAvailable methods are:\n\n * `get($path)`\n * `post($path)`\n * `put($path)`\n * `delete($path)`\n * `head($path)`\n\nYou can also define parameters in routes by wrapping a name in curly braces (e.g. `{parameterName}`).\nA parameter consists a name and a pattern. By default, a parameter matches anything that is not a forward slash character (`/`),\nbut this can be overridden in the parameter definition by adding the desired pattern after the name, separated by a colon (`;`). The parameter definition follows the syntax of PHP's built-in PREG engine.\nExample route that matches words as parameter: `hello/{name:\\w+}`.\n\n*Note*: Routes are identified by their parameters' patterns, not their names. Because of this, two routes may be similar in structure if they have different parameter patterns.\n\nRouting the request is done with `match(Request $request)` or `matchCurrentRequest`. This will either throw an exception or return a `Match` instance that holds information about the matched route.\n\nUsing `add`, a route can be defined for multiple HTTP methods at once. To do this, pass the desired method names separated by a pipe ('|') character as the first argument.\n\n    $router-\u003eadd('GET|POST', 'some/path');\n\n### Options\n\nThe above methods return an instance of `Routy\\Initializers\\RouteInitializerInterface` which can be used to set names\nto the routes, specify a callback that will be called if a route is matched or to set extra information.\n\nA more full route definition looks like this:\n\n    $router-\u003eget('some/path')\n           -\u003ename('demoRoute')\n           -\u003eonMatch(function($name) { echo 'Hello ' . $name; })\n           -\u003eextras(['name' =\u003e 'World']);\n\n * `setName($name)`\n * `onMatch(callback)`: Because using the `Match` object that is returned by `match` can be cumbersome, a callback function can be supplied for each route that will be called when the route is matched.\n * `extras(array $extras)`: Sets extra information to the route in the form of a key-value pair.\n\n*Note*: adding routes for multiple methods create multiple separate routes. Because one route name can not belong to multiple routes,\nwhen using add to define multiple routes, setting the name using the returned Initializer will throw an exception.\n\n### Route callbacks\n\nUsing `onMatch` a callback can be defined for the routes. This is the easiest way to decide, which route was matched and what action should be taken.\nBy default, the callback will receive the matched parameters (and extras set on the route) in the parameter list. Parameters are passed by their names and are actually optional.\n\n    $callback = function($name = 'World') {echo 'Hello, ' . $name . '!';};\n    $router-\u003eget('hello)')-\u003eonMatch($callback);\n    $router-\u003eget('hello/me)')-\u003eextras('name' =\u003e 'Daniel')-\u003eonMatch($callback);\n    $router-\u003eget('hello/{name)')-\u003eonMatch($callback);\n\nThe mapping of the parameters are done by an instance of `Routy\\Invokers\\DelegateInterface` and the default\nbehaviour can be overridden by supplying a subclass of this interface to `onMatch` that wraps the callback function.\n\n### Generating URL-s\n\nUsing named routes, Routy can also generate URLs via the `to($routeName, array $parameters)` method. All of the route's parameters\nmust be supplied as the second argument, and extra ones will be appended to the URL as further GET parameters.\n\n    $router-\u003eget('hello/{name}')-\u003ename('hello');\n    echo $router-\u003eto('hello', ['name' =\u003e 'World', 'extra' =\u003e 'hi']); //prints \"hello/World?extra=hi\"\n\n### Resources\n\nRouty supports [Rails-like](http://guides.rubyonrails.org/routing.html#resource-routing-the-rails-default) resources.\nA resource can be defined by using `resource($name)`, or `resources($singularName, $pluralName)`.\n\n### Notes on HHVM\n\nRouty is tested on HHVM 3.6.6 and it is found that the basic function of the library works with one exception:\nSince route generation happens in an object's destructor, any exception thrown in there will crash the whole script.\nThis is not an issue in PHP, but the HHVM actually issues a fatal error in this case, which makes the thrown exceptions\nfatal and not catchable.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbugadani%2Frouty","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbugadani%2Frouty","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbugadani%2Frouty/lists"}