facebook/hack-router-codegen 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

facebook/hack-router-codegen

最新稳定版本:v1.0.0rc5

Composer 安装命令:

composer require facebook/hack-router-codegen

包简介

URI routing for Hack with codegen

README 文档

README

Continuous Integration

Code generation for controller classes using the UriPattern system from 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

<?hh
use \Facebook\HackRouter\Codegen;

final class UpdateCodegen {
  public 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:

public static function getUriPattern(): UriPattern {
  return (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:

  • 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

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

License

hack-router-codegen is MIT-licensed.

统计信息

  • 总下载量: 16.64k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 16
  • Forks: 6
  • 开发语言: Hack

其他信息

  • 授权协议: Unknown
  • 更新时间: 2017-02-15