annotate src/Generator/Controller/ControllerGenerator.php @ 5:b0b2e79ad8e6

Not exatly sure what was changed but commiting to it :)
author luka
date Thu, 12 Oct 2023 19:41:04 -0400
parents a20439b1c9d3
children 769a17898cc0
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
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
3 namespace Wizzard\MagicForger\Generator\Controller;
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;
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
6 use Wizzard\MagicForger\Generator\BaseGenerator;
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
7 use Illuminate\Support\Str;
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
8
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
9 #[AsCommand(name: 'mf:controller')]
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
10 class ControllerGenerator extends BaseGenerator
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 /**
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
13 * 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
14 *
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
15 * @var string
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
16 */
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
17 protected $name = 'mf:controller';
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 /**
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
20 * The console command description.
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
21 *
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
22 * @var string
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
23 */
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
24 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
25
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
26 /**
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
27 * The type of class being generated.
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
28 *
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
29 * @var string
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
30 */
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
31 protected $type = 'Controller';
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 /**
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
34 * Execute the console command.
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
35 */
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
36 public function handle()
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
37 {
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
38 $table = $this->getTable($this->getTableInput());
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 */
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
47 protected function getStub()
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 *
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
55 * @param string $stub
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
56 * @return string
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
57 */
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
58 protected function resolveStubPath($stub)
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
59 {
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
60 return is_file($customPath = $this->laravel->basePath(trim($stub, '/')))
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
61 ? $customPath
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
62 : __DIR__.$stub;
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
63 }
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
64
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
65 protected function getClassName($name)
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
66 {
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
67 return $this->controller_name($name);
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
68 }
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
69
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
70 /**
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
71 * Get the stub file for the generator.
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
72 *
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
73 * @return string
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
74 */
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
75 protected function getPath($name = null)
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
76 {
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
77 return str_replace(['App\\', '\\'], ['app/', '/'], $this->getControllerNamespace() . '/' . $this->controller_name($this->getTableInput()) . '.php');
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 }