{"id":21771149,"url":"https://github.com/initphp/router","last_synced_at":"2025-04-13T16:41:25.451Z","repository":{"id":41142517,"uuid":"470087565","full_name":"InitPHP/Router","owner":"InitPHP","description":"This is an open source library that lets you create and manage advanced routes for HTTP requests.","archived":false,"fork":false,"pushed_at":"2023-03-20T12:33:08.000Z","size":96,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T07:35:52.524Z","etag":null,"topics":["php","php-route","php-router","php-routing","router"],"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/InitPHP.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":"2022-03-15T09:26:59.000Z","updated_at":"2024-11-05T15:16:10.000Z","dependencies_parsed_at":"2022-08-21T10:10:44.139Z","dependency_job_id":null,"html_url":"https://github.com/InitPHP/Router","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InitPHP%2FRouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InitPHP%2FRouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InitPHP%2FRouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InitPHP%2FRouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/InitPHP","download_url":"https://codeload.github.com/InitPHP/Router/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248747083,"owners_count":21155390,"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-route","php-router","php-routing","router"],"created_at":"2024-11-26T14:15:13.462Z","updated_at":"2025-04-13T16:41:25.425Z","avatar_url":"https://github.com/InitPHP.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# InitPHP Router\n\nThis is an open source library that lets you create and manage advanced routes for HTTP requests.\n\n[![Latest Stable Version](http://poser.pugx.org/initphp/router/v)](https://packagist.org/packages/initphp/router) [![Total Downloads](http://poser.pugx.org/initphp/router/downloads)](https://packagist.org/packages/initphp/router) [![Latest Unstable Version](http://poser.pugx.org/initphp/router/v/unstable)](https://packagist.org/packages/initphp/router) [![License](http://poser.pugx.org/initphp/router/license)](https://packagist.org/packages/initphp/router) [![PHP Version Require](http://poser.pugx.org/initphp/router/require/php)](https://packagist.org/packages/initphp/router)\n\n## Features\n\n- Full support for GET, POST, PUT, DELETE, OPTIONS, PATCH, HEAD and ANY request methods.\n- Variable request methods with (Laravel-like) `$_REQUEST['_method']`. (Default is off, optionally can be activated)\n- Controller support. (HomeController@about or HomeController::about)\n- Middleware/Filter (before and after) support.\n- Static and dynamic route patterns.\n- Ability to create custom parameter pattern.\n- Namespace support.\n- Route grouping support.\n- Domain-based routing support.\n- Ability to define custom 404 errors\n- Ability to name routes\n- Ability to call a class in (Symfony-like) callable functions or parameters of controller methods.\n- Routing by request ports.\n- Routing by client IP address (Via `$_SERVER['REMOTE_ADDR']`. Locally, this value can be something like `::1` or `127.0.0.1`.)\n- A directory path can be defined as a virtual link.\n\n## Requirements\n\n- PHP 7.2 or later\n- Apache is; **AllowOverride All** should be set to and **mod_rewrite** should be on.\n- Any library that implements the [Psr-7 HTTP Message Interface](https://www.php-fig.org/psr/psr-7/) and an emitter written for Psr-7. For example; [InitPHP HTTP](https://github.com/InitPHP/HTTP) Library\n\n## Installation\n\n```\ncomposer require initphp/router\n```\n\nIs Apache `.htaccess`\n\n```\nRewriteEngine On\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule ^(.*)$ index.php [L]\n```\n\nIs NGINX;\n\n```\nserver {\n\tlisten 80;\n\tserver_name myinitphpdomain.dev;\n\troot /var/www/myInitPHPDomain/public;\n\tindex index.php;\n\tlocation / {\n\t\ttry_files $uri $uri/ /index.php?$query_string;\n\t}\n\tlocation ~ \\.php$ {\n\t\tfastcgi_split_path_info ^(.+\\.php)(/.+)$;\n\t\tfastcgi_pass unix:/var/run/php7.4-fpm.sock;\n\t\tfastcgi_index index.php;\n\t\tinclude fastcgi.conf;\n\t\tfastcgi_intercept_errors on;\n\t}\n}\n```\n\n## Configuration\n\n```php\n$config = [\n    'paths'                 =\u003e [\n        'controller'            =\u003e null, //The full path to the directory where the Controller classes are kept.\n        'middleware'            =\u003e null, //The full path to the directory where the Middleware classes are kept.\n    ],\n    'namespaces'            =\u003e [\n        'controller'            =\u003e null, //Namespace prefix of Controller classes, if applicable.\n        'middleware'            =\u003e null, //Namespace prefix of Middleware classes, if applicable.\n    ],\n    'base_path'             =\u003e '/', // If you are working in a subdirectory; identifies your working directory.\n    'variable_method'       =\u003e false, // It makes the request method mutable with Laravel-like $_REQUEST['_method'].\n    'argument_new_instance' =\u003e false, // This configuration is used for Request and Response objects that you want as arguments.\n];\n```\n\n## Usage\n\nThe following example uses the [InitPHP HTTP](https://github.com/InitPHP/HTTP) library. If you wish, you can use this library using the command below, or you can perform similar operations using another library that uses the Psr-7 HTTP Message interface.\n\n```\ncomposer require initphp/http\n```\n\n_**See the Wiki for detailed documentation.**_\n\n```php\nrequire_once \"vendor/autoload.php\";\nuse \\InitPHP\\HTTP\\Message\\{Request, Response, Stream};\nuse \\InitPHP\\HTTP\\Emitter\\Emitter;\nuse \\InitPHP\\Router\\Router;\n\n$request = Request::createFromGlobals();\n$response = new Response();\n\n// Create the router object.\n$router = new Router($request, $response, []);\n\n// ... Create routes.\n$router-\u003eget('/', function () {\n    return 'Hello World!';\n});\n\n$router-\u003epost('/login', function (Request $request, Response $response) {\n    return $response-\u003ejson([\n        'status'        =\u003e 0,\n        'message'       =\u003e 'Unauthorized',\n    ], 401);\n});\n\n// If you do not make a definition for 404 errors; An exception is thrown if there is no match with the request.\n$router-\u003eerror_404(function () {\n    echo 'Page Not Found';\n});\n\n// Resolve the current route and get the generated HTTP response object.\n$response = $router-\u003edispatch();\n\n// Publish the HTTP response object.\n$emitter = new Emitter;\n$emitter-\u003eemit($response);\n```\n\n## Getting Help\n\nIf you have questions, concerns, bug reports, etc, please file an issue in this repository's Issue Tracker.\n\n## Getting Involved\n\n\u003e All contributions to this project will be published under the MIT License. By submitting a pull request or filing a bug, issue, or feature request, you are agreeing to comply with this waiver of copyright interest.\n\nThere are two primary ways to help:\n\n- Using the issue tracker, and\n- Changing the code-base.\n\n### Using the issue tracker\n\nUse the issue tracker to suggest feature requests, report bugs, and ask questions. This is also a great way to connect with the developers of the project as well as others who are interested in this solution.\n\nUse the issue tracker to find ways to contribute. Find a bug or a feature, mention in the issue that you will take on that effort, then follow the Changing the code-base guidance below.\n\n### Changing the code-base\n\nGenerally speaking, you should fork this repository, make changes in your own fork, and then submit a pull request. All new code should have associated unit tests that validate implemented features and the presence or lack of defects. Additionally, the code should follow any stylistic and architectural guidelines prescribed by the project. In the absence of such guidelines, mimic the styles and patterns in the existing code-base.\n\n## Credits\n\n- [Muhammet ŞAFAK](https://www.muhammetsafak.com.tr) \u003c\u003cinfo@muhammetsafak.com.tr\u003e\u003e\n\n## License\n\nCopyright \u0026copy; 2022 [MIT Licence](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finitphp%2Frouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finitphp%2Frouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finitphp%2Frouter/lists"}