mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-17 17:47:13 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
/vendor
|
||||
composer.lock
|
||||
.idea
|
||||
+9137
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "barryvdh/ide-helper",
|
||||
"description": "",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Barry vd. Heuvel",
|
||||
"email": "[email protected]"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.0",
|
||||
"illuminate/support": "4.0.x",
|
||||
"dannykopping/docblock": "dev-master"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Barryvdh\\IdeHelper": "src/"
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
## Laravel IDE Helper & Generator
|
||||
|
||||
### Complete phpDocs, directly from the source
|
||||
|
||||
Add the _IDE_helper.php to your laravel folder (not in a public folder). The file isn't used by Laravel, but it has to be indexed by your IDE.
|
||||
The file has been tested in PHPStorm 6.
|
||||
|
||||
### Automatic phpDoc generation for Laravel Facades
|
||||
|
||||
Require this package in your composer.json:
|
||||
|
||||
"barryvdh/laravel-ide-helper": "dev-master"
|
||||
|
||||
And add the ServiceProvider to the providers array in app/config/app.php
|
||||
|
||||
'Barryvdh\IdeHelper\IdeHelperServiceProvider',
|
||||
|
||||
You can now re-generate the docs yourself (for future updates) in arisan
|
||||
|
||||
php artisan ide-helper:generate
|
||||
|
||||
You can also publish the config-file to add extra facades (ie. for bundles).
|
||||
|
||||
php artisan config:publish barryvdh/ide-helper
|
||||
|
||||
You can just add the Facade and the 'real' class, like the rest of the classes.
|
||||
|
||||
'Eloquent' => 'Illuminate\Database\Eloquent\Model',
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php namespace Barryvdh\IdeHelper;
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use DocBlock\Parser;
|
||||
|
||||
class GeneratorCommand extends Command {
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'ide-helper:generate';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Generate a new IDE Helper file.';
|
||||
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$filename = $this->argument('filename');
|
||||
|
||||
$aliases = \Config::get('ide-helper::aliases');
|
||||
$content = $this->parseDocBlocks($aliases);
|
||||
|
||||
$written = \File::put($filename, $content);
|
||||
|
||||
if($written !== false){
|
||||
$this->info("A new helper file was written to $filename");
|
||||
}else{
|
||||
$this->error("The helper file could not be created at $filename");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return array(
|
||||
array('filename', InputArgument::OPTIONAL, 'The path to the helper file', \Config::get('ide-helper::filename')),
|
||||
);
|
||||
}
|
||||
|
||||
protected function parseDocBlocks($aliases){
|
||||
$d = new Parser();
|
||||
|
||||
$output = "<?php\r\ndie('Only to be used as an helper for your IDE');\n";
|
||||
|
||||
foreach($aliases as $alias => $className){
|
||||
|
||||
$d->analyze($className);
|
||||
$output .= "class $alias extends $className{\r\n";
|
||||
|
||||
$methods = $d->getMethods();
|
||||
|
||||
foreach ($methods as $method)
|
||||
{
|
||||
$returnAnnotations = $method->getAnnotations(array("return"));
|
||||
if(!empty($returnAnnotations)){
|
||||
foreach ($returnAnnotations as $annotation)
|
||||
{
|
||||
$returnValue = $annotation->values[0];
|
||||
}
|
||||
}else{
|
||||
$returnValue = 'void';
|
||||
}
|
||||
|
||||
$annotations = $method->getAnnotations(array("param"));
|
||||
|
||||
$output .= "/**\n * ".trim($method->description)."\n *\n * @static\n";
|
||||
$params = array();
|
||||
if(!empty($annotations)){
|
||||
foreach ($annotations as $annotation)
|
||||
{
|
||||
$output .=" * @param\t".implode($annotation->values, "\t")."\n";
|
||||
}
|
||||
}
|
||||
|
||||
$output .= " * @return ".$returnValue."\n */\n public static function ".$method->name."(";
|
||||
|
||||
$reflection = $method->getReflectionObject();
|
||||
foreach ($reflection->getParameters() as $param) {
|
||||
$paramStr = '$'.$param->getName();
|
||||
if ($param->isOptional()) {
|
||||
$default = $param->getDefaultValue();
|
||||
if(is_bool($default)){
|
||||
$default = $default? 'true':'false';
|
||||
}elseif(is_array($default)){
|
||||
$default = 'array()';
|
||||
}elseif(is_null($default)){
|
||||
$default = 'null';
|
||||
}else{
|
||||
$default = "'".trim($default)."'";
|
||||
}
|
||||
|
||||
$paramStr .= " = $default";
|
||||
}
|
||||
$params[] = $paramStr;
|
||||
}
|
||||
$output .= implode($params, ", ");
|
||||
|
||||
|
||||
$output .= "){}\n\n";
|
||||
|
||||
|
||||
}
|
||||
$output .= "}\n\n";
|
||||
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php namespace Barryvdh\IdeHelper;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class IdeHelperServiceProvider extends ServiceProvider {
|
||||
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
|
||||
/**
|
||||
* Bootstrap the application events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->package('barryvdh/ide-helper');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
|
||||
$this->app['command.ide-helper.generate'] = $this->app->share(function($app)
|
||||
{
|
||||
return new GeneratorCommand;
|
||||
});
|
||||
$this->commands('command.ide-helper.generate');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return array('command.ide-helper.generate');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Filename
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The default path to the helper file
|
||||
|
|
||||
*/
|
||||
|
||||
'filename' => '_IDE_helper.php',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Class Aliases
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This array of class aliases will be parsed and added to the helper file.
|
||||
|
|
||||
*/
|
||||
|
||||
'aliases' => array(
|
||||
|
||||
'App' => 'Illuminate\Foundation\Application',
|
||||
'Artisan' => 'Illuminate\Foundation\Artisan',
|
||||
'Auth' => 'Illuminate\Auth\Guard',
|
||||
'Blade' => 'Illuminate\View\Compilers\BladeCompiler',
|
||||
'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',
|
||||
'Eloquent' => 'Illuminate\Database\Eloquent\Model',
|
||||
'Event' => 'Illuminate\Events\Event',
|
||||
'File' => 'Illuminate\Filesystem\Filesystem',
|
||||
'Form' => 'Illuminate\Support\Facades\Form',
|
||||
'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\Paginator',
|
||||
'Password' => 'Illuminate\Auth\Reminders\PasswordBroker',
|
||||
'Queue' => 'Illuminate\Queue\QueueManager',
|
||||
'Redirect' => 'Illuminate\Routing\Redirector',
|
||||
'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',
|
||||
|
||||
),
|
||||
|
||||
);
|
||||
Reference in New Issue
Block a user