{"id":21719955,"url":"https://github.com/ext/php-routes","last_synced_at":"2025-04-12T20:52:15.616Z","repository":{"id":20284321,"uuid":"23557661","full_name":"ext/php-routes","owner":"ext","description":"Routing for MVC-ish PHP projects.","archived":false,"fork":false,"pushed_at":"2025-04-07T14:32:55.000Z","size":242,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T20:52:09.341Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://php-routes.readthedocs.io/en/latest/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ext.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"COPYING","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}},"created_at":"2014-09-01T22:36:47.000Z","updated_at":"2025-04-07T14:31:13.000Z","dependencies_parsed_at":"2023-11-23T13:45:18.193Z","dependency_job_id":"ebc21c92-7296-4244-b946-cbeacc3f31f5","html_url":"https://github.com/ext/php-routes","commit_stats":{"total_commits":165,"total_committers":5,"mean_commits":33.0,"dds":"0.16969696969696968","last_synced_commit":"db4f590616f88f3c77fe70564393e77f8ea50a46"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ext%2Fphp-routes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ext%2Fphp-routes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ext%2Fphp-routes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ext%2Fphp-routes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ext","download_url":"https://codeload.github.com/ext/php-routes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248631728,"owners_count":21136560,"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-26T01:45:49.102Z","updated_at":"2025-04-12T20:52:15.593Z","avatar_url":"https://github.com/ext.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"PHP-routes\n==========\n\n[![PHP](https://github.com/ext/php-routes/actions/workflows/php.yml/badge.svg)](https://github.com/ext/php-routes/actions/workflows/php.yml) [![Coverage Status](https://coveralls.io/repos/github/ext/php-routes/badge.svg?branch=master)](https://coveralls.io/github/ext/php-routes?branch=master)\n[![Documentation](https://readthedocs.org/projects/pip/badge/?version=latest)](http://php-routes.readthedocs.io/en/latest/)\n\nRouting for MVC-ish PHP projects.\n\n    composer require sidvind/php-routes\n\nExample\n-------\n\nPut routes in a separate file, e.g. `routes.php`:\n\n```php\n\u003c?php\n/* basic routes */\n$get('foo', ['to' =\u003e 'MyController#foo']);\n$post('bar/:id/baz', ['to' =\u003e 'MyController#update']); /* use :var for variables */\n\n/* automatically setup RESTful routes */\n$resource('article', [], function($r){\n  $r-\u003emembers(function($r){\n    $r-\u003epatch('frobnicate'); /* maps to PATCH /article/:id/frobnicate */\n  });\n  $r-\u003ecollection(function($r){\n    $r-\u003epatch('twiddle'); /* maps to PATCH /article/twiddle */\n  });\n});\n\n/* scoping */\n$scope(':lang', [], function($r){\n  $r-\u003eget('barney'); /* maps to GET /:lang/barney */\n});\n```\n\nCreate a dispatcher:\n\n```php\n\u003c?php\nclass Dispatcher extends Sidvind\\PHPRoutes\\Router {\n\tpublic function dispatch($url, $method){\n\t\tif ( $match = $this-\u003ematch($url, $method) ){\n\t\t\t$class = \"{$match-\u003econtroller}Controller\";\n\t\t\t$controller = new $class();\n\t\t\treturn call_user_func_array([$controller, $match-\u003eaction], $match-\u003eargs);\n\t\t} else {\n\t\t  /* 404 */\n\t\t}\n\t}\n}\n$router = new Dispatcher('routes.php');\n$router-\u003edispatch($url, $method);\n```\n\nTo preview/debug routes use `bin/php-routes`:\n\n```\n# bin/php-routes routes.php\n        GET    /foo             MyController#foo      #^/foo(?P\u003cformat\u003e\\.\\w+)?$#\n        POST   /bar/:id/baz     MyController#update   #^/bar/(?P\u003cid\u003e[A-Za-z0-9\\-_\\.]+)/baz(?P\u003cformat\u003e\\.\\w+)?$#\narticle GET    /article         Article#list          #^/article(?P\u003cformat\u003e\\.\\w+)?$#\n...\n# bin/php-routes routes.php get /foo\nController: MyController\nAction: foo\nFormat:\nArguments:\n[]\n# bin/php-routes routes.php get /bar\nbin/php-routes: url doesn't match any route.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fext%2Fphp-routes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fext%2Fphp-routes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fext%2Fphp-routes/lists"}