{"id":22477566,"url":"https://github.com/maplephp/handler","last_synced_at":"2026-02-08T17:05:32.957Z","repository":{"id":209894720,"uuid":"630979954","full_name":"MaplePHP/Handler","owner":"MaplePHP","description":"Router dispatcher and emitter","archived":false,"fork":false,"pushed_at":"2024-09-16T17:19:00.000Z","size":109,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-20T10:49:08.647Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MaplePHP.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-21T15:58:22.000Z","updated_at":"2023-11-29T17:15:52.000Z","dependencies_parsed_at":"2024-01-01T11:31:17.561Z","dependency_job_id":"43e608a7-de13-43d2-9bf9-de6521add2eb","html_url":"https://github.com/MaplePHP/Handler","commit_stats":null,"previous_names":["maplephp/handler"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/MaplePHP/Handler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaplePHP%2FHandler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaplePHP%2FHandler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaplePHP%2FHandler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaplePHP%2FHandler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MaplePHP","download_url":"https://codeload.github.com/MaplePHP/Handler/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaplePHP%2FHandler/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266253749,"owners_count":23900056,"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-12-06T14:11:33.758Z","updated_at":"2026-02-08T17:05:32.922Z","avatar_url":"https://github.com/MaplePHP.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MaplePHP - Handler \nMaplePHP is built upon **nikic/FastRoute**. It is possible you change it with you own preferences, but i do not really see why you would, becouse FastRoute works really great and uses regular expression for advanced users. You can add your routers in \"app/Http/Routes/web.php\".\n\nUsed in MaplePHP framework.\n\n### Structrue\n\nGroup\n```html\n@routes-\u003egroup([PATTERN], [CALLABLE], [MIDDELWARE]);\n@routes-\u003egroup([CALLABLE], [MIDDELWARE]);\n@routes-\u003egroup([CALLABLE]);\n```\n\nRouter\n```html\n@routes-\u003eget([PATTERN], [ [CLASS], [METHOD] ]);\n```\n\n### Self explainable example\nThis is a self explainable example for advanced users\n```php\n$routes-\u003egroup(\"[POSSIBLE_PATTERNS]\", function($routes) {\n    \n    // Router data - will inherit the group pattern and middlewares\n    $routes-\u003eget(\"[PATTERN]\", ['CLASS', \"METHOD\"]);\n\n\t// You can nest groups in infinity\n    $routes-\u003egroup(function($routes) {\n    \t// Router data - will inherit group and group parents patterns and middlewares\n\t\t$routes-\u003eget(\"[PATTERN]\", ['CLASS', \"METHOD\"]);\n\t\t$routes-\u003epost(\"[PATTERN]\", ['CLASS', \"METHOD\"]);\n\n    }, [\n\t    [Http\\Middlewares\\LoggedIn::class, \"privateZone\"],\n\t]);\n\n}, [\n    [\n    \tHttp\\Middlewares\\SessionStart::class,\n\t\tHttp\\Middlewares\\DomManipulation::class\n    ]\n]);\n\n```\n\n## How it works\n\n### Different router responses\n```php\n// Catch a GET response\n$routes-\u003eget(\"/{page:about}\", ['Http\\Controllers\\Pages', \"about\"]);\n\n// Catch a POST response\n$routes-\u003epost(\"/{page:about}\", ['Http\\Controllers\\Pages', \"about\"]);\n\n// Catch a PUT response\n$routes-\u003eput(\"/{page:about}\", ['Http\\Controllers\\Pages', \"about\"]);\n\n// Catch a DELETE response\n$routes-\u003edelete(\"/{page:about}\", ['Http\\Controllers\\Pages', \"about\"]);\n\n// Catch a Custom response\n$routes-\u003emap(\"CLI\",\"/{page:about}\", ['Http\\Controllers\\Pages', \"about\"]);\n\n// Catch a Multiple responses\n$routes-\u003emap([\"GET\", \"POST\"],\"/{page:about}\", ['Http\\Controllers\\Pages', \"about\"]);\n\n// Take control over all the HTTP request errors (404, 403...). If removed, MaplePHP will generically try to handle the error responses. \n$routes-\u003emap(\"*\", '[/{any:.*}]', ['Http\\Controllers\\HttpRequestError', \"handleError\"]);\n\n// Group \n$routes-\u003egroup(\"/{lang:en}\", function($routes) {\n\t$routes-\u003eget(\"/{page:about}\", ['Http\\Controllers\\Pages', \"about\"]);\n    $routes-\u003eget(\"/{page:contact}\", ['Http\\Controllers\\Pages', \"contact\"]);\n});\n```\n\n### Groups\nYou can easily group routers under a patter. Bellow for example will show the page/method **about** if you vist **example.com/en/about**.\n```php\n// Group under language /en\n$routes-\u003egroup(\"/{lang:en}\", function($routes) {\n\t$routes-\u003eget(\"/{page:about}\", ['Http\\Controllers\\Pages', \"about\"]);\n    $routes-\u003eget(\"/{page:contact}\", ['Http\\Controllers\\Pages', \"contact\"]);\n});\n\n// Group under language all possible languages\n$routes-\u003egroup(\"/{lang:[^/]+}\", function($routes) {\n\t$routes-\u003eget(\"/{page:about}\", ['Http\\Controllers\\Pages', \"about\"]);\n    $routes-\u003eget(\"/{page:contact}\", ['Http\\Controllers\\Pages', \"contact\"]);\n});\n```\n\n### Middlewares\nMiddleware is a software component that sits between the client and the server and acts as an intermediary. Middleware can perform various tasks such as authentication, authorization, caching, logging, error handling, and more. In more simpler terms Middlewares will quickly and easily extend you applications functionallity accross specified routers.\n\n```php\n$routes-\u003egroup(function($routes) {\n\t$routes-\u003eget(\"/{form:login}\", ['Http\\Controllers\\Users\\Login', \"form\"]);\n\n\t// You can nest groups in infinity\n\t$routes-\u003egroup(function($routes) {\n        // Router data - will inherit group and group parents patterns and middlewares\n        $routes-\u003eget(\"/{profile:profile}\", ['Http\\Controllers\\Examples\\PrivatePage', \"profile\"]);\n    }, [\n        [Http\\Middlewares\\LoggedIn::class, \"privateZone\"]\n    ]);\n\n}, [\n    Http\\Middlewares\\SessionStart::class,\n\tHttp\\Middlewares\\DomManipulation::class\n]);\n\n```\n\n### Patterns\nIt is possible to use Regular Expression (Regex). Form more information you can also [click here](https://github.com/nikic/FastRoute).\n\n#### In very simple applications you could write a pattern like this\n```html\n/param1\n/param1/param2/param3\n```\n\n#### But in more advanced applicaton it is good know some more advanced patterns:\nFind all, strings and numbers (counts as one parameter)\n```html\n[^/]+\n```\n\nAllow only numbers\n```html\n\\d+\n```\n\nFind everything for dynamic parameters \n```html\n.+\n```\nIF match or else\n```html\n(?:match|elseMatch)\n```\n\nIt is also highly recommended to attach a KEY to a pattern. With the example above you can write more complete routes like bellow.\n```html\n/{page:param1}\n/{page:[^/]+}\nOK: /about-us\nNOT_FOUND: /about-us/environment\n```\n\n```html\n/{page:[^/]+}/{subpagePage:[^/]+}\nOK: /about-us/environment\n```\n```html\n/{page:.+}\nOK: /about-us/environment\n```\n```html\n/{page-id:\\d+}\nOK: /5242\nNOT_FOUND: /about-us\n```\n```html\n/{product-id:\\d+}/{slug:[^/]+}\nOK: /5242/round-table\n```\n```html\n/{cat:.+}[/{pagination:pagin-\\d+}]\nOK: /cat1/cat2/.../cat5\nOK: /cat1/cat2/.../cat5/pagin-2\n```\n\n### Complete example\n```php\n$routes-\u003egroup(function($routes) {\n    // Will handle all HTTP request errors \n\t$routes-\u003emap(\"*\", '[/{any:.*}]', ['Http\\Controllers\\HttpRequestError', \"handleError\"]);\n\n    // Your routes\n\t$routes-\u003eget(\"/\", ['Http\\Controllers\\Examples\\Pages', \"start\"]);\n\t$routes-\u003eget(\"/{page:about}\", ['Http\\Controllers\\Examples\\Pages', \"about\"]);\n\n    \n    $routes-\u003egroup(function($routes) {\n        // Regular page with form\n        $routes-\u003eget(\"/{form:login}\", ['Http\\Controllers\\Users\\Login', \"form\"]);\n        // Open form in a modal with ajax call\n        $routes-\u003eget(\"/{form:login}/{model:model}\", ['Http\\Controllers\\Users\\Login', \"formModel\"]);\n        // Login request\n        $routes-\u003epost(\"/{form:login}\", ['Http\\Controllers\\Users\\Login', \"login\"]);\n\n    }, [\n        [Http\\Middlewares\\LoggedIn::class, \"publicZone\"],\n    ]);\n\n    $routes-\u003egroup(function($routes) {\n        // Will handle all HTTP request errors \n        $routes-\u003eget(\"/{profile:profile}\", ['Http\\Controllers\\Examples\\PrivatePage', \"profile\"]);\n\n    }, [\n        [Http\\Middlewares\\LoggedIn::class, \"privateZone\"]\n    ]);\n\n}, [\n    Http\\Middlewares\\SessionStart::class,\n\tHttp\\Middlewares\\DomManipulation::class\n]);\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaplephp%2Fhandler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaplephp%2Fhandler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaplephp%2Fhandler/lists"}