|
5
|
1 <?php
|
|
|
2
|
|
|
3 namespace Wizzard\MagicForger\Generator\Route;
|
|
|
4
|
|
|
5 use Symfony\Component\Console\Attribute\AsCommand;
|
|
|
6 use Wizzard\MagicForger\Generator\BaseGenerator;
|
|
|
7 use Wizzard\MagicForger\Replacer;
|
|
|
8 use Illuminate\Support\Str;
|
|
|
9
|
|
|
10 #[AsCommand(name: 'mf:routes')]
|
|
|
11 class RouteGenerator extends BaseGenerator
|
|
|
12 {
|
|
|
13 /**
|
|
|
14 * The name and signature of the console command.
|
|
|
15 *
|
|
|
16 * @var string
|
|
|
17 */
|
|
|
18 protected $name = 'mf:routes';
|
|
|
19
|
|
|
20 /**
|
|
|
21 * The console command description.
|
|
|
22 *
|
|
|
23 * @var string
|
|
|
24 */
|
|
|
25 protected $description = 'Generates the Route File for a table.';
|
|
|
26
|
|
|
27 /**
|
|
|
28 * The type of class being generated.
|
|
|
29 *
|
|
|
30 * @var string
|
|
|
31 */
|
|
|
32 protected $type = 'Route';
|
|
|
33
|
|
|
34 /**
|
|
|
35 * Execute the console command.
|
|
|
36 */
|
|
|
37 public function handle()
|
|
|
38 {
|
|
|
39 parent::handle();
|
|
|
40 }
|
|
|
41
|
|
|
42 /**
|
|
|
43 * Get the stub file for the generator.
|
|
|
44 *
|
|
|
45 * @return string
|
|
|
46 */
|
|
|
47 protected function getStub()
|
|
|
48 {
|
|
|
49 return $this->resolveStubPath('/stubs/routes.stub');
|
|
|
50 }
|
|
|
51
|
|
|
52 /**
|
|
|
53 * Resolve the fully-qualified path to the stub.
|
|
|
54 *
|
|
|
55 * @param string $stub
|
|
|
56 * @return string
|
|
|
57 */
|
|
|
58 protected function resolveStubPath($stub)
|
|
|
59 {
|
|
|
60 return is_file($customPath = $this->laravel->basePath(trim($stub, '/')))
|
|
|
61 ? $customPath
|
|
|
62 : __DIR__.$stub;
|
|
|
63 }
|
|
|
64
|
|
|
65 protected function getClassName($name)
|
|
|
66 {
|
|
|
67 return $this->routes_name($name);
|
|
|
68 }
|
|
|
69
|
|
|
70 /**
|
|
|
71 * Get the stub file for the generator.
|
|
|
72 *
|
|
|
73 * @return string
|
|
|
74 */
|
|
|
75 protected function getPath($name = null)
|
|
|
76 {
|
|
|
77 return str_replace(['App\\', '\\'], ['app/', '/'], $this->getRouteNamespace() . '/' . $this->routes_name($this->getTableInput()) . '.php');
|
|
|
78 }
|
|
|
79 }
|