From ec18f19777afb709d79288cb448be935bc2e43ec Mon Sep 17 00:00:00 2001 From: Barry Date: Mon, 1 Apr 2013 19:03:57 +0200 Subject: [PATCH] Replace facades instead of aliases More logical, because aliases are auto-detected. This way, the original facade is also kept. --- readme.md | 2 +- .../LaravelIdeHelper/GeneratorCommand.php | 13 +++++++++---- src/config/config.php | 16 ++++++++-------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/readme.md b/readme.md index 000ef23..03348c2 100644 --- a/readme.md +++ b/readme.md @@ -25,7 +25,7 @@ If you use SublimeText CodeIntel, the format is a bit different. So add --sublim php artisan ide-helper:generate -S -You can also publish the config-file to add extra facades (ie. for bundles) or set defaults for --helpers or --sublime. +You can also publish the config-file to change implementations (ie. interface to specific class) or set defaults for --helpers or --sublime. php artisan config:publish barryvdh/laravel-ide-helper diff --git a/src/Barryvdh/LaravelIdeHelper/GeneratorCommand.php b/src/Barryvdh/LaravelIdeHelper/GeneratorCommand.php index 609dfec..eafd546 100644 --- a/src/Barryvdh/LaravelIdeHelper/GeneratorCommand.php +++ b/src/Barryvdh/LaravelIdeHelper/GeneratorCommand.php @@ -34,8 +34,8 @@ class GeneratorCommand extends Command { $this->useMemoryDriver(); } - $aliases = \Config::get('laravel-ide-helper::aliases'); - $aliases += \Config::get('app.aliases'); + $replace = \Config::get('laravel-ide-helper::replace'); + $aliases = \Config::get('app.aliases'); if( $this->option('helpers') || (\Config::get('laravel-ide-helper::include_helpers') && ! $this->option('nohelpers'))){ $helpers = \Config::get('laravel-ide-helper::helper_files'); @@ -45,7 +45,7 @@ class GeneratorCommand extends Command { $sublime = $this->option('sublime') || \Config::get('laravel-ide-helper::sublime'); - $content = $this->generateDocs($aliases, $helpers, $sublime); + $content = $this->generateDocs($aliases, $replace, $helpers, $sublime); $written = \File::put($filename, $content); @@ -92,7 +92,7 @@ class GeneratorCommand extends Command { ); } - protected function generateDocs($aliases, $helpers = array(), $sublime = false){ + protected function generateDocs($aliases, $replace, $helpers = array(), $sublime = false){ $d = new Parser(); $d->setAllowInherited(true); $d->setMethodFilter(\ReflectionMethod::IS_PUBLIC); @@ -107,6 +107,11 @@ class GeneratorCommand extends Command { }else{ $root = $facade; } + + if(in_array($root, $replace)){ + $root = $replace[$root]; + } + if(!class_exists($root) && !interface_exists($root)){ $this->error("Class $root is not found."); continue; diff --git a/src/config/config.php b/src/config/config.php index ae7f582..7629899 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -43,19 +43,19 @@ return array( /* |-------------------------------------------------------------------------- - | Custom Facades + | Replaced classes (Managers) |-------------------------------------------------------------------------- | - | These facades cannot be found directly, because of a Manager class. + | These implementations cannot be found directly, because of a Manager class. | */ - 'aliases' => array( - 'Auth' => 'Illuminate\Auth\Guard', - 'Cache' => 'Illuminate\Cache\StoreInterface', - 'DB' => 'Illuminate\Database\Connection', - 'Queue' => 'Illuminate\Queue\QueueInterface', - 'Redis' => 'Illuminate\Redis\Database', + 'replace' => array( + 'Illuminate\Auth\AuthManager' => 'Illuminate\Auth\Guard', + 'Illuminate\Cache\CacheManager' => 'Illuminate\Cache\StoreInterface', + 'Illuminate\Database\DatabaseManager' => 'Illuminate\Database\Connection', + 'Illuminate\Queue\QueueManager' => 'Illuminate\Queue\QueueInterface', + 'Illuminate\Redis\RedisManager' => 'Illuminate\Redis\Database', ), );