Merge pull request #377 from ellisio/type-overrides

Allow Type Overrides
This commit is contained in:
Barry vd. Heuvel
2016-08-24 22:41:37 +02:00
committed by GitHub
3 changed files with 32 additions and 9 deletions
+15 -3
View File
@@ -1,4 +1,4 @@
<?php
<?php
return array(
@@ -71,7 +71,7 @@ return array(
'emergency' => '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,16 @@ 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',
),
);
+14 -2
View File
@@ -212,7 +212,6 @@ class ModelsCommand extends Command
}
return $output;
}
@@ -279,11 +278,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.
*
+3 -4
View File
@@ -118,7 +118,7 @@ class Generator
{
$defaultUserModel = config('auth.providers.users.model', config('auth.model', 'App\User'));
$this->interfaces['\Illuminate\Contracts\Auth\Authenticatable'] = $defaultUserModel;
try {
if (class_exists('Auth') && is_a('Auth', '\Illuminate\Support\Facades\Auth', true)) {
if (class_exists('\Illuminate\Foundation\Application')) {
@@ -182,7 +182,6 @@ class Generator
}
} catch (\Exception $e) {
}
}
/**
@@ -200,7 +199,7 @@ class Generator
if ($facade == 'Illuminate\Support\Facades\Redis' && !class_exists('Predis\Client')) {
continue;
}
$magicMethods = array_key_exists($name, $this->magic) ? $this->magic[$name] : array();
$alias = new Alias($name, $facade, $magicMethods, $this->interfaces);
if ($alias->isValid()) {
@@ -246,7 +245,7 @@ class Generator
'Storage' => 'Illuminate\Support\Facades\Storage',
//'Validator' => 'Illuminate\Support\Facades\Validator',
];
$facades = array_merge($facades, $this->config->get('app.aliases', []));
// Only return the ones that actually exist