This commit is contained in:
Barry vd. Heuvel
2014-08-06 19:27:22 +02:00
parent 70ab315092
commit e9bc9347cc
6 changed files with 74 additions and 38 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
{
"name": "barryvdh/laravel-ide-helper",
"description": "Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.",
"keywords": ["laravel", "autocomplete", "phpstorm", "netbeans", "sublime", "codeintel", "phpdoc"],
"keywords": ["laravel", "autocomplete", "ide", "helper", "phpstorm", "netbeans", "sublime", "codeintel", "phpdoc"],
"license": "MIT",
"authors": [
{
@@ -30,7 +30,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.10-dev"
"dev-master": "1.11-dev"
}
}
}
+21 -11
View File
@@ -3,7 +3,7 @@
* Laravel IDE Helper Generator
*
* @author Barry vd. Heuvel <[email protected]>
* @copyright 2013 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl)
* @copyright 2014 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/barryvdh/laravel-ide-helper
*/
@@ -26,6 +26,12 @@ class Alias
protected $magicMethods = array();
protected $interfaces = array();
/**
* @param string $alias
* @param string $facade
* @param array $magicMethods
* @param array $interfaces
*/
public function __construct($alias, $facade, $magicMethods = array(), $interfaces = array())
{
$this->alias = $alias;
@@ -67,7 +73,6 @@ class Alias
echo "Class not exists: $class\r\n";
}
}
}
/**
@@ -129,7 +134,6 @@ class Alias
$this->addMagicMethods();
$this->detectMethods();
return $this->methods;
}
/**
@@ -191,11 +195,9 @@ class Alias
$this->error(
"PDOException: " . $e->getMessage() . "\nPlease configure your database connection correctly, or use the sqlite memory driver (-M). Skipping $facade."
);
} catch (\Exception $e) {
$this->error("Exception: " . $e->getMessage() . "\nSkipping $facade.");
}
}
/**
@@ -212,8 +214,11 @@ class Alias
return false;
}
protected function addMagicMethods(){
/**
* Add magic methods, as defined in the configuration files
*/
protected function addMagicMethods()
{
foreach($this->magicMethods as $magic => $real){
list($className, $name) = explode('::', $real);
if(!class_exists($className) && !interface_exists($className)){
@@ -230,6 +235,7 @@ class Alias
}
}
}
/**
* Get the methods for one or multiple classes.
*
@@ -257,10 +263,14 @@ class Alias
}
}
// Helper class to log errors
protected function error($msg)
/**
* Output an error.
*
* @param string $string
* @return void
*/
protected function error($string)
{
echo $msg . "\r\n";
echo $string . "\r\n";
}
}
+5 -11
View File
@@ -3,7 +3,7 @@
* Laravel IDE Helper Generator
*
* @author Barry vd. Heuvel <[email protected]>
* @copyright 2013 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl)
* @copyright 2014 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/barryvdh/laravel-ide-helper
*/
@@ -16,11 +16,7 @@ use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Illuminate\Foundation\AliasLoader;
use phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlock\Context;
use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock\Serializer as DocBlockSerializer;
/**
* A command to generate autocomplete information for your IDE
@@ -103,11 +99,9 @@ class GeneratorCommand extends Command
$helpers = '';
}
$generator = new Generator($this->config, $this->view, $helpers);
$output = $generator->generate();
$written = $this->files->put($filename, $output);
$generator = new Generator($this->config, $this->view, $this->getOutput(), $helpers);
$content = $generator->generate();
$written = $this->files->put($filename, $content);
if ($written !== false) {
$this->info("A new helper file was written to $filename");
+21 -3
View File
@@ -3,7 +3,7 @@
* Laravel IDE Helper Generator
*
* @author Barry vd. Heuvel <[email protected]>
* @copyright 2013 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl)
* @copyright 2014 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/barryvdh/laravel-ide-helper
*/
@@ -12,6 +12,7 @@ namespace Barryvdh\LaravelIdeHelper;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Config\Repository as ConfigRepository;
use Symfony\Component\Console\Output\OutputInterface;
class Generator
{
@@ -21,6 +22,9 @@ class Generator
/** @var \Illuminate\View\Factory */
protected $view;
/** @var \Symfony\Component\Console\Output\OutputInterface */
protected $output;
protected $extra = array();
protected $magic = array();
protected $interfaces = array();
@@ -29,10 +33,12 @@ class Generator
/**
* @param \Illuminate\Config\Repository $config
* @param \Illuminate\View\Factory $view
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @param string $helpers
*/
public function __construct(ConfigRepository $config,
/* Illuminate\View\Factory */ $view,
OutputInterface $output = null,
$helpers = ''
) {
$this->config = $config;
@@ -58,7 +64,6 @@ class Generator
->with('namespaces', $this->getNamespaces())
->with('helpers', $this->helpers)
->render();
}
protected function detectDrivers()
@@ -123,7 +128,6 @@ class Generator
foreach (AliasLoader::getInstance()->getAliases() as $name => $facade) {
$magicMethods = array_key_exists($name, $this->magic) ? $this->magic[$name] : array();
$alias = new Alias($name, $facade, $magicMethods, $this->interfaces);
if ($alias->isValid()) {
//Add extra methods, from other classes (magic static calls)
@@ -173,4 +177,18 @@ class Generator
}
}
/**
* Write a string as error output.
*
* @param string $string
* @return void
*/
protected function error($string)
{
if($this->output){
$this->output->writeln("<error>$string</error>");
}else{
echo $string . "\r\n";
}
}
}
+1 -3
View File
@@ -3,7 +3,7 @@
* Laravel IDE Helper Generator
*
* @author Barry vd. Heuvel <[email protected]>
* @copyright 2013 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl)
* @copyright 2014 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/barryvdh/laravel-ide-helper
*/
@@ -42,14 +42,12 @@ class IdeHelperServiceProvider extends ServiceProvider
*/
public function register()
{
$this->app['command.ide-helper.generate'] = $this->app->share(
function ($app) {
return new GeneratorCommand($app['config'], $app['files'], $app['view']);
}
);
$this->app['command.ide-helper.models'] = $this->app->share(
function () {
return new ModelsCommand();
+24 -8
View File
@@ -3,7 +3,7 @@
* Laravel IDE Helper Generator
*
* @author Barry vd. Heuvel <[email protected]>
* @copyright 2013 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl)
* @copyright 2014 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/barryvdh/laravel-ide-helper
*/
@@ -17,16 +17,24 @@ use phpDocumentor\Reflection\DocBlock\Serializer as DocBlockSerializer;
class Method
{
/** @var \phpDocumentor\Reflection\DocBlock */
protected $phpdoc;
protected $output = '';
protected $name;
protected $namespace;
protected $phpdoc;
protected $params = array();
protected $params_with_default = array();
protected $interfaces = array();
public function __construct($method, $alias, $class, $methodName = null, $interfaces = array())
/**
* @param \ReflectionMethod $method
* @param string $alias
* @param string $class
* @param string|null $methodName
* @param array $interfaces
*/
public function __construct(\ReflectionMethod $method, $alias, $class, $methodName = null, $interfaces = array())
{
$this->interfaces = $interfaces;
$this->name = $methodName ?: $method->name;
@@ -39,7 +47,7 @@ class Method
try {
$this->normalizeDescription($method);
} catch (\Exception $e) {
$this->info("Cannot normalize method $alias::{$this->name}..");
$this->error("Cannot normalize method $alias::{$this->name}..");
}
//Get the parameters, including formatted default values
@@ -57,8 +65,6 @@ class Method
$declaringClass = $method->getDeclaringClass();
$this->declaringClassName = '\\' . ltrim($declaringClass->name, '\\');
$this->root = '\\' . ltrim($class->getName(), '\\');
}
/**
@@ -121,7 +127,7 @@ class Method
*/
public function getParams($implode = true)
{
return implode(', ', $this->params);
return $implode ? implode(', ', $this->params) : $this->params;
}
/**
@@ -132,7 +138,7 @@ class Method
*/
public function getParamsWithDefault($implode = true)
{
return implode(', ', $this->params_with_default);
return $implode ? implode(', ', $this->params_with_default) : $this->params_with_default;
}
/**
@@ -250,4 +256,14 @@ class Method
}
}
/**
* Output an error.
*
* @param string $string
* @return void
*/
protected function error($string)
{
echo $string . "\r\n";
}
}