{"id":26675549,"url":"https://github.com/sakibweb/phro","last_synced_at":"2025-03-26T03:18:41.278Z","repository":{"id":238563857,"uuid":"796825228","full_name":"sakibweb/PHRO","owner":"sakibweb","description":"PHRO is PHP Route / Router Library","archived":false,"fork":false,"pushed_at":"2024-09-17T19:44:20.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-18T00:15:32.277Z","etag":null,"topics":["php","php-route","php-router","route","router","sakibweb"],"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/sakibweb.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":"2024-05-06T17:46:20.000Z","updated_at":"2024-09-17T19:44:23.000Z","dependencies_parsed_at":"2024-05-06T19:02:12.299Z","dependency_job_id":"e898a0d5-6e40-4583-a83b-7e625f3f41c0","html_url":"https://github.com/sakibweb/PHRO","commit_stats":null,"previous_names":["sakibweb/phro"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakibweb%2FPHRO","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakibweb%2FPHRO/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakibweb%2FPHRO/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakibweb%2FPHRO/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sakibweb","download_url":"https://codeload.github.com/sakibweb/PHRO/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245579723,"owners_count":20638679,"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","route","router","sakibweb"],"created_at":"2025-03-26T03:18:40.786Z","updated_at":"2025-03-26T03:18:41.269Z","avatar_url":"https://github.com/sakibweb.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHRO\n### PHRO is PHP Route / Router Library\nPHRO is a comprehensive PHP Route/Router library class, PHRO, that allows for defining and handling HTTP routes in PHP applications.\n\n# Features\n### Route Matching:\n* The library supports defining routes for different HTTP methods (GET, POST, PUT, PATCH, DELETE) with the ability to add custom methods.\n* It uses URL pattern matching, including support for URL parameters (denoted by @param), to determine which route should be invoked based on the request URL and method.\n\n### Root URL Generation:\n* The root() function dynamically generates the base URL for the application, considering whether HTTPS is enabled.\n\n### Route Groups:\n* Organize routes into groups for better organization and code readability.\n\n### Parameter Extraction:\n* Automatically extract route parameters from the URL.\n\n### IP Information Fetching:\n* The fetchIPInfo() function gathers detailed IP information (private and public) from multiple external services. It maps API responses to a standard format, including location details (latitude, longitude), ISP, city, and country information.\n* If an API returns valid JSON data, it is processed and merged into the internal $params array for later use.\n\n### User Agent Parsing:\n* The userAgentInfo() function attempts to extract the browser and device information from the HTTP_USER_AGENT header using regular expressions for popular browsers such as Chrome, Firefox, Safari, Edge, Opera, and Internet Explorer.\n\n### URL Handling:\n* The library handles URL trimming and splitting based on / and supports dynamic routes using @param in the URL, allowing for flexible route definitions with parameters.\n\n### HTTP Request Handling:\n* Routes are matched against the current HTTP request method (GET, POST, etc.) and the URL pattern. If a route matches, the corresponding callback function is executed.\n* The method match() does the heavy lifting by comparing the requested URL and method to defined routes, supporting dynamic segments.\n\n### Curl for External API Requests:\n* It uses curl to send HTTP requests to external IP information services with a timeout mechanism for better reliability in case of delays or failures.\n\n### Error Handling:\n* Execute a callback function when no route is matched.\n\n### Encryption:\n* Encrypt and decrypt data using a secret key.\n\n# Usage\n### Creating PHRO Instance\nTo create a PHRO instance and define routes:\n```\nPHRO::initialize('/your/default/path'); // Optional: Set a default path for routes\n\nPHRO::key('your_secret_key'); // Set encryption key\n\nPHRO::get('/hello', function() {\n    echo \"Hello, World!\";\n});\nPHRO::post('/api/user', function() {\n    // Handle POST request to /api/user\n});\n```\n\n### Group Routes:\n```\nPHRO::group('/api', function() {\n    PHRO::get('/users', function($params) {\n        // Routes within this group will be prefixed with '/api'\n    });\n});\n```\n\n### Matching Routes\nPHRO matches routes based on URL patterns and HTTP methods:\n```\n// Define a route with parameters\nPHRO::get('/user/@id', function($params) {\n    $userId = $params['id'];\n    // Fetch user data based on $userId\n});\n\n// Listen for incoming requests\nPHRO::listen(function() {\n    echo \"404 Not Found\";\n});\n```\n### Handling Custom HTTP Methods\nYou can define routes for custom HTTP methods using the add() method:\n```\nPHRO::add('OPTIONS', '/api/user', function() {\n    // Handle OPTIONS request to /api/user\n});\n```\n### Handling 404 Not Found Errors\nYou can define a callback function to handle 404 Not Found errors:\n```\nPHRO::listen(function() {\n    echo \"404 Not Found\";\n});\n```\n### Displaying All Routes\nGet all defined routes with full link and method:\n```\nprint_r(PHRO::routes());\n```\n\n### Decryption:\nDecrypts encrypted data.\n```\n// Make sure set encryption key\nPHRO::key('your_secret_key');\n\n// Decrypt data\n$decryptedData = PHRO::decrypt($params['encryptdata']);\n```\n\n\n# Documentation:\n* PHRO::initialize(): Initializes the router with an optional default path.\n* PHRO::key(): Sets or retrieves the encryption key.\n* PHRO::root(): Returns the base URL of the application.\n* PHRO::get(): Defines a route for GET requests.\n* PHRO::post(): Defines a route for POST requests.\n* PHRO::put(): Defines a route for PUT requests.\n* PHRO::patch(): Defines a route for PATCH requests.\n* PHRO::delete(): Defines a route for DELETE requests.\n* PHRO::add(): Defines a route for a custom HTTP method.\n* PHRO::group(): Defines a group of routes with a shared prefix.\n* PHRO::routes(): Returns an array of defined routes.\n* PHRO::decrypt(): Decrypts encrypted data.\n\n# Note:\n* Replace your_secret_key with a strong, unique key.\n\nLet me know if you'd like to add more features or refine specific parts of this library!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsakibweb%2Fphro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsakibweb%2Fphro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsakibweb%2Fphro/lists"}