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