{"id":27117109,"url":"https://github.com/a904guy/link-hack","last_synced_at":"2026-01-20T19:31:59.059Z","repository":{"id":17995892,"uuid":"21007247","full_name":"a904guy/Link-Hack","owner":"a904guy","description":"Link-Hack is a Hack Lang HHVM version of Amanpreet Singh's Simple PHP Router","archived":false,"fork":false,"pushed_at":"2017-08-12T21:18:03.000Z","size":23,"stargazers_count":15,"open_issues_count":1,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-17T10:22:40.618Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://hawkins.app/","language":"Hack","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/a904guy.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":"2014-06-19T16:23:23.000Z","updated_at":"2023-08-29T10:59:46.000Z","dependencies_parsed_at":"2022-09-04T15:40:32.863Z","dependency_job_id":null,"html_url":"https://github.com/a904guy/Link-Hack","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a904guy%2FLink-Hack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a904guy%2FLink-Hack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a904guy%2FLink-Hack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a904guy%2FLink-Hack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/a904guy","download_url":"https://codeload.github.com/a904guy/Link-Hack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247601457,"owners_count":20964864,"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":"2025-04-07T05:54:01.214Z","updated_at":"2026-01-20T19:31:59.044Z","avatar_url":"https://github.com/a904guy.png","language":"Hack","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Link-Hack is a __Hack Lang HHVM version__ of Amanpreet Singh's __minimal__ PHP Router https://github.com/apsdehal/Link\nA __minimal__ router for your webapps and APIs that effortlessly links all of your project. Its fast and to the point.\n\n# Features\n- RESTful routing\n- Wildcards to help simplify writing routes\n- Regex routes to unleash any possibility\n- Named routes to help you create links easily\n- Before and after routes function support\n- Tested with Ubuntu 14.04, hhvm 3.2.0-dev+2014.06.18 (rel), nginx 1.4.6\n\n# Dependencies\n\n## Hack HHVM\nhttp://docs.hhvm.com/manual/en/install.php\n\n## Nginx\nhttp://wiki.nginx.org/Install\n\n# Install\n\n## Manual Include\n\n```php\n\trequire(\"Link-Hack/src/Link.hh\");\n```\n\n## Composer\n\n```bash\n\tcomposer require link-hack/router\n```\n\n# Config\n\n## Nginx\n```\nserver {\n        listen 80 default_server;\n        listen [::]:80 default_server ipv6only=on;\n\n        root /path/Link-Hack/src/; # Changet to path of your environment\n        server_name _; #catchall\n\n\tif (!-e $request_filename)\n\t{\n\t        rewrite ^/(.*)$ /YourRouter.hh?/$1 last;\n        \tbreak;\n\t}\n\n        location / {\n\n        root /path/Link-Hack/src/; # Changet to path of your environment\n        fastcgi_pass   127.0.0.1:9000; #Whatever HHVM daemon is set to run on.\n        # or if you used a unix socket\n        # fastcgi_pass   unix:/var/run/hhvm/hhvm.sock;\n        fastcgi_index  YourRouter.hh;\n        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;\n        include        fastcgi_params;\n\n        }\n\n}\n```\n\n# Basics\n\n## Simple Routing\n\n```php\n\nfunction routeMe(): void\n{\n\techo 'I am routed';\n}\n\nLink::all( Map{\n\t'/' =\u003e Map{'routeMe' =\u003e []}\n});\n```\n\n## Named Routing\n\nIn Link-Hack routes can be named and then further used generating links in a simple and elegant way.\n\n\n```php\n\nfunction nameMe() :void\n{\n\techo 'I am named';\n}\n\nLink::all( Map{\n\t'/named' =\u003e Map{'nameMe' =\u003e [], 'Its my name' =\u003e []}\n});\n```\n\nNames to routes must be given as second argument in array while the first being the route handler.\n\n### Usage\n\nThese named routes can be used in creating in hassle free links.\n\n```html\n\t\u003ca href=\"\u003c?hh echo Link::route('Its my name') ?\u003e\"\u003eGo to named route\u003c/a\u003e\n```\n\n## Routing with classes\n\nLink can handle classes as Route handler easily, but remember non-static class will be handled both on construct and RESTfully.\n\n```php\n\n$routes = Map{\n\t'/' =\u003e Map{'IndexController::getMeHome' =\u003e []}, // Static function\n\t'/home' =\u003e  Map{'HomeController' =\u003e []}, // Class\n\t'/office' =\u003e  Map{'OfficeController' =\u003e []} // Class\n});\n\nLink::all($routes);\n\n```\n\n## RESTful routing\n\nRESTful routing is a breeze for Link-Hack.\n\n```php\n\nclass HomeController\n{\n\t\n\tfunction get() :void\n\t{\n\t\techo 'You have got to home :)';\n\t}\n\n\tfunction post() :void\n\t{\n\t\techo 'You have posted to home';\n\t}\n\n\tfunction put() :void\n\t{\n\t\techo 'You have put to home';\n\t}\n\n\tfunction delete() :void\n\t{\n\t    echo 'You have deleted the home :(';\n\t}\n}\n\nLink::all( Map{\n\t'/' =\u003e Map{'HomeController' =\u003e [], 'HomeRoute' =\u003e []}\n});\n```\n\n# Dynamic Routes\n\n## Regex Shorthands\n\nLink-Hack supports numbers, string and alphanumeric wildcards which can be used as `{i} {s} {a}` respectively.\n\n```php\n$routes = Map{\n\t'/' =\u003e Map{'IndexController' =\u003e []},\n\t'/{i}' =\u003e Map{'IndexController' =\u003e []},\n\t\t// Parameter in place of {i} will be passed to IndexController\n\t'/posts/{a}/{i}/{s}' =\u003e Map{'PostsController' =\u003e []}\n};\n\nLink::all($routes);\n```\n\n## Pure Regex\n\nLink-Hack supports writing your own regex based routes.\n\n```php\n$routes = Map{\n\t'/regex/([\\d]+)/([a-zA-Z]+)/([a-zA-Z]+)' =\u003e Map{'regexController' =\u003e []}\n};\n\nLink::all($routes);\n```\n\n## Supplementary Handlers\n\nThrough Link-Hack, universal before and after handlers can be added, such that these are executed always before and after any route is routed. This can be done as follows:\n\n```php\n\nfunction universalBeforeHandler( $id ) :void\n{\n    echo 'Hello I occurred before with ' . $id . '\\n';\n}\n\nfunction universalAfterHandler( ?$id ) :void\n{\n    if( $id )\n        echo 'Hello I occurred after with ' . $id;\n    else\n        echo 'I simply occurred after';\n}\n\nfunction main() :void\n{\n    echo 'I simply occurred\\n'\n}\n\nLink::before( Map{'universalBeforeHandler' =\u003e array('12')} ); // If you want to pass parameters to them, pass them as arrays\nLink::after( Map{'universalAfterHandler' =\u003e []} ); // else just don't specify them.\n\nLink::all( Map{\n    '/' =\u003e Map{'main' =\u003e []}\n})\n```\n\nNow go to '/' in your browser to find:\n\n```sh\nHello I occurred before with 12\n\nI simply occurred\n\nI simply occurred after.\n```\n\n## Passing Parameters to Named Routes\n\nYou can pass parameters to named routes if the have wildcards in the route path, this will thus generate dynamic links through a single named route.\n\n```php\n\nfunction nameMe( $i, $s ) :void\n{\n\techo 'I am named and I have been passed ' . $i . $s ;\n}\n\nLink::all( Map{\n\t'/named/{i}/{s}' =\u003e Map{'nameMe' =\u003e [], 'Its my name' =\u003e []}\n});\n```\n\nNow generate a link through Link\n\n```php\n\necho Link::route( 'Its my name', array(1, 'Me') );\n```\n\nThis in turn will generate `/named/1/Me` and the browser will return `I am named and I have been passed 1Me`\n\n## [404,500] Errors\n\nYou should probably add a 404 handler to your routes Map, Link will take care of handling routes that are not found. In case, Link-Hack doesn't find a 404/500 route defined, it will just send the appropriate header. The 500 route will be executed if there is any exceptions thrown from the controllers/methods/functions/closure called.\n\n```php\n\nfunction notFound() :void\n{\n\techo 'This page is missing';\n}\n\nfunction errorFound() :void\n{\n\techo 'Oops, something went wrong, try again later';\n}\n\nfunction mainPage() :void\n{\n\tthrow new Exception('Meh? :(');\n}\n\nLink::all( Map{\n\t'/' =\u003e Map{'mainPage' =\u003e []},\n\t'404' =\u003e Map{'notFound' =\u003e []},\n\t'500' =\u003e Map{'errorFound' =\u003e []}\n});\n```\n\n# License\n### Creative Commons Attribution-ShareAlike 3.0 Unported\nhttp://creativecommons.org/licenses/by-sa/3.0/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa904guy%2Flink-hack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fa904guy%2Flink-hack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa904guy%2Flink-hack/lists"}