|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Mnabialek\LaravelModular\Services; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Foundation\Application; |
|
6
|
|
|
|
|
7
|
|
|
class Config |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Name for module config file (without .php extension) |
|
11
|
|
|
* |
|
12
|
|
|
* @var string |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $configName = 'modular'; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var Application |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $app; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Config constructor. |
|
23
|
|
|
* |
|
24
|
|
|
* @param Application $app |
|
25
|
|
|
*/ |
|
26
|
|
|
public function __construct(Application $app) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->app = $app; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Get config file name |
|
33
|
|
|
* |
|
34
|
|
|
* @return string |
|
35
|
|
|
*/ |
|
36
|
|
|
public function configName() |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->configName; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Get full path where configuration file should be placed |
|
43
|
|
|
* |
|
44
|
|
|
* @return string |
|
45
|
|
|
*/ |
|
46
|
|
|
public function configPath() |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->app['path.config'] . DIRECTORY_SEPARATOR . |
|
49
|
|
|
"{$this->configName()}.php"; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Get value from module configuration file |
|
54
|
|
|
* |
|
55
|
|
|
* @param string|null $key |
|
56
|
|
|
* @param mixed $default |
|
57
|
|
|
* |
|
58
|
|
|
* @return mixed |
|
59
|
|
|
*/ |
|
60
|
|
|
protected function get($key = null, $default = null) |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->app['config']->get("{$this->configName()}.{$key}", |
|
63
|
|
|
$default); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Get modules configuration |
|
68
|
|
|
* |
|
69
|
|
|
* @return array |
|
70
|
|
|
*/ |
|
71
|
|
|
public function modules() |
|
72
|
|
|
{ |
|
73
|
|
|
return (array)$this->get('modules'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Get directory where modules will be stored |
|
78
|
|
|
* |
|
79
|
|
|
* @return string |
|
80
|
|
|
*/ |
|
81
|
|
|
public function directory() |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->get('directory'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Get namespace prefix for all modules |
|
88
|
|
|
* |
|
89
|
|
|
* @return string |
|
90
|
|
|
*/ |
|
91
|
|
|
public function modulesNamespace() |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->get('namespace'); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Get seeder namespace prefix |
|
98
|
|
|
* |
|
99
|
|
|
* @return string |
|
100
|
|
|
*/ |
|
101
|
|
|
public function seederNamespace() |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->get('module_seeding.namespace'); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Get seeder file |
|
108
|
|
|
* |
|
109
|
|
|
* @return string |
|
110
|
|
|
*/ |
|
111
|
|
|
public function seederFile() |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->get('module_seeding.file'); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Get service provider filename |
|
118
|
|
|
* |
|
119
|
|
|
* @return string |
|
120
|
|
|
*/ |
|
121
|
|
|
public function serviceProviderNamespace() |
|
122
|
|
|
{ |
|
123
|
|
|
return $this->get('module_service_providers.namespace'); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Get namespace for controllers when loading routes |
|
128
|
|
|
* |
|
129
|
|
|
* @return string |
|
130
|
|
|
*/ |
|
131
|
|
|
public function routingControllerNamespace() |
|
132
|
|
|
{ |
|
133
|
|
|
return $this->get('module_routing.route_group_namespace'); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Get routing file |
|
138
|
|
|
* |
|
139
|
|
|
* @param string $prefix |
|
140
|
|
|
* |
|
141
|
|
|
* @return string |
|
142
|
|
|
*/ |
|
143
|
|
|
public function routingFile($prefix) |
|
144
|
|
|
{ |
|
145
|
|
|
return $this->get("module_routing.{$prefix}file"); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Get factory file |
|
150
|
|
|
* |
|
151
|
|
|
* @return string |
|
152
|
|
|
*/ |
|
153
|
|
|
public function factoryFile() |
|
154
|
|
|
{ |
|
155
|
|
|
return $this->get('module_factories.file'); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Get start separator for replacements |
|
160
|
|
|
* |
|
161
|
|
|
* @return string |
|
162
|
|
|
*/ |
|
163
|
|
|
public function startSeparator() |
|
164
|
|
|
{ |
|
165
|
|
|
return $this->get('separators.start'); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Get end separator for replacements |
|
170
|
|
|
* |
|
171
|
|
|
* @return string |
|
172
|
|
|
*/ |
|
173
|
|
|
public function endSeparator() |
|
174
|
|
|
{ |
|
175
|
|
|
return $this->get('separators.end'); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* Get default stubs group name when creating module |
|
180
|
|
|
* |
|
181
|
|
|
* @return string |
|
182
|
|
|
*/ |
|
183
|
|
|
public function stubsDefaultGroup() |
|
184
|
|
|
{ |
|
185
|
|
|
return $this->get('stubs.module_default_group'); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Get default stubs group name when creating module files |
|
190
|
|
|
* |
|
191
|
|
|
* @return string |
|
192
|
|
|
*/ |
|
193
|
|
|
public function filesStubsDefaultGroup() |
|
194
|
|
|
{ |
|
195
|
|
|
return $this->get('stubs.files_default_group'); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* Get default migration type |
|
200
|
|
|
* |
|
201
|
|
|
* @return string |
|
202
|
|
|
*/ |
|
203
|
|
|
public function migrationDefaultType() |
|
204
|
|
|
{ |
|
205
|
|
|
return $this->get('module_migrations.default_type'); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* Get stub name for migration of given type |
|
210
|
|
|
* |
|
211
|
|
|
* @param string $type |
|
212
|
|
|
* |
|
213
|
|
|
* @return string |
|
214
|
|
|
*/ |
|
215
|
|
|
public function migrationStubFileName($type) |
|
216
|
|
|
{ |
|
217
|
|
|
return $this->get("module_migrations.types.{$type}"); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* Get path where migrations are stored inside Module |
|
222
|
|
|
* |
|
223
|
|
|
* @return string |
|
224
|
|
|
*/ |
|
225
|
|
|
public function migrationsPath() |
|
226
|
|
|
{ |
|
227
|
|
|
return $this->get('module_migrations.path'); |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* Get service provider file |
|
232
|
|
|
* |
|
233
|
|
|
* @return string |
|
234
|
|
|
*/ |
|
235
|
|
|
public function serviceProviderFile() |
|
236
|
|
|
{ |
|
237
|
|
|
return $this->get('module_service_providers.file'); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* Get path where stubs are located |
|
242
|
|
|
* |
|
243
|
|
|
* @return string |
|
244
|
|
|
*/ |
|
245
|
|
|
public function stubsPath() |
|
246
|
|
|
{ |
|
247
|
|
|
return $this->get('stubs.path'); |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* Get relative directory for given stub group |
|
252
|
|
|
* |
|
253
|
|
|
* @param string $group |
|
254
|
|
|
* |
|
255
|
|
|
* @return string |
|
256
|
|
|
*/ |
|
257
|
|
|
public function stubGroupDirectory($group) |
|
258
|
|
|
{ |
|
259
|
|
|
return $this->get("stubs_groups.{$group}.stub_directory", $group); |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
/** |
|
263
|
|
|
* Get directories to create for given stub group |
|
264
|
|
|
* |
|
265
|
|
|
* @param string $group |
|
266
|
|
|
* |
|
267
|
|
|
* @return array |
|
268
|
|
|
*/ |
|
269
|
|
|
public function stubGroupDirectories($group) |
|
270
|
|
|
{ |
|
271
|
|
|
return (array)$this->get("stubs_groups.{$group}.directories", []); |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
/** |
|
275
|
|
|
* Get files to create for given stub group |
|
276
|
|
|
* |
|
277
|
|
|
* @param string $group |
|
278
|
|
|
* |
|
279
|
|
|
* @return array |
|
280
|
|
|
*/ |
|
281
|
|
|
public function stubGroupFiles($group) |
|
282
|
|
|
{ |
|
283
|
|
|
return (array)$this->get("stubs_groups.{$group}.files", []); |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
/** |
|
287
|
|
|
* Get all existing stub groups |
|
288
|
|
|
* |
|
289
|
|
|
* @return array |
|
290
|
|
|
*/ |
|
291
|
|
|
public function stubGroups() |
|
292
|
|
|
{ |
|
293
|
|
|
return array_keys((array)$this->get('stubs_groups', [])); |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
/** |
|
297
|
|
|
* Get auto add to configuration status |
|
298
|
|
|
* |
|
299
|
|
|
* @return bool |
|
300
|
|
|
*/ |
|
301
|
|
|
public function autoAdd() |
|
302
|
|
|
{ |
|
303
|
|
|
return (bool)$this->get('module_make.auto_add', false); |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
/** |
|
307
|
|
|
* Get auto add pattern |
|
308
|
|
|
* |
|
309
|
|
|
* @return string |
|
310
|
|
|
*/ |
|
311
|
|
|
public function autoAddPattern() |
|
312
|
|
|
{ |
|
313
|
|
|
return $this->get('module_make.pattern'); |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
/** |
|
317
|
|
|
* Get auto add template |
|
318
|
|
|
* |
|
319
|
|
|
* @return string |
|
320
|
|
|
*/ |
|
321
|
|
|
public function autoAddTemplate() |
|
322
|
|
|
{ |
|
323
|
|
|
return $this->get('module_make.module_template'); |
|
324
|
|
|
} |
|
325
|
|
|
} |
|
326
|
|
|
|