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