IHackCodegenConfig defines several methods for project-specification, such as indentation preferences, and where any paths generated should be relative to.

HackCodegenConfig is a concrete implementation, which takes the project root directory as a parameter; HackCodegenFactory is a convenience class to instantiate the codegen builders without having to explicitly pass configuration into each of them; for example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?hh

use Facebook\HackCodegen\{
  CodegenClass
  HackCodegenConfig,
  HackCodegenFactory
};

$config = new HackCodegenConfig(realpath(__DIR__.'/../'));

$class_a = new CodegenClass($config, 'ClassA');
$class_b = new CodegenClass($config, 'ClassB');

$cg = new HackCodegenFactory($config);

$class_c = $cg->codegenClass('ClassC');
$class_d = $cg->codegenClass('ClassD');

HackCodegenFactory is the recommended way to use Hack Codegen.

Edit on GitHub