1 | <?php |
||
2 | |||
3 | namespace App\Ship\Command; |
||
4 | |||
5 | use App\Ship\Utils\FileCreator; |
||
6 | use Rudra\Container\Facades\Rudra; |
||
7 | use Rudra\Cli\ConsoleFacade as Cli; |
||
8 | |||
9 | class CreateModelCommand extends FileCreator |
||
10 | { |
||
11 | /** |
||
12 | * Creates a file with Seed data |
||
13 | * ----------------------------- |
||
14 | * Создает файл с данными Seed |
||
15 | */ |
||
16 | public function actionIndex(): void |
||
17 | { |
||
18 | Cli::printer("Enter table name: ", "magneta"); |
||
19 | $prefix = str_replace(PHP_EOL, "", Cli::reader()); |
||
20 | $className = ucfirst($prefix); |
||
21 | |||
22 | Cli::printer("Enter container: ", "magneta"); |
||
23 | $container = ucfirst(str_replace(PHP_EOL, "", Cli::reader())); |
||
24 | |||
25 | if (!empty($container)) { |
||
26 | |||
27 | $this->writeFile( |
||
28 | [str_replace('/', DIRECTORY_SEPARATOR, Rudra::config()->get('app.path') . "/app/Containers/$container/Entity/"), "{$className}.php"], |
||
29 | $this->createEntity($className, $container) |
||
30 | ); |
||
31 | |||
32 | $this->writeFile( |
||
33 | [str_replace('/', DIRECTORY_SEPARATOR, Rudra::config()->get('app.path') . "/app/Containers/$container/Repository/"), "{$className}Repository.php"], |
||
34 | $this->createRepository($className, $container) |
||
35 | ); |
||
36 | |||
37 | } else { |
||
38 | $this->actionIndex(); |
||
39 | } |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Creates class data |
||
44 | * ------------------ |
||
45 | * Создает данные класса |
||
46 | * |
||
47 | * @param string $className |
||
48 | * @param string $container |
||
49 | * @return string |
||
50 | */ |
||
51 | private function createEntity(string $className, string $container): string |
||
52 | { |
||
53 | $table = strtolower($className); |
||
54 | |||
55 | return <<<EOT |
||
56 | <?php |
||
57 | |||
58 | namespace App\Containers\\{$container}\Entity; |
||
59 | |||
60 | use Rudra\Model\Entity; |
||
61 | |||
62 | /** |
||
63 | * @see \App\Containers\\$container\Repository\\{$className}Repository |
||
64 | */ |
||
65 | class {$className} extends Entity |
||
66 | { |
||
67 | public static string \$table = "$table"; |
||
68 | public static string \$directory = __DIR__; |
||
69 | }\r\n |
||
70 | EOT; |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * Creates class data |
||
75 | * ------------------ |
||
76 | * Создает данные класса |
||
77 | * |
||
78 | * @param string $className |
||
79 | * @param string $container |
||
80 | * @return string |
||
81 | */ |
||
82 | private function createRepository(string $className, string $container): string |
||
83 | { |
||
84 | $table = strtolower($className); |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
85 | |||
86 | return <<<EOT |
||
87 | <?php |
||
88 | |||
89 | namespace App\Containers\\{$container}\Repository; |
||
90 | |||
91 | use Rudra\Model\QBFacade; |
||
92 | use Rudra\Model\Repository; |
||
93 | |||
94 | class {$className}Repository extends Repository |
||
95 | { |
||
96 | |||
97 | }\r\n |
||
98 | EOT; |
||
99 | } |
||
100 | } |
||
101 |