Pro Yearly is on sale from $80 to $50! »

プログラムを作るためのプログラムを作るためのプログラム / 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. Masanobu Naruse ログラムを作るための プ プ プ ログラムを作るための ログラム

  2. 2

  3. 3

  4. 4

  5. 5

  6. ログラムを作るための プ プ プ ログラムを作るための ログラム

  7. ログラムを作るための プ プ プ ログラムを作るための ログラム

  8. 8

  9. ログラムを作るための プ プ プ ログラムを作るための ログラム

  10. プログラミングを高速化 10

  11. 君、プログラミング早いね

  12. 12 STEP 1 STEP 2 STEP 3 STEP 4 4つのステップを確認しよう

  13. 13 STEP 1 STEP 2 STEP 3 STEP 4 4つのステップを確認しよう

  14. 14

  15. 15

  16. ログラムを作るための プ プ プ ログラムを作るための ログラム

  17. 17

  18. ログラムを作るための プ プ プ ログラムを作るための ログラム

  19. 19

  20. 20

  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; } }
  22. 22

  23. 23

  24. 24 クラスを定義するには class と書きます。

  25. 25

  26. 26

  27. Class File Generator 27

  28. 28 https://github.com/nrslib/cfg

  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);
  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);
  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; } }
  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);
  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);
  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);
  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);
  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);
  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);
  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);
  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; }
  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; }
  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);
  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);
  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);
  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; }
  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; }
  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; }
  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);
  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);
  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);
  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);
  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);
  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);
  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);
  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; } }
  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);
  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); ?> }
  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 使えよ
  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 使えよ それな
  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); ?> }
  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; }
  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); ?> }
  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); ?> }
  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); ?> }
  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); ?> }
  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); ?> }
  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); ?> }
  67. 67

  68. 68 PHP って テンプレートエンジン だったんだね

  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);
  70. 70

  71. 71

  72. 72

  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; }
  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; } }
  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; } }
  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; } } こう書きたい
  77. ログラムを作るための プ プ プ ログラムを作るための ログラム

  78. 78

  79. None
  80. Auther Masanobu Naruse HomePage https://nrslib.com Twitter @nrslib 80