|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SoliDry\Blocks; |
|
4
|
|
|
|
|
5
|
|
|
use SoliDry\Documentation\Documentation; |
|
6
|
|
|
use SoliDry\Extension\BaseController; |
|
7
|
|
|
use SoliDry\Helpers\Classes; |
|
8
|
|
|
use SoliDry\Helpers\Console; |
|
9
|
|
|
use SoliDry\Types\ConsoleInterface; |
|
10
|
|
|
use SoliDry\Types\ControllersInterface; |
|
11
|
|
|
use SoliDry\Types\DefaultInterface; |
|
12
|
|
|
use SoliDry\Types\PhpInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class Controllers |
|
16
|
|
|
* @package SoliDry\Blocks |
|
17
|
|
|
*/ |
|
18
|
|
|
class Controllers extends Documentation implements ControllersInterface |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Creates the DefaultController and outputs path to the console |
|
23
|
|
|
* |
|
24
|
|
|
* @throws \ReflectionException |
|
25
|
|
|
*/ |
|
26
|
|
|
public function createDefault(): void |
|
27
|
|
|
{ |
|
28
|
|
|
$this->setDefaultContent(); |
|
29
|
|
|
$fileController = $this->generator->formatControllersPath() |
|
30
|
|
|
. PhpInterface::SLASH |
|
31
|
|
|
. $this->generator->defaultController |
|
32
|
|
|
. DefaultInterface::CONTROLLER_POSTFIX |
|
33
|
|
|
. PhpInterface::PHP_EXT; |
|
34
|
|
|
|
|
35
|
|
|
$isCreated = FileManager::createFile($fileController, $this->sourceCode); |
|
36
|
|
|
if($isCreated) |
|
37
|
|
|
{ |
|
38
|
|
|
Console::out($fileController . PhpInterface::SPACE . Console::CREATED, Console::COLOR_GREEN); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function resetContent() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->setBeforeProps($this->getEntityFile($this->generator->formatControllersPath(), DefaultInterface::CONTROLLER_POSTFIX)); |
|
45
|
|
|
$this->setComment(DefaultInterface::PROPS_START, 0); |
|
46
|
|
|
$this->setAfterProps(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Sets *Controller content |
|
51
|
|
|
*/ |
|
52
|
|
|
protected function setContent() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->setTag(); |
|
55
|
|
|
$this->setNamespace( |
|
56
|
|
|
$this->generator->httpDir . PhpInterface::BACKSLASH . $this->generator->controllersDir |
|
57
|
|
|
); |
|
58
|
|
|
$this->startClass( |
|
59
|
|
|
$this->className . DefaultInterface::CONTROLLER_POSTFIX, |
|
60
|
|
|
$this->generator->defaultController . DefaultInterface::CONTROLLER_POSTFIX |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
|
|
// set props comments to preserve user-land code on regen |
|
64
|
|
|
$this->setComment(DefaultInterface::PROPS_START); |
|
65
|
|
|
$this->setComment(DefaultInterface::PROPS_END); |
|
66
|
|
|
|
|
67
|
|
|
if (empty($this->generator->options[ConsoleInterface::OPTION_NO_DOCS])) { |
|
68
|
|
|
$this->setControllersDocs(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$this->endClass(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Sets the DefaultController content |
|
76
|
|
|
* |
|
77
|
|
|
* @throws \ReflectionException |
|
78
|
|
|
*/ |
|
79
|
|
|
private function setDefaultContent() |
|
80
|
|
|
{ |
|
81
|
|
|
$this->setTag(); |
|
82
|
|
|
$this->setNamespace( |
|
83
|
|
|
$this->generator->httpDir . PhpInterface::BACKSLASH . $this->generator->controllersDir |
|
84
|
|
|
); |
|
85
|
|
|
$baseFullMapper = BaseController::class; |
|
86
|
|
|
$baseMapperName = Classes::getName($baseFullMapper); |
|
87
|
|
|
|
|
88
|
|
|
$this->setUse($baseFullMapper, false, true); |
|
89
|
|
|
$this->startClass($this->generator->defaultController . DefaultInterface::CONTROLLER_POSTFIX, $baseMapperName); |
|
90
|
|
|
|
|
91
|
|
|
// set props comments to preserve user-land code on regen |
|
92
|
|
|
$this->setComment(DefaultInterface::PROPS_START); |
|
93
|
|
|
$this->setComment(DefaultInterface::PROPS_END); |
|
94
|
|
|
|
|
95
|
|
|
if (empty($this->generator->options[ConsoleInterface::OPTION_NO_DOCS])) { |
|
96
|
|
|
$this->setDefaultDocs(); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
$this->endClass(); |
|
100
|
|
|
} |
|
101
|
|
|
} |