1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SoliDry\Blocks; |
4
|
|
|
|
5
|
|
|
use SoliDry\Controllers\BaseCommand; |
6
|
|
|
use SoliDry\Extension\JSONApiInterface; |
7
|
|
|
use SoliDry\Helpers\Classes; |
8
|
|
|
use SoliDry\Types\DefaultInterface; |
9
|
|
|
use SoliDry\Types\DirsInterface; |
10
|
|
|
use SoliDry\Types\ModelsInterface; |
11
|
|
|
use SoliDry\Types\PhpInterface; |
12
|
|
|
use SoliDry\Types\ApiInterface; |
13
|
|
|
use SoliDry\Types\RoutesInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Trait RoutesTrait |
17
|
|
|
* @package SoliDry\Blocks |
18
|
|
|
* |
19
|
|
|
* @property BaseCommand generator |
20
|
|
|
*/ |
21
|
|
|
trait RoutesTrait |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @param string $version |
25
|
|
|
*/ |
26
|
|
|
public function openGroup() : void |
27
|
|
|
{ |
28
|
|
|
$versionNamespace = DirsInterface::MODULES_DIR . |
29
|
|
|
PhpInterface::BACKSLASH . PhpInterface::BACKSLASH |
30
|
|
|
. strtoupper($this->generator->version); |
31
|
|
|
|
32
|
|
|
$this->sourceCode .= RoutesInterface::CLASS_ROUTE . PhpInterface::DOUBLE_COLON |
33
|
|
|
. RoutesInterface::METHOD_GROUP . PhpInterface::OPEN_PARENTHESES |
34
|
|
|
. PhpInterface::OPEN_BRACKET |
35
|
|
|
. PhpInterface::QUOTES . DefaultInterface::PREFIX_KEY . |
36
|
|
|
PhpInterface::QUOTES |
37
|
|
|
. PhpInterface::SPACE . PhpInterface::DOUBLE_ARROW . |
38
|
|
|
PhpInterface::SPACE |
39
|
|
|
. PhpInterface::QUOTES . $this->generator->version . PhpInterface::QUOTES |
40
|
|
|
. PhpInterface::COMMA . PhpInterface::SPACE . |
41
|
|
|
PhpInterface::QUOTES |
42
|
|
|
. PhpInterface::PHP_NAMESPACE . PhpInterface::QUOTES |
43
|
|
|
. PhpInterface::SPACE . PhpInterface::DOUBLE_ARROW |
44
|
|
|
. PhpInterface::SPACE . PhpInterface::QUOTES; |
45
|
|
|
|
46
|
|
|
$this->setBackslashes(2); |
|
|
|
|
47
|
|
|
$this->sourceCode .= $versionNamespace; |
48
|
|
|
|
49
|
|
|
$this->setBackslashes(2); |
50
|
|
|
$this->sourceCode .= DirsInterface::HTTP_DIR; |
51
|
|
|
|
52
|
|
|
$this->setBackslashes(2); |
53
|
|
|
$this->sourceCode .= DirsInterface::CONTROLLERS_DIR . PhpInterface::QUOTES |
54
|
|
|
. PhpInterface::CLOSE_BRACKET . PhpInterface::COMMA |
55
|
|
|
. PhpInterface::SPACE . PhpInterface::PHP_FUNCTION . |
56
|
|
|
PhpInterface::OPEN_PARENTHESES |
57
|
|
|
. PhpInterface::CLOSE_PARENTHESES . PHP_EOL; |
58
|
|
|
|
59
|
|
|
$this->sourceCode .= PhpInterface::OPEN_BRACE . PHP_EOL; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function closeGroup() : void |
63
|
|
|
{ |
64
|
|
|
$this->sourceCode .= PhpInterface::CLOSE_BRACE . PhpInterface::CLOSE_PARENTHESES |
65
|
|
|
. PhpInterface::SEMICOLON . PHP_EOL; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Sets route to sourceCode |
70
|
|
|
* |
71
|
|
|
* @param string $method |
72
|
|
|
* @param string $uri |
73
|
|
|
* @param string $endPoint |
74
|
|
|
*/ |
75
|
|
|
public function setRoute(string $method, string $uri, string $endPoint) : void |
76
|
|
|
{ |
77
|
|
|
$this->sourceCode .= PhpInterface::TAB_PSR4 . RoutesInterface::CLASS_ROUTE . |
78
|
|
|
PhpInterface::DOUBLE_COLON |
79
|
|
|
. $method . PhpInterface::OPEN_PARENTHESES . $uri . PhpInterface::COMMA . |
80
|
|
|
PhpInterface::SPACE . $endPoint . PhpInterface::CLOSE_PARENTHESES . |
81
|
|
|
PhpInterface::SEMICOLON . PHP_EOL; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
private function composeRelationsUri() : string |
88
|
|
|
{ |
89
|
|
|
return $this->composeRelationsBaseUri() . PhpInterface::SLASH . ApiInterface::RAML_RELATIONSHIPS |
90
|
|
|
. PhpInterface::SLASH . PhpInterface::OPEN_BRACE |
91
|
|
|
. ModelsInterface::MODEL_METHOD_RELATIONS . PhpInterface::CLOSE_BRACE . PhpInterface::QUOTES; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
private function composeRelatedUri() : string |
95
|
|
|
{ |
96
|
|
|
return $this->composeRelationsBaseUri() . PhpInterface::SLASH . PhpInterface::OPEN_BRACE |
97
|
|
|
. JSONApiInterface::URI_METHOD_RELATED . PhpInterface::CLOSE_BRACE . PhpInterface::QUOTES; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
private function composeIdUri() : string |
104
|
|
|
{ |
105
|
|
|
return $this->composeBaseUri() . PhpInterface::SLASH . PhpInterface::OPEN_BRACE |
106
|
|
|
. ApiInterface::RAML_ID . PhpInterface::CLOSE_BRACE . PhpInterface::QUOTES; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Creates bulk requests uri |
111
|
|
|
* |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
|
|
private function composeBulkUri() : string |
115
|
|
|
{ |
116
|
|
|
return $this->composeBaseUri() . PhpInterface::SLASH . JSONApiInterface::EXT_BULK . PhpInterface::QUOTES; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Creates standard object uri |
121
|
|
|
* |
122
|
|
|
* @return string |
123
|
|
|
*/ |
124
|
|
|
private function composeObjectUri() : string |
125
|
|
|
{ |
126
|
|
|
return $this->composeBaseUri() . PhpInterface::QUOTES; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Creates base uri |
131
|
|
|
* |
132
|
|
|
* @return string |
133
|
|
|
*/ |
134
|
|
|
private function composeBaseUri() : string |
135
|
|
|
{ |
136
|
|
|
return PhpInterface::QUOTES . PhpInterface::SLASH . strtolower($this->generator->objectName); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Creates base uri for relations |
141
|
|
|
* @return string |
142
|
|
|
*/ |
143
|
|
|
private function composeRelationsBaseUri() : string |
144
|
|
|
{ |
145
|
|
|
return PhpInterface::QUOTES . PhpInterface::SLASH . strtolower($this->generator->objectName) . |
146
|
|
|
PhpInterface::SLASH . PhpInterface::OPEN_BRACE |
147
|
|
|
. ApiInterface::RAML_ID . PhpInterface::CLOSE_BRACE; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Creates controller@method end-point |
152
|
|
|
* |
153
|
|
|
* @param string $uriMethod |
154
|
|
|
* @return string |
155
|
|
|
*/ |
156
|
|
|
private function composeEndPoint(string $uriMethod) : string |
157
|
|
|
{ |
158
|
|
|
return PhpInterface::QUOTES . |
159
|
|
|
Classes::getClassName($this->generator->objectName) . DefaultInterface::CONTROLLER_POSTFIX |
160
|
|
|
. PhpInterface::AT . $uriMethod |
161
|
|
|
. PhpInterface::QUOTES; |
162
|
|
|
} |
163
|
|
|
} |