2020use Doctrine \DBAL \Exception as DBALException ;
2121use Doctrine \DBAL \Types \Type ;
2222use Illuminate \Console \Command ;
23+ use Illuminate \Contracts \Config \Repository as Config ;
2324use Illuminate \Contracts \Database \Eloquent \CastsAttributes ;
2425use Illuminate \Database \Eloquent \Factories \Factory ;
2526use Illuminate \Database \Eloquent \Model ;
@@ -72,6 +73,11 @@ class ModelsCommand extends Command
7273 */
7374 protected $ files ;
7475
76+ /**
77+ * @var Config
78+ */
79+ protected $ config ;
80+
7581 /**
7682 * The console command name.
7783 *
@@ -115,13 +121,12 @@ class ModelsCommand extends Command
115121 */
116122 protected $ dateClass ;
117123
118- /**
119- * @param Filesystem $files
120- */
121- public function __construct (Filesystem $ files )
124+ public function __construct (Filesystem $ files , Config $ config )
122125 {
126+ $ this ->files = $ files ;
127+ $ this ->config = $ config ;
128+
123129 parent ::__construct ();
124- $ this ->files = $ files ;
125130 }
126131
127132 /**
@@ -135,7 +140,7 @@ public function handle()
135140 $ this ->write = $ this ->option ('write ' );
136141 $ this ->write_mixin = $ this ->option ('write-mixin ' );
137142 $ this ->dirs = array_merge (
138- $ this ->laravel [ ' config ' ] ->get ('ide-helper.model_locations ' , []),
143+ $ this ->config ->get ('ide-helper.model_locations ' , []),
139144 $ this ->option ('dir ' )
140145 );
141146 $ model = $ this ->argument ('model ' );
@@ -145,10 +150,10 @@ public function handle()
145150 if ($ this ->option ('smart-reset ' )) {
146151 $ this ->keep_text = $ this ->reset = true ;
147152 }
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 );
150155 $ 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 );
152157
153158 $ this ->write = $ this ->write_mixin ? true : $ this ->write ;
154159 //If filename is default and Write is not specified, ask what to do
@@ -244,7 +249,7 @@ protected function generateDocs($loadModels, $ignore = '')
244249
245250 $ ignore = array_merge (
246251 explode (', ' , $ ignore ),
247- $ this ->laravel [ ' config ' ] ->get ('ide-helper.ignored_models ' , [])
252+ $ this ->config ->get ('ide-helper.ignored_models ' , [])
248253 );
249254
250255 foreach ($ models as $ name ) {
@@ -412,7 +417,7 @@ public function castPropertiesType($model)
412417 */
413418 protected function getTypeOverride ($ type )
414419 {
415- $ typeOverrides = $ this ->laravel [ ' config ' ] ->get ('ide-helper.type_overrides ' , []);
420+ $ typeOverrides = $ this ->config ->get ('ide-helper.type_overrides ' , []);
416421
417422 return $ typeOverrides [$ type ] ?? $ type ;
418423 }
@@ -432,7 +437,7 @@ public function getPropertiesFromTable($model)
432437 $ databasePlatform ->registerDoctrineTypeMapping ('enum ' , 'string ' );
433438
434439 $ 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 }" , []);
436441 foreach ($ customTypes as $ yourTypeName => $ doctrineTypeName ) {
437442 try {
438443 if (!Type::hasType ($ yourTypeName )) {
@@ -1010,7 +1015,7 @@ protected function getCollectionClass($className)
10101015 */
10111016 protected function getRelationTypes (): array
10121017 {
1013- $ configuredRelations = $ this ->laravel [ ' config ' ] ->get ('ide-helper.additional_relation_types ' , []);
1018+ $ configuredRelations = $ this ->config ->get ('ide-helper.additional_relation_types ' , []);
10141019 return array_merge (self ::RELATION_TYPES , $ configuredRelations );
10151020 }
10161021
@@ -1019,7 +1024,7 @@ protected function getRelationTypes(): array
10191024 */
10201025 protected function hasCamelCaseModelProperties ()
10211026 {
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 );
10231028 }
10241029
10251030 protected function getReturnType (\ReflectionMethod $ reflection ): ?string
@@ -1237,7 +1242,7 @@ protected function getClassNameInDestinationFile(object $model, string $classNam
12371242 $ className = trim ($ className , '\\' );
12381243 $ writingToExternalFile = !$ this ->write || $ this ->write_mixin ;
12391244 $ 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 );
12411246
12421247 if (($ writingToExternalFile && $ classIsNotInExternalFile ) || $ forceFQCN ) {
12431248 return '\\' . $ className ;
@@ -1405,7 +1410,7 @@ protected function getReflectionNamedType(ReflectionNamedType $paramType): strin
14051410 */
14061411 protected function runModelHooks ($ model ): void
14071412 {
1408- $ hooks = $ this ->laravel [ ' config ' ] ->get ('ide-helper.model_hooks ' , []);
1413+ $ hooks = $ this ->config ->get ('ide-helper.model_hooks ' , []);
14091414
14101415 foreach ($ hooks as $ hook ) {
14111416 $ hookInstance = $ this ->laravel ->make ($ hook );
0 commit comments