PHP code example of facebook / hack-codegen

1. Go to this page and download the library: Download facebook/hack-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/ */

    

facebook / hack-codegen example snippets


<?hh
 Facebook\HackCodegen\HackCodegenFactory;

$cg = new HackCodegenFactory(new HackCodegenConfig());

echo $cg->codegenFile('HelloWorld.php')
  ->addClass(
    $cg->codegenClass('HelloWorld')
      ->addMethod(
        $cg->codegenMethod('sayHi')
          ->setReturnType('void')
          ->setBody(
            $cg->codegenHackBuilder()
              ->addAssignment(
                '$some_vector',
                Vector { 1, 2, 3 },
                HackBuilderValues::vector(
                  HackBuilderValues::export(),
                ),
              )
              ->addAssignment(
                '$debug_info',
                Map { 'file' => '__FILE__', 'line' => '__LINE__' },
                HackBuilderValues::map(
                  HackBuilderKeys::export(),
                  HackBuilderValues::literal(),
                ),
              )
              ->addAssignment(
                '$some_vector_of_vectors',
                Vector { Vector { 1, 2, 3 }, Vector { 4, 5, 6 } },
                HackBuilderValues::vector(
                  HackBuilderValues::vector(
                    HackBuilderValues::export(),
                  ),
                ),
              )
              ->addLine('echo "hello world\n";')
              ->getCode();
          );
      )
  )->save();