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 *
@@ -119,13 +125,12 @@ class ModelsCommand extends Command
119125 */
120126 protected $ dateClass ;
121127
122- /**
123- * @param Filesystem $files
124- */
125- public function __construct (Filesystem $ files )
128+ public function __construct (Filesystem $ files , Config $ config )
126129 {
130+ $ this ->files = $ files ;
131+ $ this ->config = $ config ;
132+
127133 parent ::__construct ();
128- $ this ->files = $ files ;
129134 }
130135
131136 /**
@@ -140,7 +145,7 @@ public function handle()
140145 $ this ->write = $ this ->option ('write ' );
141146 $ this ->write_mixin = $ this ->option ('write-mixin ' );
142147 $ this ->dirs = array_merge (
143- $ this ->laravel [ ' config ' ] ->get ('ide-helper.model_locations ' , []),
148+ $ this ->config ->get ('ide-helper.model_locations ' , []),
144149 $ this ->option ('dir ' )
145150 );
146151 $ model = $ this ->argument ('model ' );
@@ -150,10 +155,10 @@ public function handle()
150155 if ($ this ->option ('smart-reset ' )) {
151156 $ this ->keep_text = $ this ->reset = true ;
152157 }
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 );
155160 $ 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 );
157162
158163 $ this ->write = $ this ->write_mixin ? true : $ this ->write ;
159164 //If filename is default and Write is not specified, ask what to do
@@ -249,7 +254,7 @@ protected function generateDocs($loadModels, $ignore = '')
249254
250255 $ ignore = array_merge (
251256 explode (', ' , $ ignore ),
252- $ this ->laravel [ ' config ' ] ->get ('ide-helper.ignored_models ' , [])
257+ $ this ->config ->get ('ide-helper.ignored_models ' , [])
253258 );
254259
255260 foreach ($ models as $ name ) {
@@ -417,7 +422,7 @@ public function castPropertiesType($model)
417422 */
418423 protected function getTypeOverride ($ type )
419424 {
420- $ typeOverrides = $ this ->laravel [ ' config ' ] ->get ('ide-helper.type_overrides ' , []);
425+ $ typeOverrides = $ this ->config ->get ('ide-helper.type_overrides ' , []);
421426
422427 return $ typeOverrides [$ type ] ?? $ type ;
423428 }
@@ -437,7 +442,7 @@ public function getPropertiesFromTable($model)
437442 $ databasePlatform ->registerDoctrineTypeMapping ('enum ' , 'string ' );
438443
439444 $ 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 }" , []);
441446 foreach ($ customTypes as $ yourTypeName => $ doctrineTypeName ) {
442447 try {
443448 if (!Type::hasType ($ yourTypeName )) {
@@ -1015,7 +1020,7 @@ protected function getCollectionClass($className)
10151020 */
10161021 protected function getRelationTypes (): array
10171022 {
1018- $ configuredRelations = $ this ->laravel [ ' config ' ] ->get ('ide-helper.additional_relation_types ' , []);
1023+ $ configuredRelations = $ this ->config ->get ('ide-helper.additional_relation_types ' , []);
10191024 return array_merge (self ::RELATION_TYPES , $ configuredRelations );
10201025 }
10211026
@@ -1024,7 +1029,7 @@ protected function getRelationTypes(): array
10241029 */
10251030 protected function hasCamelCaseModelProperties ()
10261031 {
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 );
10281033 }
10291034
10301035 protected function getReturnType (\ReflectionMethod $ reflection ): ?string
@@ -1242,7 +1247,7 @@ protected function getClassNameInDestinationFile(object $model, string $classNam
12421247 $ className = trim ($ className , '\\' );
12431248 $ writingToExternalFile = !$ this ->write || $ this ->write_mixin ;
12441249 $ 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 );
12461251
12471252 if (($ writingToExternalFile && $ classIsNotInExternalFile ) || $ forceFQCN ) {
12481253 return '\\' . $ className ;
@@ -1410,7 +1415,7 @@ protected function getReflectionNamedType(ReflectionNamedType $paramType): strin
14101415 */
14111416 protected function runModelHooks ($ model ): void
14121417 {
1413- $ hooks = $ this ->laravel [ ' config ' ] ->get ('ide-helper.model_hooks ' , []);
1418+ $ hooks = $ this ->config ->get ('ide-helper.model_hooks ' , []);
14141419
14151420 foreach ($ hooks as $ hook ) {
14161421 $ hookInstance = $ this ->laravel ->make ($ hook );
0 commit comments