20
20
use Doctrine \DBAL \Exception as DBALException ;
21
21
use Doctrine \DBAL \Types \Type ;
22
22
use Illuminate \Console \Command ;
23
+ use Illuminate \Contracts \Config \Repository as Config ;
23
24
use Illuminate \Contracts \Database \Eloquent \CastsAttributes ;
24
25
use Illuminate \Database \Eloquent \Factories \Factory ;
25
26
use Illuminate \Database \Eloquent \Model ;
@@ -72,6 +73,11 @@ class ModelsCommand extends Command
72
73
*/
73
74
protected $ files ;
74
75
76
+ /**
77
+ * @var Config
78
+ */
79
+ protected $ config ;
80
+
75
81
/**
76
82
* The console command name.
77
83
*
@@ -119,13 +125,12 @@ class ModelsCommand extends Command
119
125
*/
120
126
protected $ dateClass ;
121
127
122
- /**
123
- * @param Filesystem $files
124
- */
125
- public function __construct (Filesystem $ files )
128
+ public function __construct (Filesystem $ files , Config $ config )
126
129
{
130
+ $ this ->files = $ files ;
131
+ $ this ->config = $ config ;
132
+
127
133
parent ::__construct ();
128
- $ this ->files = $ files ;
129
134
}
130
135
131
136
/**
@@ -140,7 +145,7 @@ public function handle()
140
145
$ this ->write = $ this ->option ('write ' );
141
146
$ this ->write_mixin = $ this ->option ('write-mixin ' );
142
147
$ this ->dirs = array_merge (
143
- $ this ->laravel [ ' config ' ] ->get ('ide-helper.model_locations ' , []),
148
+ $ this ->config ->get ('ide-helper.model_locations ' , []),
144
149
$ this ->option ('dir ' )
145
150
);
146
151
$ model = $ this ->argument ('model ' );
@@ -150,10 +155,10 @@ public function handle()
150
155
if ($ this ->option ('smart-reset ' )) {
151
156
$ this ->keep_text = $ this ->reset = true ;
152
157
}
153
- $ this ->write_model_magic_where = $ this ->laravel [ ' config ' ] ->get ('ide-helper.write_model_magic_where ' , true );
154
- $ this ->write_model_external_builder_methods = $ this ->laravel [ ' config ' ] ->get ('ide-helper.write_model_external_builder_methods ' , true );
158
+ $ this ->write_model_magic_where = $ this ->config ->get ('ide-helper.write_model_magic_where ' , true );
159
+ $ this ->write_model_external_builder_methods = $ this ->config ->get ('ide-helper.write_model_external_builder_methods ' , true );
155
160
$ this ->write_model_relation_count_properties =
156
- $ this ->laravel [ ' config ' ] ->get ('ide-helper.write_model_relation_count_properties ' , true );
161
+ $ this ->config ->get ('ide-helper.write_model_relation_count_properties ' , true );
157
162
158
163
$ this ->write = $ this ->write_mixin ? true : $ this ->write ;
159
164
//If filename is default and Write is not specified, ask what to do
@@ -249,7 +254,7 @@ protected function generateDocs($loadModels, $ignore = '')
249
254
250
255
$ ignore = array_merge (
251
256
explode (', ' , $ ignore ),
252
- $ this ->laravel [ ' config ' ] ->get ('ide-helper.ignored_models ' , [])
257
+ $ this ->config ->get ('ide-helper.ignored_models ' , [])
253
258
);
254
259
255
260
foreach ($ models as $ name ) {
@@ -417,7 +422,7 @@ public function castPropertiesType($model)
417
422
*/
418
423
protected function getTypeOverride ($ type )
419
424
{
420
- $ typeOverrides = $ this ->laravel [ ' config ' ] ->get ('ide-helper.type_overrides ' , []);
425
+ $ typeOverrides = $ this ->config ->get ('ide-helper.type_overrides ' , []);
421
426
422
427
return $ typeOverrides [$ type ] ?? $ type ;
423
428
}
@@ -437,7 +442,7 @@ public function getPropertiesFromTable($model)
437
442
$ databasePlatform ->registerDoctrineTypeMapping ('enum ' , 'string ' );
438
443
439
444
$ platformName = $ databasePlatform ->getName ();
440
- $ customTypes = $ this ->laravel [ ' config ' ] ->get ("ide-helper.custom_db_types. {$ platformName }" , []);
445
+ $ customTypes = $ this ->config ->get ("ide-helper.custom_db_types. {$ platformName }" , []);
441
446
foreach ($ customTypes as $ yourTypeName => $ doctrineTypeName ) {
442
447
try {
443
448
if (!Type::hasType ($ yourTypeName )) {
@@ -1015,7 +1020,7 @@ protected function getCollectionClass($className)
1015
1020
*/
1016
1021
protected function getRelationTypes (): array
1017
1022
{
1018
- $ configuredRelations = $ this ->laravel [ ' config ' ] ->get ('ide-helper.additional_relation_types ' , []);
1023
+ $ configuredRelations = $ this ->config ->get ('ide-helper.additional_relation_types ' , []);
1019
1024
return array_merge (self ::RELATION_TYPES , $ configuredRelations );
1020
1025
}
1021
1026
@@ -1024,7 +1029,7 @@ protected function getRelationTypes(): array
1024
1029
*/
1025
1030
protected function hasCamelCaseModelProperties ()
1026
1031
{
1027
- return $ this ->laravel [ ' config ' ] ->get ('ide-helper.model_camel_case_properties ' , false );
1032
+ return $ this ->config ->get ('ide-helper.model_camel_case_properties ' , false );
1028
1033
}
1029
1034
1030
1035
protected function getReturnType (\ReflectionMethod $ reflection ): ?string
@@ -1242,7 +1247,7 @@ protected function getClassNameInDestinationFile(object $model, string $classNam
1242
1247
$ className = trim ($ className , '\\' );
1243
1248
$ writingToExternalFile = !$ this ->write || $ this ->write_mixin ;
1244
1249
$ classIsNotInExternalFile = $ reflection ->getName () !== $ className ;
1245
- $ forceFQCN = $ this ->laravel [ ' config ' ] ->get ('ide-helper.force_fqn ' , false );
1250
+ $ forceFQCN = $ this ->config ->get ('ide-helper.force_fqn ' , false );
1246
1251
1247
1252
if (($ writingToExternalFile && $ classIsNotInExternalFile ) || $ forceFQCN ) {
1248
1253
return '\\' . $ className ;
@@ -1410,7 +1415,7 @@ protected function getReflectionNamedType(ReflectionNamedType $paramType): strin
1410
1415
*/
1411
1416
protected function runModelHooks ($ model ): void
1412
1417
{
1413
- $ hooks = $ this ->laravel [ ' config ' ] ->get ('ide-helper.model_hooks ' , []);
1418
+ $ hooks = $ this ->config ->get ('ide-helper.model_hooks ' , []);
1414
1419
1415
1420
foreach ($ hooks as $ hook ) {
1416
1421
$ hookInstance = $ this ->laravel ->make ($ hook );
0 commit comments