annotate src/Generator/Controller/ControllerGenerator.php @ 21:f0b0d014e448 main-dev

Cleaning up code based on AI overlord review
author Luka Sitas <sitas.luka.97@gmail.com>
date Wed, 26 Feb 2025 19:45:08 -0500
parents 19b7a8de0019
children ee8ef14e158d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
1 <?php
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
2
19
19b7a8de0019 updating namespace from typo
Luka Sitas <sitas.luka.97@gmail.com>
parents: 9
diff changeset
3 namespace Wizard\MagicForger\Generator\Controller;
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
4
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
5 use Symfony\Component\Console\Attribute\AsCommand;
19
19b7a8de0019 updating namespace from typo
Luka Sitas <sitas.luka.97@gmail.com>
parents: 9
diff changeset
6 use Wizard\MagicForger\Generator\BaseGenerator;
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
7
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
8 #[AsCommand(name: 'mf:controller')]
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
9 class ControllerGenerator extends BaseGenerator
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
10 {
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
11 /**
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
12 * The name and signature of the console command.
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
13 *
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
14 * @var string
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
15 */
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
16 protected $name = 'mf:controller';
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
17
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
18 /**
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
19 * The console command description.
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
20 *
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
21 * @var string
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
22 */
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
23 protected $description = 'Generates the Controller File for a table.';
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
24
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
25 /**
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
26 * The type of class being generated.
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
27 *
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
28 * @var string
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
29 */
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
30 protected $type = 'Controller';
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
31
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
32 /**
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
33 * Execute the console command.
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
34 *
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
35 * @return void
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
36 */
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
37 public function handle(): void
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
38 {
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
39 parent::handle();
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
40 }
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
41
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
42 /**
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
43 * Get the stub file for the generator.
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
44 *
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
45 * @return string
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
46 */
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
47 protected function getStub(): string
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
48 {
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
49 return $this->resolveStubPath('/stubs/controller.stub');
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
50 }
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
51
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
52 /**
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
53 * Resolve the fully-qualified path to the stub.
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
54 *
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
55 * @param string $stub
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
56 * @return string
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
57 */
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
58 protected function resolveStubPath(string $stub): string
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
59 {
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
60 $customPath = $this->laravel->basePath(trim($stub, '/'));
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
61
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
62 return is_file($customPath) ? $customPath : __DIR__ . $stub;
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
63 }
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
64
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
65 /**
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
66 * Get the path for the generated file.
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
67 *
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
68 * @param string|null $name
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
69 * @return string
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
70 */
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
71 protected function getPath(?string $name = null): string
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
72 {
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
73 return str_replace(
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
74 ['App\\', '\\'],
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
75 ['app/', '/'],
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
76 $this->getControllerNamespace() . '/' . $this->controller_name($this->getTableInput()) . '.php'
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
77 );
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
78 }
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
79
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
80 /**
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
81 * Get the class name for the controller.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
82 *
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
83 * @param string $name
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
84 * @return string
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
85 */
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
86 protected function getClassName(string $name): string
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
87 {
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
88 return $this->controller_name($name);
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
89 }
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
90 }