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