PHPackages                             facebook/hack-router-codegen - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. facebook/hack-router-codegen

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

facebook/hack-router-codegen
============================

URI routing for Hack with codegen

v1.0.0rc5(8y ago)1216.8k↓100%7[5 issues](https://github.com/hhvm/hack-router-codegen/issues)[1 PRs](https://github.com/hhvm/hack-router-codegen/pulls)Hack

Since Feb 15Pushed 2y ago15 watchersCompare

[ Source](https://github.com/hhvm/hack-router-codegen)[ Packagist](https://packagist.org/packages/facebook/hack-router-codegen)[ Docs](https://github.com/hhvm/hack-router-codegen)[ RSS](/packages/facebook-hack-router-codegen/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (27)Used By (0)

Hack-Router-Codegen
===================

[](#hack-router-codegen)

[![Continuous Integration](https://github.com/hhvm/hack-router-codegen/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/hhvm/hack-router-codegen/actions/workflows/build-and-test.yml)

Code generation for controller classes using the `UriPattern` system from [`hhvm/hack-router`](https://github.com/hhvm/hack-router)

This currently supports generating:

- Request routing maps
- Hack request routing classes for your site

For now, looking at the unit tests is the best way to learn how to use it.

Building a Request Router
=========================

[](#building-a-request-router)

```
 WebController::class,
        'router' => shape(
          'abstract' => false,
          'file' => __DIR__.'/../codegen/Router.php',
          'class' => 'Router',
        ),
      ),
    )->build;
  }
}
```

This will generate a class called 'Router', complete with an automatically-generated route map, based on the URI patterns in your controllers.

`WebController` is the root controller for your site, and must implement `Facebook\HackRouter\IncludeInUriMap`, which in turn requires `Facebook\HackRouter\HasUriPattern` - for example:

```
public static function getUriPattern(): UriPattern {
  return (new UriPattern())
    ->literal('/')
    ->string('MyString')
    ->literal('/')
    ->int('MyInt')
    ->literal('/')
    ->enum(MyEnum::class, 'MyEnum');
}
```

Commit Your Codegen!
====================

[](#commit-your-codegen)

This is unusual advice, but it's the best approach for Hack code as you otherwise have a circular dependency:

- HHVM will not execute hack code if there are references to undefined classes
- Once you use the codegen, you reference the codegen classes
- ... so you can't build them if you don't already have them

Contributing
============

[](#contributing)

We welcome GitHub issues and pull requests - please see CONTRIBUTING.md for details.

License
=======

[](#license)

hack-router-codegen is MIT-licensed.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance12

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~70 days

Recently: every ~168 days

Total

26

Last Release

1607d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3757713?v=4)[Joel Marcey](/maintainers/JoelMarcey)[@JoelMarcey](https://github.com/JoelMarcey)

![](https://avatars.githubusercontent.com/u/601530?v=4)[Yang, Bo](/maintainers/Atry)[@Atry](https://github.com/Atry)

![](https://avatars.githubusercontent.com/u/727402?v=4)[Alexey Toptygin](/maintainers/alexeyt)[@alexeyt](https://github.com/alexeyt)

---

Top Contributors

[![fredemmott](https://avatars.githubusercontent.com/u/360927?v=4)](https://github.com/fredemmott "fredemmott (152 commits)")[![jjergus](https://avatars.githubusercontent.com/u/2483917?v=4)](https://github.com/jjergus "jjergus (20 commits)")[![lexidor](https://avatars.githubusercontent.com/u/31805625?v=4)](https://github.com/lexidor "lexidor (9 commits)")[![Atry](https://avatars.githubusercontent.com/u/601530?v=4)](https://github.com/Atry "Atry (2 commits)")[![kmeht](https://avatars.githubusercontent.com/u/1120478?v=4)](https://github.com/kmeht "kmeht (1 commits)")[![simonwelsh](https://avatars.githubusercontent.com/u/125915?v=4)](https://github.com/simonwelsh "simonwelsh (1 commits)")

---

Tags

codegenhacklangpsr-7routingrouterroutinghhvmhack

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/facebook-hack-router-codegen/health.svg)

```
[![Health](https://phpackages.com/badges/facebook-hack-router-codegen/health.svg)](https://phpackages.com/packages/facebook-hack-router-codegen)
```

###  Alternatives

[bramus/router

A lightweight and simple object oriented PHP Router

1.1k458.8k48](/packages/bramus-router)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
