{"id":21216880,"url":"https://github.com/lablnet/zestrouter","last_synced_at":"2026-03-08T13:40:05.467Z","repository":{"id":57010531,"uuid":"145532250","full_name":"lablnet/ZestRouter","owner":"lablnet","description":"ZestRouter is a small but powerful routing class for php","archived":false,"fork":false,"pushed_at":"2020-10-23T09:33:45.000Z","size":13,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-17T06:10:03.351Z","etag":null,"topics":["advance","class","free","oop","php","php7","routing"],"latest_commit_sha":null,"homepage":"","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/lablnet.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":"2018-08-21T08:31:39.000Z","updated_at":"2023-06-18T13:55:04.000Z","dependencies_parsed_at":"2022-08-21T15:10:14.579Z","dependency_job_id":null,"html_url":"https://github.com/lablnet/ZestRouter","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lablnet%2FZestRouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lablnet%2FZestRouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lablnet%2FZestRouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lablnet%2FZestRouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lablnet","download_url":"https://codeload.github.com/lablnet/ZestRouter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225637087,"owners_count":17500360,"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":["advance","class","free","oop","php","php7","routing"],"created_at":"2024-11-20T21:56:07.947Z","updated_at":"2026-03-08T13:40:05.438Z","avatar_url":"https://github.com/lablnet.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ZestRouter\n\nZestRouter is a small but powerful routing class for php\n\n```php\n\u003c?php \n\nuse Lablnet\\ZestRouter;\n\nrequire_once \"../vendor/autoload.php\";\n\n$router = new ZestRouter;\n\n//Namespaces uses for loading controllers olny\n//$router-\u003esetDefaultNamespace(\"App\\Controllers\\\\\");\n\n$router-\u003eget('', function () {\n    echo 'Example route using closure';\n});\n/*\n//OR\n$router-\u003eadd('', function () {\n    echo 'Example route using closure';\n},'GET');\n*/\n$router-\u003eget('test','Home@index');\n/*\n //OR\n $router-\u003eget('test',['controller' =\u003e 'Home', 'action' =\u003e 'index']);\n //OR\n  $router-\u003eadd('test',['controller' =\u003e 'Home', 'action' =\u003e 'index'],'GET');\n\n*/\n//Dispatch/Process the request automatically for mannually dispatch request take a look at Process Request section\n$router-\u003edispatch($_SERVER['QUERY_STRING']);\n\n```\n\n# Features\n\n- Can be used with all HTTP Methods\n- Flexible regular expression routing\n- Custom regexes\n- Router with controllers by namespaces\n- Routers using closure\n\n# install\n\nRun the command in terminal/cmd\n``` composer require lablnet/zestrouter ```\n\n# Getting started\n\n## Requirements\n\n- PHP 7 or newest\n- Composer\n\n## Rewrite all requests\n\n### Apache (.htaccess)\n\n```\n# Remove the question mark from the request but maintain the query string\nRewriteEngine On\n\n# Uncomment the following line if your public folder isn't the web server's root\n# RewriteBase /\n\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteCond %{REQUEST_FILENAME} !-l\nRewriteRule ^(.*)$ index.php?$1 [L,QSA]\n\n```\n\n### Nginx (nginx.conf)\n\n```\n\nlocation / { \n    if (!-f $request_filename){\n        set $rule_0 1$rule_0;\n    }   \n    if (!-d $request_filename){\n        set $rule_0 2$rule_0;\n    }\n    if ($rule_0 = \"21\"){\n        rewrite ^/(.*)$ /index.php?$1 last;\n    }   \n}\n\n```\n\n## Adding Routes\n\nBy now, you should have rewrite all requests\n\n### simple (default way)\nthere are many to two ways to add the routes\n\n#### Using add method\n```php\n\n    $router-\u003eadd('', function () {\n        echo \"Welcome\";\n    },'GET'); \n\n```\nThe `add()` method accepts the following parameters.\n\n`$route` (string)\nThis is the route pattern to match against. This can be a plain string, a custom regex.\n\n`$params` (array|string|Closure)\nThis is paramter for controllers and controller method or closure\n(array) =\u003e ['controller' =\u003e 'Home', 'action' =\u003e 'index'] \n(string) =\u003e \"Home@index\" \n(closure) =\u003e function () { echo \"Welcome\"; }\n\n`$method` (string)\nThis is a pipe-delimited string of the accepted HTTP requests methods.\n\nExample: GET|POST|PATCH|PUT|DELETE\n\n#### Using rests method\n```php\n\n    $router-\u003eget('', function () {\n        echo \"Welcome\";\n    }); \n\n```\nthere are 5 request methods supports\n`get(),post(),put(),patch(),delete()``\n\nThese methods accepts the following parameters.\n\n`$route` (string)\nThis is the route pattern to match against. This can be a plain string, a custom regex.\n\n`$params` (array|string|Closure)\nThis is paramter for controllers and controller method or closure\n(array) =\u003e ['controller' =\u003e 'Home', 'action' =\u003e 'index'] \n(string) =\u003e \"Home@index\" \n(closure) =\u003e function () { echo \"Welcome\"; }\n\n## Example adding the routes\n\n```php\n\n// add homepage using callable\n$router-\u003eget( '/home', function() {\n    require __DIR__ . '/views/home.php';\n});\n\n// add users details page using controller@action string\n$router-\u003eget( 'users/{id:[0-9]+}', 'UserController@showDetails' );\n\n```\nFor quickly adding multiple routes, you can use the addRoutes method. This method accepts an array or any kind of traversable.\n\n```php\n$router-\u003eaddRoutes(array(\n  array('users/{username:\\w+}', 'users@view', 'get'),\n  array('users/{id:\\d+}', 'users@update', 'PATCH'),\n  array('users/{id:\\d+}', 'users@delete', 'DELETE')\n));\n```\n\n\n# Matching Requests\n\nTo match the current request, just call the `customDispatch()` method without any parameters.\n\n``` php\n$match = $router-\u003ecustomDispatch();\n```\n\nIf a match was found, the `customDispatch()` method will return an associative array\n\n# Processing Requests\n\nZestRouter process requests for you but so you are free to use the method you prefer. To help you get started, here's a simplified example using closures.\n\n```php \n\n//Add the routes\n$router-\u003eget('', function () {\n    echo 'Example route using closure';\n});\n$router-\u003eget('user/{id:\\d+}', function ($args) {\n    echo 'Example route using closure with params id: ' .$args['id'];\n});\n\n// match current request url\n$match = $router-\u003ecustomDispatch();\nif ($match \u0026\u0026 is_callable( $match['callable'] )) {\n\tcall_user_func( $match['callable'], $match ); \n} else {\n\t// no route was matched\n\techo '404 Not Found';\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flablnet%2Fzestrouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flablnet%2Fzestrouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flablnet%2Fzestrouter/lists"}