main.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. require 'vendor/autoload.php'; // 引入 Composer 的自动加载文件
  3. use inter\gen\DbStruct2ClassProcess;
  4. use inter\gen\ProcessConfig;
  5. use inter\mysqlStruct\Struct;
  6. use inter\storage\mysql\Config;
  7. use inter\storage\mysql\DB;
  8. use Smarty\Smarty;
  9. $argv = $_SERVER['argv'];
  10. $database = 'new_energy';
  11. //$database = 'bms_alarm';
  12. //$database = 'business';
  13. if (!empty($argv[1])) {
  14. $database = $argv[1];
  15. }
  16. $type = "query";
  17. if (!empty($argv[2])) {
  18. $type = $argv[2];
  19. }
  20. $dbConfig = new Config('101.37.90.21', "", 'root', 'QAZwsx!@#456', $database);
  21. $db = new DB($dbConfig);
  22. $dbProcess = new Struct($db);
  23. $dbProcess->SelectDatabase($database); //->AddUseTable("dh_admin_commission_account");
  24. $dbStruct = $dbProcess->GetDatabase();
  25. $config = new ProcessConfig();
  26. $config->savePath = "gen";
  27. $config->isHasGetFunc = true;
  28. $config->isHasSetFunc = true;
  29. if ($type == "record") {
  30. // record
  31. $tpl = "record.tpl";
  32. $config->fileNameSuffix = "Record";
  33. $config->SetNamespace('common/table/' . $database . '/record');
  34. $config->addUse("Yii");
  35. $config->addUse("common/table/NewEnergyDBRecord");
  36. $config->extends[] = "NewEnergyDBRecord";
  37. } else if ($type == "query") {
  38. // query
  39. $tpl = "query.tpl";
  40. $config->SetNamespace('common/table/' . $database . '/query');
  41. $config->fileNameSuffix = "Query";
  42. $config->addUse("common/table/BaseQuery");
  43. $config->extends[] = "BaseQuery";
  44. } else if ($type == "gset") {
  45. // get set
  46. $tpl = "setGet.tpl";
  47. $config->fileNameSuffix = "Trait";
  48. $config->SetNamespace('common/table/' . $database . '/getter_setter');
  49. } else {
  50. echo "不支持的类型";
  51. return;
  52. }
  53. $opt = new DbStruct2ClassProcess($config, $dbStruct);
  54. $files = $opt->GetFiles();
  55. $smarty = new Smarty(); // 创建 Smarty 对象实例
  56. foreach ($files as $file) {
  57. // 配置 Smarty
  58. $smarty->setTemplateDir('TPL') // 设置模板目录
  59. ->setCompileDir('gen/templates_c'); // 设置编译目录
  60. // 分配变量到模板
  61. $smarty->assign('file', $file);
  62. $smarty->assign("database", $database);
  63. // 渲染模板
  64. //$content = $smarty->fetch('template.tpl');
  65. $content = $smarty->fetch($tpl);
  66. // 保存内容到文件
  67. $filePath = $file->GetPath() . '/' . $file->GetFileName();
  68. file_put_contents($filePath, $content);
  69. }