{"id":20555670,"url":"https://github.com/attogram/router","last_synced_at":"2025-03-06T06:40:31.058Z","repository":{"id":62489419,"uuid":"115221970","full_name":"attogram/router","owner":"attogram","description":"Attogram Router for PHP 7 - small, flexible, and surprisingly powerful.","archived":false,"fork":false,"pushed_at":"2020-06-15T12:56:28.000Z","size":239,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-17T05:19:47.889Z","etag":null,"topics":["attogram-router","no-dependencies","one-class","php-router","php-router-standalone","php-routing","php7","router"],"latest_commit_sha":null,"homepage":"https://getitdaily.com/attogram-router/","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/attogram.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"attogram","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2017-12-23T21:09:04.000Z","updated_at":"2020-02-15T17:00:19.000Z","dependencies_parsed_at":"2022-11-02T11:15:26.591Z","dependency_job_id":null,"html_url":"https://github.com/attogram/router","commit_stats":null,"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/attogram%2Frouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/attogram%2Frouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/attogram%2Frouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/attogram%2Frouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/attogram","download_url":"https://codeload.github.com/attogram/router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242163848,"owners_count":20082224,"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":["attogram-router","no-dependencies","one-class","php-router","php-router-standalone","php-routing","php7","router"],"created_at":"2024-11-16T03:19:51.158Z","updated_at":"2025-03-06T06:40:31.039Z","avatar_url":"https://github.com/attogram.png","language":"PHP","readme":"# Attogram Router\n\nWelcome to the Attogram Router for PHP 7 -\nsmall, flexible, and surprisingly powerful.\n\n[![Attogram Router](https://raw.githubusercontent.com/attogram/attogram-docs/master/router/attogram.router.250.png)](https://github.com/attogram/router)\n\n[![Maintainability](https://api.codeclimate.com/v1/badges/95f2868eeb1ed710b794/maintainability)](https://codeclimate.com/github/attogram/router/maintainability)\n[![Build Status](https://travis-ci.org/attogram/router.svg?branch=master)](https://travis-ci.org/attogram/router)\n[![Latest Stable Version](https://poser.pugx.org/attogram/router/v/stable)](https://packagist.org/packages/attogram/router)\n[![Total Downloads](https://poser.pugx.org/attogram/router/downloads)](https://packagist.org/packages/attogram/router)\n\nComposer: `composer require attogram/router`\n\nGit: `git clone https://github.com/attogram/router.git`\n\nDownload: `https://github.com/attogram/router/archive/master.zip`\n\nLicense: `MIT`\n\n## Examples\n\n* live demo: \u003chttps://getitdaily.com/attogram-router/\u003e\n* demo source: \u003chttps://github.com/attogram/router/tree/master/examples\u003e\n\n## Usage\n\nSetup URL rewriting. For example with Apache `.htaccess`:\n\n```\nOptions +FollowSymLinks\nRewriteEngine On\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteRule ^ index.php [L]\n```\n\nCreate your `index.php`.  For example:\n\n```php\nuse Attogram\\Router\\Router;\n\nrequire_once('/path/to/vendor/autoload.php');\n\n$router = new Router();\n\n// Allow routes\n$router-\u003eallow('/', 'home');\n$router-\u003eallow('/foo/bar', 'foobar');\n$router-\u003eallow('/pi', 3.141);\n$router-\u003eallow('/hello', function () { print 'world'; });\n$router-\u003eallow('/book/?/chapter/?', function (Router $router) {\n    $book = $router-\u003egetVar(0);\n    $chapter = $router-\u003egetVar(1);\n});\n\n// Get the $control that matches the current request\n$control = $router-\u003ematch();\n\n// If no match, $control is null\nif (!$control) {\n    header('HTTP/1.0 404 Not Found');\n    exit;\n}\n\n// Now dispatch based on $control, in whatever manner you wish\n```\n\n## Public Functions\n\n### allow\n\n`public function allow(string $route, $control)`\n\n* Allow and set a control for a route\n* $route = a string with the URI list, forward-slash delimited\n  * Exact routing:\n    * Home:  '/'\n    * Page:  '/foo/bar'\n      * preceding and trailing slashes are optional, except for top level '/'\n  * Variable routing:\n    * use a question mark to denote a URI segment as a variable\n    * variables are retrieved via `$router-\u003egetVar(int $index)`\n    * Examples:\n      * '/id/?' - retrieve with `getVar(0)`\n      * '/book/?/chapter/?' - retrieve with `getVar(0)` and `getVar(1)`\n      * '/foo/?/?/?' - retrieve with `getVar(0)`, `getVar(1)` and `getVar(2)`\n* $control = anything you want\n  * a string, a closure, an array, an object, an int, a float, whatever!\n\n### match\n\n`public function match()`\n\n* Get the control for the current request, or null if no matching request\n\n### getVar\n\n`public function getVar(int $index = 0)`\n\n* Get a URI segment variable, by index.  Starting at 0.\n\n### getHome\n\n`public function getHome(): string`\n\n* Get URL to the installation home\n\n### getHomeFull\n\n`public function getHomeFull(): string`\n\n* Get URL to the installation home, with protocol and host\n\n### getCurrent\n\n`public function getCurrent(): string`\n\n* Get URL to the current request\n\n### getCurrentFull\n\n`public function getCurrentFull(): string`\n\n* Get URL to the current request,  with protocol and host\n\n### setForceSlash\n\n`public function setForceSlash(bool $forceSlash)`\n\n* Sets the optional forcing of a trailing slash on all requests\n* by default is false\n\n### redirect\n\n`redirect(string $url, int $httpResponseCode = 301, bool $exitAfter = true)`\n\n* Redirect to a new url and exit\n* optionally set a response code (301 = permanent, 302 = moved)\n\n### getGet\n\n`public function getGet(string $name = '')`\n\n* Get a global `_GET` variable, or empty string if not found\n\n### getPost\n\n`public function getPost(string $name = '')`\n\n* Get a global `_POST` variable, or empty string if not found\n\n### getServer\n\n`public function getServer(string $name = '')`\n\n* Get a global `_SERVER` variable, or empty string if not found\n\n### getHost\n\n`public function getHost(): string`\n\n* Get the current hostname\n\n### getHostFull\n\n`public function getHostFull(): string`\n\n* Get the current hostname, with protocol and host\n\n### getProtocol\n\n`public function getProtocol(): string`\n\n* Get the current protocol: `http` or `https`\n\n----\n","funding_links":["https://github.com/sponsors/attogram"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fattogram%2Frouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fattogram%2Frouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fattogram%2Frouter/lists"}