GeneratorCommand.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Dcat\Admin\Console;
  3. use Dcat\Admin\Support\Helper;
  4. use Illuminate\Console\GeneratorCommand as BaseCommand;
  5. use Illuminate\Support\Str;
  6. abstract class GeneratorCommand extends BaseCommand
  7. {
  8. protected $baseDirectory;
  9. /**
  10. * Get the root namespace for the class.
  11. *
  12. * @return string
  13. */
  14. protected function rootNamespace()
  15. {
  16. return $this->getDefaultNamespace(null);
  17. }
  18. /**
  19. * Get the destination class path.
  20. *
  21. * @param string $name
  22. * @return string
  23. */
  24. protected function getPath($name)
  25. {
  26. return Helper::guessClassFileName($name);
  27. }
  28. /**
  29. * @return string
  30. */
  31. protected function getBaseDir()
  32. {
  33. if ($this->baseDirectory) {
  34. return trim(base_path($this->baseDirectory), '/');
  35. }
  36. if ($this->hasOption('base') && $this->option('base')) {
  37. return trim(base_path($this->option('base')), '/');
  38. }
  39. return $this->laravel['path'];
  40. }
  41. /**
  42. * @return void
  43. */
  44. protected function askBaseDirectory()
  45. {
  46. if (! Str::startsWith(config('admin.route.namespace'), 'App')) {
  47. $dir = explode('\\', config('admin.route.namespace'))[0];
  48. $this->baseDirectory = trim($this->ask('Please enter the application path', Helper::slug($dir)));
  49. }
  50. }
  51. }