PHPackages                             link-hack/router - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. link-hack/router

ActiveLibrary[Framework](/categories/framework)

link-hack/router
================

Link-Hack is a Hack Lang HHVM version of Amanpreet Singh's Simple PHP Router

1623[1 issues](https://github.com/a904guy/Link-Hack/issues)Hack

Since Aug 12Pushed 8y ago3 watchersCompare

[ Source](https://github.com/a904guy/Link-Hack)[ Packagist](https://packagist.org/packages/link-hack/router)[ RSS](/packages/link-hack-router/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (1)Used By (0)

Link-Hack is a **Hack Lang HHVM version** of Amanpreet Singh's **minimal** PHP Router
------------------------------------------------------------------------------------------------------------------------

[](#link-hack-is-a-hack-lang-hhvm-version-of-amanpreet-singhs-minimal-php-router-httpsgithubcomapsdehallink)

A **minimal** router for your webapps and APIs that effortlessly links all of your project. Its fast and to the point.

Features
========

[](#features)

- RESTful routing
- Wildcards to help simplify writing routes
- Regex routes to unleash any possibility
- Named routes to help you create links easily
- Before and after routes function support
- Tested with Ubuntu 14.04, hhvm 3.2.0-dev+2014.06.18 (rel), nginx 1.4.6

Dependencies
============

[](#dependencies)

Hack HHVM
---------

[](#hack-hhvm)

Nginx
-----

[](#nginx)

Install
=======

[](#install)

Manual Include
--------------

[](#manual-include)

```
	require("Link-Hack/src/Link.hh");
```

Composer
--------

[](#composer)

```
	composer require link-hack/router
```

Config
======

[](#config)

Nginx
-----

[](#nginx-1)

```
server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /path/Link-Hack/src/; # Changet to path of your environment
        server_name _; #catchall

	if (!-e $request_filename)
	{
	        rewrite ^/(.*)$ /YourRouter.hh?/$1 last;
        	break;
	}

        location / {

        root /path/Link-Hack/src/; # Changet to path of your environment
        fastcgi_pass   127.0.0.1:9000; #Whatever HHVM daemon is set to run on.
        # or if you used a unix socket
        # fastcgi_pass   unix:/var/run/hhvm/hhvm.sock;
        fastcgi_index  YourRouter.hh;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;

        }

}

```

Basics
======

[](#basics)

Simple Routing
--------------

[](#simple-routing)

```
function routeMe(): void
{
	echo 'I am routed';
}

Link::all( Map{
	'/' => Map{'routeMe' => []}
});
```

Named Routing
-------------

[](#named-routing)

In Link-Hack routes can be named and then further used generating links in a simple and elegant way.

```
function nameMe() :void
{
	echo 'I am named';
}

Link::all( Map{
	'/named' => Map{'nameMe' => [], 'Its my name' => []}
});
```

Names to routes must be given as second argument in array while the first being the route handler.

### Usage

[](#usage)

These named routes can be used in creating in hassle free links.

```
