1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Contains the ConcordDefault convention class. |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2017 Attila Fulop |
6
|
|
|
* @author Attila Fulop |
7
|
|
|
* @license MIT |
8
|
|
|
* @since 2017-04-14 |
9
|
|
|
* |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
namespace Konekt\Concord\Conventions; |
14
|
|
|
|
15
|
|
|
use Konekt\Concord\Contracts\Convention; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Concord's default conventions |
19
|
|
|
*/ |
20
|
|
|
class ConcordDefault extends BaseConvention implements Convention |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @inheritdoc |
25
|
|
|
*/ |
26
|
|
|
public function modulesFolder() : string |
27
|
|
|
{ |
28
|
|
|
return 'Modules'; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @inheritDoc |
33
|
|
|
*/ |
34
|
|
|
public function modelsFolder(): string |
35
|
|
|
{ |
36
|
|
|
return 'Models'; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @inheritDoc |
41
|
|
|
*/ |
42
|
|
|
public function contractsFolder(): string |
43
|
|
|
{ |
44
|
|
|
return 'Contracts'; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @inheritDoc |
49
|
|
|
*/ |
50
|
|
|
public function controllersFolder(): string |
51
|
|
|
{ |
52
|
|
|
return 'Http/Controllers'; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @inheritDoc |
57
|
|
|
*/ |
58
|
|
|
public function requestsFolder(): string |
59
|
|
|
{ |
60
|
|
|
return 'Http/Requests'; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @inheritDoc |
65
|
|
|
*/ |
66
|
|
|
public function resourcesFolder(): string |
67
|
|
|
{ |
68
|
|
|
return 'Http/Resources'; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @inheritDoc |
73
|
|
|
*/ |
74
|
|
|
public function contractForRequest(string $requestClass): string |
75
|
|
|
{ |
76
|
|
|
return sprintf( |
77
|
|
|
'%s\\Contracts\\Requests\\%s', |
78
|
|
|
$this->oneLevelUp($this->oneLevelUp($this->getNamespace($requestClass))), |
79
|
|
|
class_basename($requestClass) |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @inheritDoc |
86
|
|
|
*/ |
87
|
|
|
public function contractForModel(string $modelClass) : string |
88
|
|
|
{ |
89
|
|
|
return sprintf( |
90
|
|
|
'%s\\Contracts\\%s', |
91
|
|
|
$this->oneLevelUp($this->getNamespace($modelClass)), |
92
|
|
|
class_basename($modelClass) |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @inheritDoc |
98
|
|
|
*/ |
99
|
|
|
public function modelForRepository(string $repositoryClass): string |
100
|
|
|
{ |
101
|
|
|
return str_replace_last('Repository', '', $repositoryClass); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @inheritDoc |
106
|
|
|
*/ |
107
|
|
|
public function modelForProxy(string $proxyClass): string |
108
|
|
|
{ |
109
|
|
|
return str_replace_last('Proxy', '', $proxyClass); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @inheritDoc |
114
|
|
|
*/ |
115
|
|
|
public function repositoryForModel(string $modelClass) : string |
116
|
|
|
{ |
117
|
|
|
return $modelClass . 'Repository'; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @inheritDoc |
122
|
|
|
*/ |
123
|
|
|
public function proxyForModel(string $modelClass) : string |
124
|
|
|
{ |
125
|
|
|
return $modelClass . 'Proxy'; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @inheritDoc |
130
|
|
|
*/ |
131
|
|
|
public function manifestFile() : string |
132
|
|
|
{ |
133
|
|
|
return 'resources/manifest.php'; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @inheritDoc |
138
|
|
|
*/ |
139
|
|
|
public function configFolder(): string |
140
|
|
|
{ |
141
|
|
|
return 'resources/config'; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @inheritDoc |
146
|
|
|
*/ |
147
|
|
|
public function migrationsFolder(): string |
148
|
|
|
{ |
149
|
|
|
return 'resources/database/migrations'; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @inheritDoc |
154
|
|
|
*/ |
155
|
|
|
public function viewsFolder(): string |
156
|
|
|
{ |
157
|
|
|
return 'resources/views'; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @inheritDoc |
162
|
|
|
*/ |
163
|
|
|
public function routesFolder(): string |
164
|
|
|
{ |
165
|
|
|
return 'resources/routes'; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @inheritDoc |
170
|
|
|
*/ |
171
|
|
|
public function providersFolder(): string |
172
|
|
|
{ |
173
|
|
|
return 'Providers'; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @inheritDoc |
179
|
|
|
*/ |
180
|
|
|
public function enumsFolder(): string |
181
|
|
|
{ |
182
|
|
|
return 'Models'; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @inheritDoc |
187
|
|
|
*/ |
188
|
|
|
public function contractForEnum(string $enumClass): string |
189
|
|
|
{ |
190
|
|
|
// Enums are in the same folder as models, so we use the existing method |
191
|
|
|
return $this->contractForModel($enumClass); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @inheritDoc |
196
|
|
|
*/ |
197
|
|
|
public function proxyForEnum(string $enumClass): string |
198
|
|
|
{ |
199
|
|
|
// Identical with model proxies |
200
|
|
|
return $this->proxyForModel($enumClass); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @inheritDoc |
205
|
|
|
*/ |
206
|
|
|
public function enumForProxy(string $proxyClass): string |
207
|
|
|
{ |
208
|
|
|
// Identical with model proxies |
209
|
|
|
return $this->modelForProxy($proxyClass); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @inheritdoc |
214
|
|
|
*/ |
215
|
|
|
public function proxyForEnumContract(string $enumContract) |
216
|
|
|
{ |
217
|
|
|
return $this->proxyForEnum( |
218
|
|
|
$this->defaultEnumClassForContract($enumContract) |
219
|
|
|
); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @inheritdoc |
224
|
|
|
*/ |
225
|
|
|
public function proxyForModelContract(string $modelContract): string |
226
|
|
|
{ |
227
|
|
|
return $this->proxyForModel( |
228
|
|
|
$this->defaultModelClassForContract($modelContract) |
229
|
|
|
); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Returns the convention's default enum class for an enum contract |
234
|
|
|
* |
235
|
|
|
* @param $enumContract |
236
|
|
|
* |
237
|
|
|
* @return string |
238
|
|
|
*/ |
239
|
|
|
protected function defaultEnumClassForContract($enumContract) |
240
|
|
|
{ |
241
|
|
|
return |
242
|
|
|
$this->oneLevelUp($this->getNamespace($enumContract)) |
243
|
|
|
. '\\' . $this->enumsFolder() |
244
|
|
|
. '\\' . class_basename($enumContract); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* Returns the convention's default model class for a model contract |
249
|
|
|
* |
250
|
|
|
* @param $modelContract |
251
|
|
|
* |
252
|
|
|
* @return string |
253
|
|
|
*/ |
254
|
|
|
protected function defaultModelClassForContract($modelContract) |
255
|
|
|
{ |
256
|
|
|
return |
257
|
|
|
$this->oneLevelUp($this->getNamespace($modelContract)) |
258
|
|
|
. '\\' . $this->modelsFolder() |
259
|
|
|
. '\\' . class_basename($modelContract); |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
|