PHP code example of hhpack / codegen
1. Go to this page and download the library: Download hhpack/codegen library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hhpack / codegen example snippets
hack
use HHPack\Codegen\{GenerateClassFile};
use HHPack\Codegen\Contract\{ClassFileGeneratable};
use Facebook\HackCodegen\{ICodegenFactory, CodegenFile, CodegenClass};
final class CustomClassGenerator implements ClassFileGeneratable {
public function __construct(private ICodegenFactory $cg) {}
public static function from(ICodegenFactory $factory): this {
return new self($factory);
}
public function generate(GenerateClassFile $target): CodegenFile {
return
$this->cg
->codegenFile($target->fileName())
->setNamespace($target->belongsNamespace())
->addClass($this->classOf($target->name()));
}
private function classOf(string $className): CodegenClass {
return $this->cg->codegenClass($className)->setIsFinal(true);
}
}