schema.sbn 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. {{~namespace_with_grace_begin __namespace~}}
  2. {{~for enum in __enums~}}
  3. {{~if enum.comment != '' ~}}
  4. /**
  5. * {{enum.comment | html.escape}}
  6. */
  7. {{~end~}}
  8. class {{full_name enum}} {
  9. {{~for item in enum.items ~}}
  10. {{~if item.comment != '' ~}}
  11. /**
  12. * {{escape_comment item.comment}}
  13. */
  14. {{~end~}}
  15. public const {{item.name}} = {{item.value}};
  16. {{~end~}}
  17. }
  18. {{~end~}}
  19. {{~for bean in __beans~}}
  20. {{name = (full_name bean)}}
  21. {{~if bean.comment != '' ~}}
  22. /**
  23. * {{escape_comment bean.comment}}
  24. */
  25. {{~end~}}
  26. {{class_modifier bean}} class {{name}}{{if bean.parent_def_type}} extends {{full_name bean.parent_def_type}}{{end}} {
  27. {{~if bean.is_abstract_type~}}
  28. public static function constructFrom($_json_) {
  29. $type = $_json_['$type'];
  30. switch ($type) {
  31. {{~ for child in bean.hierarchy_not_abstract_children~}}
  32. case '{{impl_data_type child bean}}': return new {{full_name child}}($_json_);
  33. {{~end~}}
  34. default: throw new \Exception("unknown type:$type");
  35. }
  36. }
  37. {{~end~}}
  38. public function __construct($_json_) {
  39. {{~if bean.parent_def_type~}}
  40. parent::__construct($_json_);
  41. {{~end~}}
  42. {{~ for field in bean.export_fields ~}}
  43. {{~if !field.ctype.is_nullable~}}
  44. if (!array_key_exists('{{field.name}}', $_json_)) { throw new \Exception("field:'{{field.name}}' missing"); }
  45. {{~end~}}
  46. {{deserialize ('$this->' + format_field_name __code_style field.name) ( '$_json_[\'' + field.name + '\']') field.ctype}};
  47. {{~end~}}
  48. }
  49. {{~ for field in bean.export_fields ~}}
  50. {{~if field.comment != '' ~}}
  51. /**
  52. * {{escape_comment field.comment}}
  53. */
  54. {{~end~}}
  55. public ${{format_field_name __code_style field.name}};
  56. {{~end~}}
  57. }
  58. {{~end~}}
  59. {{~for table in __tables
  60. key_type = table.key_ttype
  61. value_type = table.value_ttype
  62. name = (full_name table)
  63. ~}}
  64. {{~if table.comment != '' ~}}
  65. /**
  66. * {{escape_comment table.comment}}
  67. */
  68. {{~end~}}
  69. class {{name}} {
  70. {{~if table.is_map_table ~}}
  71. private $_dataMap;
  72. private $_dataList;
  73. public function __construct($_json_) {
  74. $this->_dataMap = [];
  75. $this->_dataList = [];
  76. foreach ($_json_ as $_json2_) {
  77. {{deserialize '$_v' '$_json2_' value_type}};
  78. array_push($this->_dataList, $_v);
  79. $this->_dataMap[$_v->{{format_field_name __code_style table.index_field.name}}] = $_v;
  80. }
  81. }
  82. public function getDataMap() { return $this->_dataMap; }
  83. public function getDataList() { return $this->_dataList; }
  84. public function get($key) { return $this->_dataMap[$key]; }
  85. {{~else if table.is_list_table ~}}
  86. private $_dataList;
  87. public function __construct($_json_) {
  88. $this->_dataList = [];
  89. foreach ($_json_ as $_json2_) {
  90. {{deserialize '$_v' '$_json2_' value_type}};
  91. array_push($this->_dataList, $_v);
  92. }
  93. }
  94. public function getDataList() { return $this->_dataList; }
  95. public function get($index) { return $this->_dataList[$index]; }
  96. {{~else~}}
  97. private $_data;
  98. public function __construct($_json_) {
  99. if (count($_json_) != 1) throw new \Exception('table:{{table.name}} mode=one, but size != 1');
  100. {{deserialize '$this->_data' '$_json_[0]' value_type}};
  101. }
  102. public function getData() { return $this->_data; }
  103. {{~ for field in value_type.def_bean.hierarchy_export_fields ~}}
  104. {{~if field.comment != '' ~}}
  105. /**
  106. * {{escape_comment field.comment}}
  107. */
  108. {{~end~}}
  109. public function get{{format_field_name __code_style field.name}}() { return $this->_data->{{format_field_name __code_style field.name}}; }
  110. {{~end~}}
  111. {{end}}
  112. }
  113. {{~end~}}
  114. class {{__name}} {
  115. {{~ for table in __tables ~}}
  116. private $_{{table.name}};
  117. {{~if table.comment != '' ~}}
  118. /**
  119. * {{escape_comment table.comment}}
  120. */
  121. {{~end~}}
  122. public function get{{table.name}}() { return $this->_{{table.name}}; }
  123. {{~end~}}
  124. public function __construct($loader) {
  125. {{~for table in __tables ~}}
  126. $this->_{{table.name}} = new {{full_name table}}($loader('{{table.output_data_file}}'));
  127. {{~end~}}
  128. }
  129. }
  130. {{~namespace_with_grace_end __namespace~}}