Exemplo n.º 1
0
 public static function generateAndRequireCode(Info $info)
 {
     if (self::OPT_PROMPT_STRICT_TYPES) {
         $doStrictTypes = ExampleRunner::getUserInput('Do you want strict types? (y/n) ');
         if (strtolower($doStrictTypes) === 'y') {
             $info->declareStrict();
         }
     }
     $code = self::getGenerator()->generate($info);
     $path = tempnam(sys_get_temp_dir(), 'code_generator_exmaple');
     $h = fopen($path, 'w');
     fwrite($h, $code);
     fclose($h);
     if (self::$options[self::OPT_DUMP_GENERATED_CODE]) {
         self::stdout('Generated code');
         self::stdout(str_repeat('=', 80));
         self::stdout('');
         self::stdout($code);
     }
     require_once $path;
 }
Exemplo n.º 2
0
<?php

declare (strict_types=1);
require_once dirname(__DIR__) . '/vendor/autoload.php';
require_once __DIR__ . '/ExampleRunner.php';
use CodeAnvil\Info\InterfaceInfo;
/**
 * @license See LICENSE file in project root
 */
$info = (new InterfaceInfo())->setNamespace('CodeAnvil\\Examples');
$interfaceName = ExampleRunner::getUserInput('Give us a name for the interface:');
$info->setName($interfaceName);
ExampleRunner::generateAndRequireCode($info);
Exemplo n.º 3
0
<?php

declare (strict_types=1);
require_once dirname(__DIR__) . '/vendor/autoload.php';
require_once __DIR__ . '/ExampleRunner.php';
use CodeAnvil\Info\ConstantInfo;
use CodeAnvil\Info\InterfaceInfo;
/**
 * @license See LICENSE file in project root
 */
$foo = (new ConstantInfo())->setName('FOO')->setDefaultValue(true);
$bar = (new ConstantInfo())->setName('BAR')->setDefaultValue(['foo', 'bar']);
$baz = (new ConstantInfo())->setName('BAZ')->setDefaultValue(1.1);
$interface = (new InterfaceInfo())->setNamespace('CodeAnil\\Examples')->setName('InterfaceWithConstants');
$interface->addConstant($foo)->addConstant($bar)->addConstant($baz);
ExampleRunner::generateAndRequireCode($interface);