Detect facades automaticcaly

This commit is contained in:
Barry
2013-03-20 15:17:05 +01:00
parent 2baa475be0
commit 38da3b86cd
4 changed files with 5852 additions and 5790 deletions
+5829 -5747
View File
File diff suppressed because it is too large Load Diff
+1 -3
View File
@@ -23,9 +23,7 @@ You can also publish the config-file to add extra facades (ie. for bundles).
php artisan config:publish barryvdh/laravel-ide-helper php artisan config:publish barryvdh/laravel-ide-helper
You can just add the Facade and the 'real' class, like the rest of the classes. The generator tries to identify the real class, but if it cannot be found, you can define it in the config file.
'Basset' => 'Basset\Basset',
You can choose to include helper files. This is not enabled by default, but you can override this with the --helpers (-H) or --nohelpers (-N) option. You can choose to include helper files. This is not enabled by default, but you can override this with the --helpers (-H) or --nohelpers (-N) option.
The Illuminate/Support/helpers.php is already set-up, but you can add/remove your own files in the config file. The Illuminate/Support/helpers.php is already set-up, but you can add/remove your own files in the config file.
@@ -30,7 +30,10 @@ class GeneratorCommand extends Command {
{ {
$filename = $this->argument('filename'); $filename = $this->argument('filename');
$this->setupDefaults();
$aliases = \Config::get('laravel-ide-helper::aliases'); $aliases = \Config::get('laravel-ide-helper::aliases');
$aliases += \Config::get('app.aliases');
if( $this->option('helpers') || (\Config::get('laravel-ide-helper::include_helpers') && ! $this->option('nohelpers'))){ if( $this->option('helpers') || (\Config::get('laravel-ide-helper::include_helpers') && ! $this->option('nohelpers'))){
$helpers = \Config::get('laravel-ide-helper::helper_files'); $helpers = \Config::get('laravel-ide-helper::helper_files');
@@ -50,6 +53,12 @@ class GeneratorCommand extends Command {
} }
protected function setupDefaults(){
//Create memory database driver, to avoid connection errors on Database facades
\Config::set('database.connections.sqlite.database',':memory');
\Config::set('database.default', 'sqlite');
}
/** /**
* Get the console command arguments. * Get the console command arguments.
* *
@@ -75,14 +84,20 @@ class GeneratorCommand extends Command {
); );
} }
protected function generateDocs($aliases, $helpers){ protected function generateDocs($aliases, $helpers = array()){
$d = new Parser(); $d = new Parser();
$d->setAllowInherited(true); $d->setAllowInherited(true);
$d->setMethodFilter(\ReflectionMethod::IS_PUBLIC); $d->setMethodFilter(\ReflectionMethod::IS_PUBLIC);
$output = "<?php die('Only to be used as an helper for your IDE');\n\n"; $output = "<?php die('Only to be used as an helper for your IDE');\n\n";
foreach($aliases as $alias => $className){ foreach($aliases as $alias => $facade){
if(method_exists($facade, 'getFacadeRoot')){
$root = get_class($facade::getFacadeRoot());
}else{
$root = $facade;
}
if(strpos($alias, '\\') !== false){ if(strpos($alias, '\\') !== false){
$parts = explode('\\', $alias); $parts = explode('\\', $alias);
@@ -92,10 +107,10 @@ class GeneratorCommand extends Command {
$namespace = ''; $namespace = '';
} }
$d->analyze($className); $d->analyze($root);
$output .= "namespace $namespace {\n class $alias{\r\n"; $output .= "namespace $namespace {\n class $alias{\r\n";
$output .= "\t/**\n\t * @var $className \$realClass\n\t */\n\t static private \$realClass;\n\n"; $output .= "\t/**\n\t * @var $root \$root\n\t */\n\t static private \$root;\n\n";
$methods = $d->getMethods(); $methods = $d->getMethods();
foreach ($methods as $method) foreach ($methods as $method)
@@ -172,7 +187,7 @@ class GeneratorCommand extends Command {
} }
$output .= implode($paramsWithDefault, ", "); $output .= implode($paramsWithDefault, ", ");
$output .= "){\r\n\t\t".($returnValue !== "void" ? 'return ' : '')."self::\$realClass->".$method->name."(".implode($params, ", ").");\r\n\t }\n\n"; $output .= "){\r\n\t\t".($returnValue !== "void" ? 'return ' : '')."self::\$root->".$method->name."(".implode($params, ", ").");\r\n\t }\n\n";
return $output; return $output;
} }
+2 -35
View File
@@ -31,52 +31,19 @@ return array(
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Class Aliases | Custom Facades
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| |
| This array of class aliases will be parsed and added to the helper file. | These facades cannot be found directly, because of a Manager class.
| |
*/ */
'aliases' => array( 'aliases' => array(
'App' => 'Illuminate\Foundation\Application',
'Artisan' => 'Illuminate\Foundation\Artisan',
'Auth' => 'Illuminate\Auth\Guard', 'Auth' => 'Illuminate\Auth\Guard',
'Blade' => 'Illuminate\View\Compilers\BladeCompiler',
'Cache' => 'Illuminate\Cache\Store', 'Cache' => 'Illuminate\Cache\Store',
'ClassLoader'=> 'Illuminate\Support\ClassLoader',
'Config' => 'Illuminate\Config\Repository',
'Controller'=> 'Illuminate\Routing\Controllers\Controller',
'Cookie' => 'Illuminate\Cookie\CookieJar',
'Crypt' => 'Illuminate\Encryption\Encrypter',
'DB' => 'Illuminate\Database\Connection', 'DB' => 'Illuminate\Database\Connection',
'Eloquent' => 'Illuminate\Database\Eloquent\Model',
'Event' => 'Illuminate\Events\Event',
'File' => 'Illuminate\Filesystem\Filesystem',
'Form' => 'Illuminate\Html\FormBuilder',
'Hash' => 'Illuminate\Hashing\BcryptHasher',
'Html' => 'Illuminate\Html\HtmlBuilder',
'Input' => 'Illuminate\Http\Request',
'Lang' => 'Illuminate\Translation\Translator',
'Log' => 'Illuminate\Log\Writer',
'Mail' => 'Illuminate\Mail\Mailer',
'Paginator' => 'Illuminate\Pagination\Environment',
'Password' => 'Illuminate\Auth\Reminders\PasswordBroker',
'Queue' => 'Illuminate\Queue\QueueInterface', 'Queue' => 'Illuminate\Queue\QueueInterface',
'Redirect' => 'Illuminate\Routing\Redirector',
'Redis' => 'Illuminate\Redis\Database', 'Redis' => 'Illuminate\Redis\Database',
'Request' => 'Illuminate\Http\Request',
'Response' => 'Illuminate\Http\Response',
'Route' => 'Illuminate\Routing\Router',
'Schema' => 'Illuminate\Database\Schema\Builder',
'Seeder' => 'Illuminate\Database\Seeder',
'Session' => 'Illuminate\Support\Facades\Session',
'Str' => 'Illuminate\Support\Str',
'URL' => 'Illuminate\Routing\UrlGenerator',
'Validator' => 'Illuminate\Validation\Factory',
'View' => 'Illuminate\View\Environment',
), ),
); );