1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Contains the ConcordDefault convention class. |
7
|
|
|
* |
8
|
|
|
* @copyright Copyright (c) 2017 Attila Fulop |
9
|
|
|
* @author Attila Fulop |
10
|
|
|
* @license MIT |
11
|
|
|
* @since 2017-04-14 |
12
|
|
|
* |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Konekt\Concord\Conventions; |
16
|
|
|
|
17
|
|
|
use Illuminate\Support\Str; |
18
|
|
|
use Konekt\Concord\Contracts\Convention; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Concord's default conventions |
22
|
|
|
*/ |
23
|
|
|
class ConcordDefault extends BaseConvention implements Convention |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @inheritdoc |
27
|
|
|
*/ |
28
|
|
|
public function modulesFolder(): string |
29
|
|
|
{ |
30
|
|
|
return 'Modules'; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @inheritDoc |
35
|
|
|
*/ |
36
|
|
|
public function modelsFolder(): string |
37
|
|
|
{ |
38
|
|
|
return 'Models'; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @inheritDoc |
43
|
|
|
*/ |
44
|
|
|
public function contractsFolder(): string |
45
|
|
|
{ |
46
|
|
|
return 'Contracts'; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @inheritDoc |
51
|
|
|
*/ |
52
|
|
|
public function controllersFolder(): string |
53
|
|
|
{ |
54
|
|
|
return 'Http/Controllers'; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @inheritDoc |
59
|
|
|
*/ |
60
|
|
|
public function requestsFolder(): string |
61
|
|
|
{ |
62
|
|
|
return 'Http/Requests'; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @inheritDoc |
67
|
|
|
*/ |
68
|
|
|
public function resourcesFolder(): string |
69
|
|
|
{ |
70
|
|
|
return 'Http/Resources'; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @inheritDoc |
75
|
|
|
*/ |
76
|
|
|
public function contractForRequest(string $requestClass): string |
77
|
|
|
{ |
78
|
|
|
return sprintf( |
79
|
|
|
'%s\\Contracts\\Requests\\%s', |
80
|
|
|
$this->oneLevelUp($this->oneLevelUp($this->getNamespace($requestClass))), |
81
|
|
|
class_basename($requestClass) |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @inheritDoc |
87
|
|
|
*/ |
88
|
|
|
public function contractForModel(string $modelClass): string |
89
|
|
|
{ |
90
|
|
|
return sprintf( |
91
|
|
|
'%s\\Contracts\\%s', |
92
|
|
|
$this->oneLevelUp($this->getNamespace($modelClass)), |
93
|
|
|
class_basename($modelClass) |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @inheritDoc |
99
|
|
|
*/ |
100
|
|
|
public function modelForRepository(string $repositoryClass): string |
101
|
|
|
{ |
102
|
|
|
return Str::replaceLast('Repository', '', $repositoryClass); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @inheritDoc |
107
|
|
|
*/ |
108
|
|
|
public function modelForProxy(string $proxyClass): string |
109
|
|
|
{ |
110
|
|
|
return Str::replaceLast('Proxy', '', $proxyClass); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @inheritDoc |
115
|
|
|
*/ |
116
|
|
|
public function repositoryForModel(string $modelClass): string |
117
|
|
|
{ |
118
|
|
|
return $modelClass . 'Repository'; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @inheritDoc |
123
|
|
|
*/ |
124
|
|
|
public function proxyForModel(string $modelClass): string |
125
|
|
|
{ |
126
|
|
|
return $modelClass . 'Proxy'; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @inheritDoc |
131
|
|
|
*/ |
132
|
|
|
public function manifestFile(): string |
133
|
|
|
{ |
134
|
|
|
return 'resources/manifest.php'; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @inheritDoc |
139
|
|
|
*/ |
140
|
|
|
public function configFolder(): string |
141
|
|
|
{ |
142
|
|
|
return 'resources/config'; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @inheritDoc |
147
|
|
|
*/ |
148
|
|
|
public function migrationsFolder(): string |
149
|
|
|
{ |
150
|
|
|
return 'resources/database/migrations'; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @inheritDoc |
155
|
|
|
*/ |
156
|
|
|
public function viewsFolder(): string |
157
|
|
|
{ |
158
|
|
|
return 'resources/views'; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @inheritDoc |
163
|
|
|
*/ |
164
|
|
|
public function routesFolder(): string |
165
|
|
|
{ |
166
|
|
|
return 'resources/routes'; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @inheritDoc |
171
|
|
|
*/ |
172
|
|
|
public function providersFolder(): string |
173
|
|
|
{ |
174
|
|
|
return 'Providers'; |
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
|
|
|
|