| 1: | <?php |
| 2: | |
| 3: | namespace Aurora\System\Console\Commands\Seeds; |
| 4: | |
| 5: | use Aurora\System\Console\Commands\GeneratorCommand; |
| 6: | use Illuminate\Filesystem\Filesystem; |
| 7: | use Illuminate\Support\Composer; |
| 8: | use Symfony\Component\Console\Input\InputArgument; |
| 9: | use Symfony\Component\Console\Input\InputInterface; |
| 10: | use Symfony\Component\Console\Output\OutputInterface; |
| 11: | |
| 12: | class SeederMakeCommand extends GeneratorCommand |
| 13: | { |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | protected $composer; |
| 20: | |
| 21: | protected function configure(): void |
| 22: | { |
| 23: | $this->setName('make:seeder') |
| 24: | ->setDescription('Create a new seeder class') |
| 25: | ->addArgument('name', InputArgument::REQUIRED, 'The name of the class'); |
| 26: | } |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | public function __construct(Filesystem $files, Composer $composer) |
| 36: | { |
| 37: | parent::__construct($files); |
| 38: | |
| 39: | $this->composer = $composer; |
| 40: | } |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | protected function execute(InputInterface $input, OutputInterface $output): int |
| 48: | { |
| 49: | $result = parent::execute($input, $output); |
| 50: | |
| 51: | $this->composer->dumpAutoloads(); |
| 52: | |
| 53: | return $result; |
| 54: | } |
| 55: | |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | |
| 61: | protected function getStub() |
| 62: | { |
| 63: | return $this->resolveStubPath('/../../stubs/seeder.stub'); |
| 64: | } |
| 65: | |
| 66: | |
| 67: | |
| 68: | |
| 69: | |
| 70: | |
| 71: | |
| 72: | protected function resolveStubPath($stub) |
| 73: | { |
| 74: | return file_exists($customPath = \Aurora\Api::RootPath() . DIRECTORY_SEPARATOR . trim($stub, '/')) |
| 75: | ? $customPath |
| 76: | : __DIR__ . $stub; |
| 77: | } |
| 78: | |
| 79: | |
| 80: | |
| 81: | |
| 82: | |
| 83: | |
| 84: | |
| 85: | protected function getPath($name) |
| 86: | { |
| 87: | return \Aurora\Api::RootPath() . 'seeds' . DIRECTORY_SEPARATOR . str_replace('\\', '/', $name) . '.php'; |
| 88: | } |
| 89: | |
| 90: | |
| 91: | |
| 92: | |
| 93: | |
| 94: | |
| 95: | |
| 96: | protected function qualifyClass($name) |
| 97: | { |
| 98: | return $name; |
| 99: | } |
| 100: | } |
| 101: | |