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
*
@@ -115,13 +121,12 @@ class ModelsCommand extends Command
115
121
*/
116
122
protected $ dateClass ;
117
123
118
- /**
119
- * @param Filesystem $files
120
- */
121
- public function __construct (Filesystem $ files )
124
+ public function __construct (Filesystem $ files , Config $ config )
122
125
{
126
+ $ this ->files = $ files ;
127
+ $ this ->config = $ config ;
128
+
123
129
parent ::__construct ();
124
- $ this ->files = $ files ;
125
130
}
126
131
127
132
/**
@@ -135,7 +140,7 @@ public function handle()
135
140
$ this ->write = $ this ->option ('write ' );
136
141
$ this ->write_mixin = $ this ->option ('write-mixin ' );
137
142
$ this ->dirs = array_merge (
138
- $ this ->laravel [ ' config ' ] ->get ('ide-helper.model_locations ' , []),
143
+ $ this ->config ->get ('ide-helper.model_locations ' , []),
139
144
$ this ->option ('dir ' )
140
145
);
141
146
$ model = $ this ->argument ('model ' );
@@ -145,10 +150,10 @@ public function handle()
145
150
if ($ this ->option ('smart-reset ' )) {
146
151
$ this ->keep_text = $ this ->reset = true ;
147
152
}
148
- $ this ->write_model_magic_where = $ this ->laravel [ ' config ' ] ->get ('ide-helper.write_model_magic_where ' , true );
149
- $ this ->write_model_external_builder_methods = $ this ->laravel [ ' config ' ] ->get ('ide-helper.write_model_external_builder_methods ' , true );
153
+ $ this ->write_model_magic_where = $ this ->config ->get ('ide-helper.write_model_magic_where ' , true );
154
+ $ this ->write_model_external_builder_methods = $ this ->config ->get ('ide-helper.write_model_external_builder_methods ' , true );
150
155
$ this ->write_model_relation_count_properties =
151
- $ this ->laravel [ ' config ' ] ->get ('ide-helper.write_model_relation_count_properties ' , true );
156
+ $ this ->config ->get ('ide-helper.write_model_relation_count_properties ' , true );
152
157
153
158
$ this ->write = $ this ->write_mixin ? true : $ this ->write ;
154
159
//If filename is default and Write is not specified, ask what to do
@@ -244,7 +249,7 @@ protected function generateDocs($loadModels, $ignore = '')
244
249
245
250
$ ignore = array_merge (
246
251
explode (', ' , $ ignore ),
247
- $ this ->laravel [ ' config ' ] ->get ('ide-helper.ignored_models ' , [])
252
+ $ this ->config ->get ('ide-helper.ignored_models ' , [])
248
253
);
249
254
250
255
foreach ($ models as $ name ) {
@@ -412,7 +417,7 @@ public function castPropertiesType($model)
412
417
*/
413
418
protected function getTypeOverride ($ type )
414
419
{
415
- $ typeOverrides = $ this ->laravel [ ' config ' ] ->get ('ide-helper.type_overrides ' , []);
420
+ $ typeOverrides = $ this ->config ->get ('ide-helper.type_overrides ' , []);
416
421
417
422
return $ typeOverrides [$ type ] ?? $ type ;
418
423
}
@@ -432,7 +437,7 @@ public function getPropertiesFromTable($model)
432
437
$ databasePlatform ->registerDoctrineTypeMapping ('enum ' , 'string ' );
433
438
434
439
$ platformName = $ databasePlatform ->getName ();
435
- $ customTypes = $ this ->laravel [ ' config ' ] ->get ("ide-helper.custom_db_types. {$ platformName }" , []);
440
+ $ customTypes = $ this ->config ->get ("ide-helper.custom_db_types. {$ platformName }" , []);
436
441
foreach ($ customTypes as $ yourTypeName => $ doctrineTypeName ) {
437
442
try {
438
443
if (!Type::hasType ($ yourTypeName )) {
@@ -1010,7 +1015,7 @@ protected function getCollectionClass($className)
1010
1015
*/
1011
1016
protected function getRelationTypes (): array
1012
1017
{
1013
- $ configuredRelations = $ this ->laravel [ ' config ' ] ->get ('ide-helper.additional_relation_types ' , []);
1018
+ $ configuredRelations = $ this ->config ->get ('ide-helper.additional_relation_types ' , []);
1014
1019
return array_merge (self ::RELATION_TYPES , $ configuredRelations );
1015
1020
}
1016
1021
@@ -1019,7 +1024,7 @@ protected function getRelationTypes(): array
1019
1024
*/
1020
1025
protected function hasCamelCaseModelProperties ()
1021
1026
{
1022
- return $ this ->laravel [ ' config ' ] ->get ('ide-helper.model_camel_case_properties ' , false );
1027
+ return $ this ->config ->get ('ide-helper.model_camel_case_properties ' , false );
1023
1028
}
1024
1029
1025
1030
protected function getReturnType (\ReflectionMethod $ reflection ): ?string
@@ -1237,7 +1242,7 @@ protected function getClassNameInDestinationFile(object $model, string $classNam
1237
1242
$ className = trim ($ className , '\\' );
1238
1243
$ writingToExternalFile = !$ this ->write || $ this ->write_mixin ;
1239
1244
$ classIsNotInExternalFile = $ reflection ->getName () !== $ className ;
1240
- $ forceFQCN = $ this ->laravel [ ' config ' ] ->get ('ide-helper.force_fqn ' , false );
1245
+ $ forceFQCN = $ this ->config ->get ('ide-helper.force_fqn ' , false );
1241
1246
1242
1247
if (($ writingToExternalFile && $ classIsNotInExternalFile ) || $ forceFQCN ) {
1243
1248
return '\\' . $ className ;
@@ -1405,7 +1410,7 @@ protected function getReflectionNamedType(ReflectionNamedType $paramType): strin
1405
1410
*/
1406
1411
protected function runModelHooks ($ model ): void
1407
1412
{
1408
- $ hooks = $ this ->laravel [ ' config ' ] ->get ('ide-helper.model_hooks ' , []);
1413
+ $ hooks = $ this ->config ->get ('ide-helper.model_hooks ' , []);
1409
1414
1410
1415
foreach ($ hooks as $ hook ) {
1411
1416
$ hookInstance = $ this ->laravel ->make ($ hook );
0 commit comments