Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

nrs
October 30, 2019

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

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

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

nrs

October 30, 2019
Tweet

More Decks by nrs

Other Decks in Programming

Transcript

  1. 2

  2. 3

  3. 4

  4. 5

  5. 8

  6. 14

  7. 15

  8. 17

  9. 19

  10. 20

  11. 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

  13. 23

  14. 25

  15. 26

  16. 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 $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 /** * 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 $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 $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 $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 $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 $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 $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 $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 $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 $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 $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 $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 $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 $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 $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 $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 $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 $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 $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 $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 $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 $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 $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 $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 $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 <?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 <?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 <?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 <?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 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 <?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 <?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 <?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 <?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 <?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 <?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

  55. 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

  57. 71

  58. 72

  59. 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 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 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 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