{"id":23806832,"url":"https://github.com/mattvb91/lightrouter","last_synced_at":"2025-11-11T04:32:24.764Z","repository":{"id":62525379,"uuid":"95302751","full_name":"mattvb91/LightRouter","owner":"mattvb91","description":"Lightweight PHP Router","archived":false,"fork":false,"pushed_at":"2017-06-28T16:26:26.000Z","size":17,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-01T23:15:29.069Z","etag":null,"topics":["php","php-library","php-router","php7"],"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/mattvb91.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}},"created_at":"2017-06-24T14:30:50.000Z","updated_at":"2022-08-06T07:22:46.000Z","dependencies_parsed_at":"2022-11-02T15:31:02.199Z","dependency_job_id":null,"html_url":"https://github.com/mattvb91/LightRouter","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattvb91%2FLightRouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattvb91%2FLightRouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattvb91%2FLightRouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattvb91%2FLightRouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattvb91","download_url":"https://codeload.github.com/mattvb91/LightRouter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240059747,"owners_count":19741717,"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":["php","php-library","php-router","php7"],"created_at":"2025-01-01T23:15:51.449Z","updated_at":"2025-11-11T04:32:24.736Z","avatar_url":"https://github.com/mattvb91.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cb\u003eLightRouter\u003c/b\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src='https://coveralls.io/repos/github/mattvb91/LightRouter/badge.svg?branch=master'/\u003e\n  \u003cimg src=\"https://travis-ci.org/mattvb91/LightRouter.svg?branch=master\"\u003e\n  \u003cimg class=\"latest_stable_version_img\" src=\"https://poser.pugx.org/mattvb91/lightrouter/v/stable\"\u003e\n  \u003cimg class=\"total_img\" src=\"https://poser.pugx.org/mattvb91/lightrouter/downloads\"\u003e\n  \u003cimg class=\"latest_unstable_version_img\" src=\"https://poser.pugx.org/mattvb91/lightrouter/v/unstable\"\u003e\n  \u003cimg class=\"license_img\" src=\"https://poser.pugx.org/mattvb91/lightrouter/license\"\u003e\n\u003c/p\u003e\n\n## LightRouter\n\nLightweight PHP router class. This is a test project. If you need a reliable \u0026 fully\ntested solution please check out FastRoute or AltoRouter.\n\n### Basic Usage\n\n```php\n$router = new mattvb91\\LightRouter\\Router();\n$router-\u003eaddRoute('/', MyController::class);\n$router-\u003erun();\n```\n\n### Defining Routes\n\nTo add new routes use the ```$router-\u003eaddRoute()``` method. If no action is defined\nit will default to ```index``` which will be needed on your controller.\n\nYou will need to pass the route path \u0026 either a controller or a closure. If you do\nnot specify an action it will default to 'index' which will be required on \nyour controller.\n\n```php\n$router-\u003eaddRoute('/', MyController::class);\n$router-\u003eaddRoute('/contact', MyController::class, 'contact');\n\n$route-\u003eaddRoute('/hello', function() {\n    echo 'Hello world';\n});\n```\n\n### Defining parameters\n\nPassing parameters into your controller actions can be done using a `:parameter` attribute\nin your route definition:\n```php\n$router-\u003eaddRoute('/view/:param', MyController::class);\n\n```\n\nYour method parameter must match the defined route parameter. In our example above \nour controllers ```view``` method would look like this:\n\n```php\npublic function view($param)\n{\n}\n```\n\n### Automatically Injecting Models\n\nIf you are using the ```LightModel``` ORM package for your DB models you can automatically\ninject the associated model by specifying the instance type in your \ncontroller action:\n\n```php\n//Your route definition\n$router-\u003eaddRoute('/user/view/:user', UserController::class, 'view');\n\n//In your UserController::class\npublic function view(User $user)\n{\n    //$user is already fully loaded for you.\n}\n```\nIf you are using your own ORM or other DB model class you can also implement \nthe ```LightRouteModelInterface::class``` in your custom model which expects\nyou to return the fully loaded instance. \n\nLightRouter will pass the associated $key from your route into the ```getForLightRoute``` method:\n\n```php\npublic class CustomModel implements LightRouteModelInterface\n{\n    public static function getForLightRoute($routeParam): LightRouteModelInterface\n    {\n        //Use $routeParam to load your model class and return the instance\n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattvb91%2Flightrouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattvb91%2Flightrouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattvb91%2Flightrouter/lists"}