1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SoliDry\Blocks; |
4
|
|
|
|
5
|
|
|
use SoliDry\Helpers\Classes; |
6
|
|
|
use SoliDry\Helpers\Console; |
7
|
|
|
use SoliDry\ApiGenerator; |
8
|
|
|
use SoliDry\Types\CommandsInterface; |
9
|
|
|
use SoliDry\Types\ModulesInterface; |
10
|
|
|
use SoliDry\Types\PhpInterface; |
11
|
|
|
|
12
|
|
|
class Module |
13
|
|
|
{ |
14
|
|
|
use ContentManager; |
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected string $sourceCode = ''; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var ApiGenerator |
23
|
|
|
*/ |
24
|
|
|
protected ApiGenerator $generator; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected string $className; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Module constructor. |
33
|
|
|
* @param $generator |
34
|
|
|
*/ |
35
|
|
|
public function __construct($generator) |
36
|
|
|
{ |
37
|
|
|
$this->generator = $generator; |
38
|
|
|
$this->className = Classes::getClassName($this->generator->objectName); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param $generator |
43
|
|
|
*/ |
44
|
|
|
public function setCodeState($generator) |
45
|
|
|
{ |
46
|
|
|
$this->generator = $generator; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function create() |
50
|
|
|
{ |
51
|
|
|
$output = []; |
52
|
|
|
exec(CommandsInterface::LARAVEL_MODULE_MAKE . PhpInterface::SPACE . $this->generator->version, $output); |
53
|
|
|
exec(CommandsInterface::LARAVEL_MODULE_USE . PhpInterface::SPACE . $this->generator->version, $output); |
54
|
|
|
exec(CommandsInterface::LARAVEL_MODULE_LIST, $output); |
55
|
|
|
foreach($output as $str) |
56
|
|
|
{ |
57
|
|
|
Console::out($str, Console::COLOR_GREEN); |
58
|
|
|
} |
59
|
|
|
$this->setTag(); |
60
|
|
|
$this->createModuleContent(); |
61
|
|
|
FileManager::createModuleConfig($this->sourceCode); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
private function createModuleContent() |
65
|
|
|
{ |
66
|
|
|
$this->sourceCode .= PhpInterface::PHP_RETURN . PhpInterface::SPACE |
67
|
|
|
. PhpInterface::OPEN_BRACKET . PHP_EOL . PhpInterface::TAB_PSR4 |
68
|
|
|
. $this->quoteParam(ModulesInterface::KEY_MODULES) |
69
|
|
|
. PhpInterface::DOUBLE_ARROW . PhpInterface::SPACE |
70
|
|
|
. PhpInterface::OPEN_BRACKET . PHP_EOL . PhpInterface::TAB_PSR4 |
71
|
|
|
. PhpInterface::TAB_PSR4 . $this->quoteParam($this->generator->version) |
72
|
|
|
. PhpInterface::COMMA . PHP_EOL . PhpInterface::TAB_PSR4 |
73
|
|
|
. PhpInterface::CLOSE_BRACKET . PHP_EOL |
74
|
|
|
. PhpInterface::CLOSE_BRACKET . PhpInterface::SEMICOLON; |
75
|
|
|
} |
76
|
|
|
} |