Module.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace Modules\Develop\Support\Generate;
  3. use Catch\CatchAdmin;
  4. use Illuminate\Support\Facades\File;
  5. use Illuminate\Support\Str;
  6. class Module
  7. {
  8. public function __construct(
  9. public string $module,
  10. protected bool $controller,
  11. protected bool $models,
  12. protected bool $requests,
  13. protected bool $database
  14. ) {
  15. }
  16. /**
  17. * create
  18. *
  19. * @return void
  20. */
  21. public function create(): void
  22. {
  23. if ($this->controller) {
  24. CatchAdmin::getModuleControllerPath($this->module);
  25. }
  26. if ($this->models) {
  27. CatchAdmin::getModuleModelPath($this->module);
  28. }
  29. if ($this->requests) {
  30. CatchAdmin::getModuleRequestPath($this->module);
  31. }
  32. if ($this->database) {
  33. CatchAdmin::getModuleMigrationPath($this->module);
  34. CatchAdmin::getModuleSeederPath($this->module);
  35. }
  36. $this->createProvider();
  37. $this->createRoute();
  38. }
  39. /**
  40. * delete
  41. *
  42. * @return void
  43. */
  44. public function delete(): void
  45. {
  46. }
  47. /**
  48. * create provider
  49. *
  50. * @return void
  51. */
  52. protected function createProvider(): void
  53. {
  54. CatchAdmin::getModuleProviderPath($this->module);
  55. File::put(
  56. CatchAdmin::getModuleProviderPath($this->module).sprintf('%sServiceProvider.php', ucfirst($this->module)),
  57. Str::of(
  58. File::get(__DIR__.DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'provider.stub')
  59. )->replace(['{Module}', '{module}'], [ucfirst($this->module), $this->module])
  60. );
  61. }
  62. /**
  63. * create route
  64. *
  65. * @return void
  66. */
  67. protected function createRoute(): void
  68. {
  69. File::copy(__DIR__.DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'route.stub', CatchAdmin::getModuleRoutePath($this->module));
  70. }
  71. }