|
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
|
|
|
}\r\n |
|
69
|
|
|
EOT; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Creates class data |
|
74
|
|
|
* ------------------ |
|
75
|
|
|
* Создает данные класса |
|
76
|
|
|
* |
|
77
|
|
|
* @param string $className |
|
78
|
|
|
* @param string $container |
|
79
|
|
|
* @return string |
|
80
|
|
|
*/ |
|
81
|
|
|
private function createRepository(string $className, string $container): string |
|
82
|
|
|
{ |
|
83
|
|
|
$table = strtolower($className); |
|
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
return <<<EOT |
|
86
|
|
|
<?php |
|
87
|
|
|
|
|
88
|
|
|
namespace App\Containers\\{$container}\Repository; |
|
89
|
|
|
|
|
90
|
|
|
use Rudra\Model\QBFacade; |
|
91
|
|
|
use Rudra\Model\Repository; |
|
92
|
|
|
|
|
93
|
|
|
class {$className}Repository extends Repository |
|
94
|
|
|
{ |
|
95
|
|
|
|
|
96
|
|
|
}\r\n |
|
97
|
|
|
EOT; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|