From f8c6ec95f6fad2f406ec70d6748945dd6de0f218 Mon Sep 17 00:00:00 2001 From: Andrew Ellis Date: Fri, 19 Aug 2016 12:20:34 -0600 Subject: [PATCH] allow a user to define the type overrides --- config/ide-helper.php | 19 ++++++++++++++++--- src/Console/ModelsCommand.php | 15 ++++++++++++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/config/ide-helper.php b/config/ide-helper.php index e575923..5c567da 100644 --- a/config/ide-helper.php +++ b/config/ide-helper.php @@ -1,4 +1,4 @@ - 'Monolog\Logger::addEmergency', ) ), - + /* |-------------------------------------------------------------------------- | Interface implementations @@ -81,7 +81,7 @@ return array( | are detected by the helpers, others can be listed below. | */ - + 'interfaces' => array( ), @@ -142,4 +142,17 @@ return array( */ 'model_camel_case_properties' => false, + /* + |-------------------------------------------------------------------------- + | Property Casts + |-------------------------------------------------------------------------- + | + | Cast the given "real type" to the given "type". + | + */ + 'type_overrides' => array( + // 'integer' => 'int', + // 'boolean' => 'bool', + ) + ); diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index d1324fc..6b47d5b 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -279,11 +279,24 @@ class ModelsCommand extends Command if (!isset($this->properties[$name])) { continue; } else { - $this->properties[$name]['type'] = $realType; + $this->properties[$name]['type'] = $this->getTypeOverride($realType); } } } + /** + * Returns the overide type for the give type. + * + * @param string $type + * @return string + */ + protected function getTypeOverride($type) + { + $typeOverrides = $this->laravel['config']->get('ide-helper.type_overrides', array()); + + return isset($typeOverrides[$type]) ? $typeOverrides[$type] : $type; + } + /** * Load the properties from the database table. *