Crud.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\crud\command;
  3. use app\crud\make\AutoMake;
  4. use app\crud\make\make\ControllerMake;
  5. use app\crud\make\make\ModelMake;
  6. use app\crud\make\make\ValidateMake;
  7. use app\crud\make\make\ListMake;
  8. use app\crud\make\make\ReadMake;
  9. use app\crud\make\make\AddMake;
  10. use app\crud\make\make\EditMake;
  11. use think\console\Command;
  12. use think\console\Input;
  13. use think\console\input\Option;
  14. use think\console\Output;
  15. class Crud extends Command
  16. {
  17. protected function configure()
  18. {
  19. $this->setName('auto crud')
  20. ->addOption('table', 't', Option::VALUE_OPTIONAL, 'the table name', null)
  21. ->addOption('controller', 'c', Option::VALUE_OPTIONAL, 'the controller name', null)
  22. ->addOption('name', 'm', Option::VALUE_OPTIONAL, 'the name', null)
  23. ->setDescription('auto make crud file');
  24. }
  25. protected function execute(Input $input, Output $output)
  26. {
  27. $table = $input->getOption('table');
  28. if (!$table) {
  29. $output->error("请输入 -t 表名");
  30. exit;
  31. }
  32. $controller = $input->getOption('controller');
  33. if (!$controller) {
  34. $output->error("请输入 -c 控制器名");
  35. exit;
  36. }
  37. $path = 'admin';
  38. $name = $input->getOption('name');
  39. if (!$name) {
  40. $name = '';
  41. }
  42. $make = new AutoMake();
  43. // 执行生成controller策略
  44. $make->executeText(new ControllerMake());
  45. $make->executeCreate($controller, $path, $table);
  46. // 执行生成model策略
  47. $make->executeText(new ModelMake());
  48. $make->executeCreate($table, $path, '');
  49. // 执行生成validate策略
  50. $make->executeText(new ValidateMake());
  51. $make->executeCreate($table, $path, '');
  52. // 执行生成list策略
  53. $make->executeText(new ListMake());
  54. $make->executeCreate($table, $path, $name);
  55. // 执行生成view策略
  56. $make->executeText(new ReadMake());
  57. $make->executeCreate($table, $path, $name);
  58. // 执行生成add策略
  59. $make->executeText(new AddMake());
  60. $make->executeCreate($table, $path, $name);
  61. // 执行生成edit策略
  62. $make->executeText(new EditMake());
  63. $make->executeCreate($table, $path, $name);
  64. $output->info($name . "crud make success");
  65. }
  66. }