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