プログラムを作るためのプログラムを作るためのプログラム / Program for program for program

E37b4344ef4bfd0fc4826c04971e54fb?s=47 nrs
October 30, 2019

プログラムを作るためのプログラムを作るためのプログラム / Program for program for program

プログラムを作るためのプログラムを作るためのプログラムの話です。
https://github.com/nrslib/cfg

# URL
HomePage: https://nrslib.com
Twitter: https://twitter.com/nrslib

E37b4344ef4bfd0fc4826c04971e54fb?s=128

nrs

October 30, 2019
Tweet

Transcript

  1. 2.

    2

  2. 3.

    3

  3. 4.

    4

  4. 5.

    5

  5. 8.

    8

  6. 14.

    14

  7. 15.

    15

  8. 17.

    17

  9. 19.

    19

  10. 20.

    20

  11. 21.

    21 /** * Class MyTestClass * @package nrslib */ class

    MyTestClass { /** @var string */ private $testField; /** @var string */ public $testField2; /** * MyTestClass constructor. * @param string $testField */ public function __construct(string $testField) { $this->testField = $testField; } /** * @param string $test * @param string $test2 */ public function test(string $test, string $test2) { } /** * */ private function test2() { $testField = 1; } }
  12. 22.

    22

  13. 23.

    23

  14. 25.

    25

  15. 26.

    26

  16. 29.

    29 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  17. 30.

    30 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  18. 31.

    31 /** * Class MyTestClass * @package nrslib */ class

    MyTestClass { /** @var string */ private $testField; /** @var string */ public $testField2; /** * MyTestClass constructor. * @param string $testField */ public function __construct(string $testField) { $this->testField = $testField; } /** * @param string $test * @param string $test2 */ public function test(string $test, string $test2) { } /** * */ private function test2() { $testField = 1; } }
  19. 32.

    32 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  20. 33.

    33 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  21. 34.

    34 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  22. 35.

    35 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  23. 36.

    36 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  24. 37.

    37 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  25. 38.

    38 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  26. 39.

    39 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta); /** * Class MyTestClass * @package nrslib */ class MyTestClass { /** @var string */ private $testField; /** @var string */ public $testField2; /** * MyTestClass constructor. * @param string $testField */ public function __construct(string $testField) { $this->testField = $testField; }
  27. 40.

    40 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta); /** * Class MyTestClass * @package nrslib */ class MyTestClass { /** @var string */ private $testField; /** @var string */ public $testField2; /** * MyTestClass constructor. * @param string $testField */ public function __construct(string $testField) { $this->testField = $testField; }
  28. 41.

    41 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  29. 42.

    42 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  30. 43.

    43 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  31. 44.

    44 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta); /** * Class MyTestClass * @package nrslib */ class MyTestClass { /** @var string */ private $testField; /** @var string */ public $testField2; /** * MyTestClass constructor. * @param string $testField */ public function __construct(string $testField) { $this->testField = $testField; }
  32. 45.

    45 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta); /** * Class MyTestClass * @package nrslib */ class MyTestClass { /** @var string */ private $testField; /** @var string */ public $testField2; /** * MyTestClass constructor. * @param string $testField */ public function __construct(string $testField) { $this->testField = $testField; }
  33. 46.

    46 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta); ... /** @var string */ private $testField; /** @var string */ public $testField2; /** * MyTestClass constructor. * @param string $testField */ public function __construct(string $testField) { $this->testField = $testField; }
  34. 47.

    47 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  35. 48.

    48 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  36. 49.

    49 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  37. 50.

    50 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  38. 51.

    51 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  39. 52.

    52 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  40. 53.

    53 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  41. 54.

    54 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta); /** * @param string $test * @param string $test2 */ public function test(string $test, string $test2) { } /** * */ private function test2() { $testField = 1; } }
  42. 55.

    55 $meta = new ClassMeta("MyTestClass", "nrslib"); $meta->setupClass() ->setConstructor(function ($define) {

    $define->addArgument('testField', 'string') ->addBody('$this->testField = $testField;'); }); $meta->setupFields() ->addField('testField', 'string') ->addField('testField2', 'string', AccessLevel::public()); $meta->setupMethods() ->addMethod('test', function($define) { $define->setAccessLevel(AccessLevel::public()) ->addArgument('test', 'string') ->addArgument('test2', 'string'); }) ->addMethod('test2', function($define) { $define->addBody('$testField = 1;'); }); $compiler = new ClassCompiler(); $source = $compiler->compile($meta);
  43. 56.

    56 <?php namespace nrslib¥Cfg¥Templates¥Classes; ... require_once "Helper.php"; ?> <?= "<?php"

    ?> namespace <?= $class->getNamespace(); ?>; <?php Helper::usingBlock($class); ?> /** * Class <?= $class->getName(); ?> * @package <?= $class->getNamespace(); ?> */ class <?= $class->getName(); ?><?php extendsBlock($class); ?><?php implementsBlock($class); ?> { <?php fieldBlock($fieldsSetting); ?> <?php constructorBlock($class, $class->getConstructor()); ?> <?php methodBlock($methodsSetting); ?> }
  44. 57.

    57 <?php namespace nrslib¥Cfg¥Templates¥Classes; ... require_once "Helper.php"; ?> <?= "<?php"

    ?> namespace <?= $class->getNamespace(); ?>; <?php Helper::usingBlock($class); ?> /** * Class <?= $class->getName(); ?> * @package <?= $class->getNamespace(); ?> */ class <?= $class->getName(); ?><?php extendsBlock($class); ?><?php implementsBlock($class); ?> { <?php fieldBlock($fieldsSetting); ?> <?php constructorBlock($class, $class->getConstructor()); ?> <?php methodBlock($methodsSetting); ?> } twig / smarty / blade 使えよ
  45. 58.

    58 <?php namespace nrslib¥Cfg¥Templates¥Classes; ... require_once "Helper.php"; ?> <?= "<?php"

    ?> namespace <?= $class->getNamespace(); ?>; <?php Helper::usingBlock($class); ?> /** * Class <?= $class->getName(); ?> * @package <?= $class->getNamespace(); ?> */ class <?= $class->getName(); ?><?php extendsBlock($class); ?><?php implementsBlock($class); ?> { <?php fieldBlock($fieldsSetting); ?> <?php constructorBlock($class, $class->getConstructor()); ?> <?php methodBlock($methodsSetting); ?> } twig / smarty / blade 使えよ それな
  46. 59.

    59 <?php namespace nrslib¥Cfg¥Templates¥Classes; ... require_once "Helper.php"; ?> <?= "<?php"

    ?> namespace <?= $class->getNamespace(); ?>; <?php Helper::usingBlock($class); ?> /** * Class <?= $class->getName(); ?> * @package <?= $class->getNamespace(); ?> */ class <?= $class->getName(); ?><?php extendsBlock($class); ?><?php implementsBlock($class); ?> { <?php fieldBlock($fieldsSetting); ?> <?php constructorBlock($class, $class->getConstructor()); ?> <?php methodBlock($methodsSetting); ?> }
  47. 60.

    60 class Helper { ... public static function fieldComment(FieldDefinition $field,

    $nest) { self::el('/** @var ' . $field->getVariableType() . ' */', $nest); } /** * Echo Line with indent. * @param string $text * @param int $nest */ public static function el(string $text = '', int $nest = 0) { echo self::indent($nest) . $text . ' '; } public static function indent(int $nest) { $indent = ''; for ($i = 0; $i < $nest; $i++) { $indent .= ' '; } return $indent; }
  48. 61.

    61 <?php namespace nrslib¥Cfg¥Templates¥Classes; ... require_once "Helper.php"; ?> <?= "<?php"

    ?> namespace <?= $class->getNamespace(); ?>; <?php Helper::usingBlock($class); ?> /** * Class <?= $class->getName(); ?> * @package <?= $class->getNamespace(); ?> */ class <?= $class->getName(); ?><?php extendsBlock($class); ?><?php implementsBlock($class); ?> { <?php fieldBlock($fieldsSetting); ?> <?php constructorBlock($class, $class->getConstructor()); ?> <?php methodBlock($methodsSetting); ?> }
  49. 62.

    62 <?php namespace nrslib¥Cfg¥Templates¥Classes; ... require_once "Helper.php"; ?> <?= "<?php"

    ?> namespace <?= $class->getNamespace(); ?>; <?php Helper::usingBlock($class); ?> /** * Class <?= $class->getName(); ?> * @package <?= $class->getNamespace(); ?> */ class <?= $class->getName(); ?><?php extendsBlock($class); ?><?php implementsBlock($class); ?> { <?php fieldBlock($fieldsSetting); ?> <?php constructorBlock($class, $class->getConstructor()); ?> <?php methodBlock($methodsSetting); ?> }
  50. 63.

    63 <?php namespace nrslib¥Cfg¥Templates¥Classes; ... require_once "Helper.php"; ?> <?= "<?php"

    ?> namespace <?= $class->getNamespace(); ?>; <?php Helper::usingBlock($class); ?> /** * Class <?= $class->getName(); ?> * @package <?= $class->getNamespace(); ?> */ class <?= $class->getName(); ?><?php extendsBlock($class); ?><?php implementsBlock($class); ?> { <?php fieldBlock($fieldsSetting); ?> <?php constructorBlock($class, $class->getConstructor()); ?> <?php methodBlock($methodsSetting); ?> }
  51. 64.

    64 <?php namespace nrslib¥Cfg¥Templates¥Classes; ... require_once "Helper.php"; ?> <?= "<?php"

    ?> namespace <?= $class->getNamespace(); ?>; <?php Helper::usingBlock($class); ?> /** * Class <?= $class->getName(); ?> * @package <?= $class->getNamespace(); ?> */ class <?= $class->getName(); ?><?php extendsBlock($class); ?><?php implementsBlock($class); ?> { <?php fieldBlock($fieldsSetting); ?> <?php constructorBlock($class, $class->getConstructor()); ?> <?php methodBlock($methodsSetting); ?> }
  52. 65.

    65 <?php namespace nrslib¥Cfg¥Templates¥Classes; ... require_once "Helper.php"; ?> <?= "<?php"

    ?> namespace <?= $class->getNamespace(); ?>; <?php Helper::usingBlock($class); ?> /** * Class <?= $class->getName(); ?> * @package <?= $class->getNamespace(); ?> */ class <?= $class->getName(); ?><?php extendsBlock($class); ?><?php implementsBlock($class); ?> { <?php fieldBlock($fieldsSetting); ?> <?php constructorBlock($class, $class->getConstructor()); ?> <?php methodBlock($methodsSetting); ?> }
  53. 66.

    66 <?php namespace nrslib¥Cfg¥Templates¥Classes; ... require_once "Helper.php"; ?> <?= "<?php"

    ?> namespace <?= $class->getNamespace(); ?>; <?php Helper::usingBlock($class); ?> /** * Class <?= $class->getName(); ?> * @package <?= $class->getNamespace(); ?> */ class <?= $class->getName(); ?><?php extendsBlock($class); ?><?php implementsBlock($class); ?> { <?php fieldBlock($fieldsSetting); ?> <?php constructorBlock($class, $class->getConstructor()); ?> <?php methodBlock($methodsSetting); ?> }
  54. 67.

    67

  55. 69.

    69 $meta = new InterfaceMeta('MyInterface', 'nrslib'); $meta->getInterfaceSetting() ->addExtend('MyInterface') ->addExtend('MyInterface2'); $meta->getMethodsSetting()

    ->addMethod('testMethod', function($define) { $define->addArgument('arg', 'string') ->addArgument('arg2', 'string'); }) ->addMethod('testMethod2', function($define) { $define->setReturnType('void'); }); $renderer = new InterfaceRenderer(); $source = $renderer->render($meta);
  56. 70.

    70

  57. 71.

    71

  58. 72.

    72

  59. 73.

    73 /** * @param string $name * @param string|null $type

    * @return MethodDefinition */ public function addArgument(string $name, string $type = null): self { array_push($this->arguments, new VariantDefinition($name, $type)); return $this; } /** * @param string $line * @return MethodDefinition */ public function addBody(string $line): self { array_push($this->body, $line); return $this; }
  60. 74.

    74 class MethodsSetting { /** @var MethodDefinition[] */ private $methods

    = []; ... /** * @param string $name * @param callable $predicate MethodDefinition => void * @return $this */ public function addMethod(string $name, $predicate) { $definition = new MethodDefinition($name); $predicate($definition); array_push($this->methods, $definition); return $this; } }
  61. 75.

    75 class MethodsSetting { /** @var MethodDefinition[] */ private $methods

    = []; ... /** * @param string $name * @param callable $predicate MethodDefinition => void * @return $this */ public function addMethod(string $name, $predicate) { $definition = new MethodDefinition($name); $predicate($definition); array_push($this->methods, $definition); return $this; } }
  62. 76.

    76 class MethodsSetting { /** @var MethodDefinition[] */ private $methods

    = []; ... /** * @param string $name * @param callable[MethodDefinition] $predicate MethodDefinition => void * @return $this */ public function addMethod(string $name, $predicate) { $definition = new MethodDefinition($name); $predicate($definition); array_push($this->methods, $definition); return $this; } } こう書きたい
  63. 78.

    78

  64. 79.