hhvm/hack-router-codegen

Name: hack-router-codegen

Owner: HipHop Virtual Machine

Description: Codegen (eg URI Map generation) on top of hhvm/hack-router

Created: 2017-02-09 04:09:29.0

Updated: 2018-04-12 18:32:37.0

Pushed: 2018-04-12 18:32:36.0

Homepage:

Size: 181

Language: Hack

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Hack-Router-Codegen Build Status

Code generation for controller classes using the UriPattern system from hhvm/hack-router

This currently supports generating:

Building a Request Router


ire_once(__DIR__.'/../vendor/hh_autoload.php');

\Facebook\HackRouter\Codegen;

l class UpdateCodegen {
blic function main(): void {
Codegen::forTree(
  __DIR__.'/../src/',
  shape(
    'controllerBase' => 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:

ic static function getUriPattern(): UriPattern {
turn (new UriPattern())
->literal('/')
->string('MyString')
->literal('/')
->int('MyInt')
->literal('/')
->enum(MyEnum::class, 'MyEnum');

Commit Your Codegen!

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

Contributing

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

License

hack-router-codegen is MIT-licensed.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.