{"id":15296374,"url":"https://github.com/d0niek/routing","last_synced_at":"2026-02-08T17:02:41.602Z","repository":{"id":56980684,"uuid":"107796469","full_name":"d0niek/routing","owner":"d0niek","description":"Routing component to resolve Uri path","archived":false,"fork":false,"pushed_at":"2017-10-22T20:45:24.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-18T05:37:06.149Z","etag":null,"topics":["php","php71","routing","uri-path"],"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/d0niek.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":"2017-10-21T16:30:24.000Z","updated_at":"2019-10-10T19:42:50.000Z","dependencies_parsed_at":"2022-08-21T10:50:28.304Z","dependency_job_id":null,"html_url":"https://github.com/d0niek/routing","commit_stats":null,"previous_names":["extalionteam/routing"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/d0niek/routing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d0niek%2Frouting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d0niek%2Frouting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d0niek%2Frouting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d0niek%2Frouting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/d0niek","download_url":"https://codeload.github.com/d0niek/routing/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d0niek%2Frouting/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29237080,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-08T14:18:14.570Z","status":"ssl_error","status_checked_at":"2026-02-08T14:18:14.071Z","response_time":57,"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":["php","php71","routing","uri-path"],"created_at":"2024-09-30T18:10:16.426Z","updated_at":"2026-02-08T17:02:41.568Z","avatar_url":"https://github.com/d0niek.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Routing\n\nRouting component to resolve Uri path\n\n## Install\n```bash\ncomposer require extalion/routing\n```\n\n## Route\nIt's a class which represent the request method and Uri path. Also it store a knowledge what controller class create to handle the request.\n```php\nuse eXtalion\\Component\\Routing\\Route;\n\n$route = new Route\\{Method}(\n    $uriPath,\n    $fullnameControllerClass\n);\n```\nwhere:\n *  **{Method}** is a class name which represent request method. Available classnames/request methods:\n  *  `Get`,\n  *  `Post`,\n  *  `Put`,\n  *  `Update`,\n  *  `Delete`,\n *  **$uriPath** is a valid Uri path which can contain parameters (see example),\n * **$fullnameControllerClass** self explanatory name :-)\n\n### Example:\n```php\nnew Route\\Get('/', HomeController::class);\nnew Route\\Get('/user', UserController::class);\nnew Route\\Put('/user', User\\SaveController::class);\nnew Route\\Delete('/user/delete/{id}', User\\DeleteController::class);\nnew Route\\Delete('/user/delete/all', User\\CleanUpController::class);\n```\nRoute `DELETE:/user/delete/{id}` has a parameter `id` and that means this route will match to this requests (all of them has **DELETE** method request):\n```bash\nexample.com/user/delete/1\nexample.com/user/delete/4\nexample.com/user/delete/nsgfg3\nexample.com/user/delete/...\n```\nbut request `example.com/user/delete/all` will be match to route `DELETE:/user/delete/all`. You don't have to care about order of defining routes, constant path are always before \"parameters\" path.\n\nIf your controller class has any dependencies you can put them to array as third parameter:\n```php\n$postRepository = new Repository\\Post\\Pdo(...);\n$mailer = new Mailer\\Swift(...);\n\nnew Route\\Put(\n    '/post',\n    PostController::class,\n    [\n        $postRepository,\n        'some_string_parameter',\n        $mailer,\n    ]\n);\n```\n\nTo extract parameters from Uri path call the method `Route::extractParameters($uriPath)`:\n```php\n$route = new Route\\Get('/post/{id}/{action}', PostController::class);\n\n$parameters = $route-\u003eextractParameters('/post/3/show');\n\nvar_dump($parameters);\n\n// array(2) {\n//   'id' =\u003e string(1) \"3\"\n//   'action' =\u003e string(4) \"show\"\n// }\n```\nYou can validate your parameters during extracting them from path:\n```php\n$route = new Route\\Get(\n    '/post/{id}/{action}/{language}',\n    PostController::class,\n    [],\n    [\n        'id' =\u003e function (string $id): int {\n            return (int) $id;\n        },\n        'action' =\u003e function (string $action): string {\n            return $action . '.php';\n        }\n    ]\n);\n\n$parameters = $route-\u003eextractParameters('/post/3/show/pl');\n\nvar_dump($parameters);\n\n// array(2) {\n//   'id' =\u003e int(3)\n//   'action' =\u003e string(8) \"show.php\"\n//   'language' =\u003e string(2) \"pl\"\n// }\n```\n\n### New request method route\nIf you want to add new request method route you have to create new class and extends `\\eXtalion\\Component\\Routing\\Route`.\n\n## Router (\\\\Basic)\nIt's a class which handle a `\\Psr\\Http\\Message\\RequestInterface` and return `Route` which match to requested method and Uri path.\n\n### Example\n```php\nuse eXtalion\\Component\\Routing\\Router;\n\n$router = new Router\\Basic(\n    new Route\\Get(...),\n    new Route\\Get(...),\n    new Route\\Post(...),\n    ...\n);\n\n$request = ... // Something what return \\Psr\\Http\\Message\\RequestInterface\n\n$route = $router-\u003ehandle($request);\n```\nIf you try to add two routes which match exactly to the same Uri Path, `\\eXtalion\\Component\\Routing\\Exception\\RouteConflict` will be thrown.\n```php\ntry {\n    $router = new Router\\Basic(\n        new Route\\Get('/user/{id}', ...),\n        new Route\\Get('/user/{login}', ...)\n    );\n} catch (RouteConflict $ex) {\n    echo $ex-\u003egetMessage();\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd0niek%2Frouting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fd0niek%2Frouting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd0niek%2Frouting/lists"}