Initial commit

This commit is contained in:
Barry vd. Heuvel
2013-03-10 01:07:57 +01:00
commit 6dea46ff3e
8 changed files with 9435 additions and 0 deletions
+128
View File
@@ -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');
}
}
View File
+66
View File
@@ -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',
),
);