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: * The Composer instance.
16: *
17: * @var \Illuminate\Support\Composer
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: * Create a new command instance.
30: *
31: * @param \Illuminate\Filesystem\Filesystem $files
32: * @param \Illuminate\Support\Composer $composer
33: * @return void
34: */
35: public function __construct(Filesystem $files, Composer $composer)
36: {
37: parent::__construct($files);
38:
39: $this->composer = $composer;
40: }
41:
42: /**
43: * Execute the console command.
44: *
45: * @return int
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: * Get the stub file for the generator.
58: *
59: * @return string
60: */
61: protected function getStub()
62: {
63: return $this->resolveStubPath('/../../stubs/seeder.stub');
64: }
65:
66: /**
67: * Resolve the fully-qualified path to the stub.
68: *
69: * @param string $stub
70: * @return string
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: * Get the destination class path.
81: *
82: * @param string $name
83: * @return string
84: */
85: protected function getPath($name)
86: {
87: return \Aurora\Api::RootPath() . 'seeds' . DIRECTORY_SEPARATOR . str_replace('\\', '/', $name) . '.php';
88: }
89:
90: /**
91: * Parse the class name and format according to the root namespace.
92: *
93: * @param string $name
94: * @return string
95: */
96: protected function qualifyClass($name)
97: {
98: return $name;
99: }
100: }
101: