Compare commits

..
47 Commits
Author SHA1 Message Date
Barry vd. Heuvel 3f9831c5cf Check for correct facades 2015-02-04 09:14:36 +01:00
Barry vd. Heuvel 2cc277440a Remove tree 2015-02-03 21:03:00 +01:00
Barry vd. Heuvel 14eab5ef84 Point to 2.0 branch 2015-01-28 09:36:05 +01:00
Barry vd. Heuvel c94012232f Merge pull request #153 from koenhendriks/patch-1
JSON standard does not allow trailing comma
2015-01-22 14:33:30 +01:00
Koen Hendriks b9685a1f83 JSON standard does not allow trailing comma
Gives errors for people just copy-pasting ;)
2015-01-22 14:26:26 +01:00
Barry vd. Heuvel 7bc74b1844 CS tweaks 2015-01-21 11:22:44 +01:00
Barry vd. Heuvel cfa0333446 Tweak quotes for doctrine warning 2015-01-21 11:10:03 +01:00
Barry vd. Heuvel 5c6fa1d43f Merge pull request #148 from BaldaI/fix-relations
Fixed class name resolution via get_class() and static::class.
2015-01-21 11:05:40 +01:00
Barry vd. Heuvel 23db0e06ca Merge pull request #150 from qufo/patch-1
Update ModelsCommand.php , Add COMMENT info.
2015-01-21 11:03:33 +01:00
Barry vd. Heuvel 52b3accd70 Use laravel instance instead of App facade
Addition to #138
2015-01-21 11:01:29 +01:00
Barry vd. Heuvel cc07cd3b2c Merge pull request #138 from SebSept/patch-1
Model doc : create model using App::make($name)
2015-01-21 11:00:26 +01:00
qufo 3113f58f45 Update ModelsCommand.php , Add COMMENT info.
When define a class(table) , we will add some comment information to the property (field), the comment information was useful for coder who has  bad memory.so ,I think we'd better show the comment at the end of  * @property  line.
I'm a Chinese, most of my team was Chinese too,   the comment information was written by Chinese, so , it's helpful!

-------------------------
当我们定义一个类(表)的时候,我们会给对象(字段)加上一些注释信息,这些注释信息对记忆力不好的程序员很有用,所以我认为我们可以在属性行的尾部加入注释信息
我是个中国人,我团队中的大部分人也是中国人,这些注释信息是中文写的,对他们很有帮助。
2015-01-08 17:28:00 +08:00
BaldaI d00dc62ed6 Fixed class name resolution via get_class() and static::class. 2015-01-01 13:58:32 +10:00
Barry vd. Heuvel 073d90b791 Merge pull request #144 from szainmehdi/master
Fixed class name resolution via ::class (#143,#129)
2014-12-20 15:18:35 +01:00
S. Zain Mehdi 5d4af73c29 Fixed class name resolution via ::class (#143,#129) 2014-12-19 11:26:42 -08:00
Barry vd. Heuvel 39ffaa62f4 Merge pull request #142 from RowdyElectron/master
Fix typo in ModelsCommand.php . Fixes #141
2014-12-17 16:30:50 +01:00
Philip Keighley 231e125821 Fix typo in ModelsCommand.php . Fixes #141 2014-12-17 10:28:07 -05:00
Barry vd. Heuvel f446326967 Add fallback package method
For L5
2014-12-16 14:10:07 +01:00
Sébastien Monterisi 57dc033061 Model doc : create model using App::make($name)
trying to generate doc for a model with dependencies in constructor will fail with `new $name` .
Now it works using App:make($name).
Laravel IOC resolves the dependencies.
2014-12-06 23:04:58 +01:00
Barry vd. Heuvel e2b59c6cb5 Use config the get User model
See #136
2014-11-29 13:11:10 +01:00
Barry vd. Heuvel 736f2f387e Remove verbose comments
Just show when it's actually a Model, not every class (for L5
especially). See #135
2014-11-29 12:53:37 +01:00
Barry vd. Heuvel 486d9d9c4d Simplify installation
http://blog.doh.ms/2014/10/13/installing-composer-packages/
2014-10-14 10:39:02 +02:00
Barry vd. Heuvel ac8b868261 Merge pull request #121 from MartinWachocki/patch-1
Fix for functions with variadic arguments
2014-10-08 16:11:38 +02:00
Martin Wachocki c0eb7e2d7e Fix for functions with variadic arguments
The `php artisan ide-helper:generate` command fails with the following error for functions with variadic arguments:

    [ReflectionException]                                 
    Internal error: Failed to retrieve the default value
2014-10-08 10:06:59 -04:00
Barry vd. Heuvel 89a17fc7b9 Merge pull request #118 from rdpascua/dev
fix typo
2014-09-28 10:19:31 -04:00
Ricardo Pascua Jr ec43d4e65b fix typo 2014-09-28 21:37:55 +08:00
Barry vd. Heuvel 03cc70759b Update composer.json 2014-09-15 17:20:52 +02:00
Barry vd. Heuvel f94743fda5 Merge pull request #111 from JonTheNiceGuy/patch-1
Valid JSON :)
2014-09-10 09:43:00 +02:00
Jon "The Nice Guy" Spriggs 3eabba3e5d Valid JSON :)
This reduces the number of errors my IDE shouts at me for :)
2014-09-03 20:03:52 +01:00
Barry vd. Heuvel f2de8d3c65 Merge pull request #110 from enigmatic-user/master
Removed space after "@method static ..."
2014-09-03 08:57:31 +02:00
Jan-Christoph Ihrens 10e16a0bdc Removed space after "@method static ..."
According to PSR-2, "there MUST NOT be trailing whitespace at the end of non-blank lines" (http://www.php-fig.org/psr/psr-2/). My IDE is checking for this, and I always have to remove the spaces manually...  ;-)
2014-09-03 08:51:03 +02:00
Barry vd. Heuvel f135845100 Revert adding costructor back
Doesn't make sense, isn't called static.
2014-08-26 13:01:45 +02:00
Barry vd. Heuvel 3c54b17760 Add __construct back
See #105
2014-08-26 11:53:54 +02:00
Barry vd. Heuvel 9a67d9132f Skip decrement/increment
They are a bit weird.
2014-08-26 10:54:34 +02:00
Barry vd. Heuvel bd33e05304 Don't add magic methods
Fixes #105
2014-08-26 10:53:32 +02:00
Barry vd. Heuvel 83bdb7acd7 Use shortname instead of alias
Fixes #106
2014-08-26 10:49:07 +02:00
Barry vd. Heuvel 4fc9c671e8 Add getShortName
For #106
2014-08-26 10:48:29 +02:00
Barry vd. Heuvel 6c18c3f39a Add json format 2014-08-19 09:49:07 +02:00
Barry vd. Heuvel 19aa77ac49 Indent with 8 spaces instead of 2 tabs
Similar to the rest.
2014-08-12 14:34:30 +02:00
Barry vd. Heuvel 25ec6bd1ea Remove message. 2014-08-12 09:14:43 +02:00
Barry vd. Heuvel 1b608fc446 Get correct namespace
The other one was empty, now it should be correct. Fixes #97
2014-08-11 13:26:11 +02:00
Barry vd. Heuvel 09055582af Add correct context for inheritdoc
Attempt 2 to fix #97
2014-08-11 13:05:28 +02:00
Barry vd. Heuvel 4cfcabb63d Normalize return/params from inheritdocs before appending
This normalizes return/param tags, before the tags are added to the docblock. This will preserve the correct context (and namespace).
Should fix #93
2014-08-11 12:07:00 +02:00
Barry vd. Heuvel cbfd53e0f9 Merge pull request #99 from alxy/patch-1
Fix a copy paste error (probably)
2014-08-11 11:01:57 +02:00
Barry vd. Heuvel fd11d89fa7 Clarify trait/interface message in model generator
Makes it clear why a trait/interface is skipped.
Fixes #98
2014-08-11 11:01:19 +02:00
alxy 7f335274bf Fix a copy paste error (probably)
I don't use this helper, however, I guess that line wasnt correct.
2014-08-11 10:30:52 +02:00
Barry vd. Heuvel c01769aebd Add note to config for interfaces 2014-08-10 10:02:50 +02:00
10 changed files with 206 additions and 67 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
{ {
"providers": [ "providers": [
"Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider" "Barryvdh\\LaravelIdeHelper\\IdeHelperServiceProvider"
] ]
} }
+5 -3
View File
@@ -1,6 +1,8 @@
## Laravel IDE Helper Generator ## Laravel IDE Helper Generator
[![Latest Stable Version](https://poser.pugx.org/barryvdh/laravel-ide-helper/version.png)](https://packagist.org/packages/barryvdh/laravel-ide-helper) [![Total Downloads](https://poser.pugx.org/barryvdh/laravel-ide-helper/d/total.png)](https://packagist.org/packages/barryvdh/laravel-ide-helper) [![Latest Stable Version](https://poser.pugx.org/barryvdh/laravel-ide-helper/version.png)](https://packagist.org/packages/barryvdh/laravel-ide-helper) [![Total Downloads](https://poser.pugx.org/barryvdh/laravel-ide-helper/d/total.png)](https://packagist.org/packages/barryvdh/laravel-ide-helper)
### For Laravel 5, check the [2.0 branch](https://github.com/barryvdh/laravel-ide-helper)
### Complete phpDocs, directly from the source ### Complete phpDocs, directly from the source
_Checkout [this Laracasts video](https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/15) for a quick introduction/explanation!_ _Checkout [this Laracasts video](https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/15) for a quick introduction/explanation!_
@@ -14,9 +16,9 @@ Note: You do need CodeIntel for Sublime Text: https://github.com/SublimeCodeInte
### Automatic phpDoc generation for Laravel Facades ### Automatic phpDoc generation for Laravel Facades
Require this package in your composer.json and run composer update (or run `composer require barryvdh/laravel-ide-helper:1.*` directly): Require this package with composer using the following command:
"barryvdh/laravel-ide-helper": "1.*" composer require barryvdh/laravel-ide-helper
After updating composer, add the ServiceProvider to the providers array in app/config/app.php After updating composer, add the ServiceProvider to the providers array in app/config/app.php
@@ -34,7 +36,7 @@ You can configure your composer.json to do this after each commit:
"post-update-cmd":[ "post-update-cmd":[
"php artisan clear-compiled", "php artisan clear-compiled",
"php artisan ide-helper:generate", "php artisan ide-helper:generate",
"php artisan optimize", "php artisan optimize"
] ]
}, },
+13 -5
View File
@@ -12,11 +12,11 @@ namespace Barryvdh\LaravelIdeHelper;
class Alias class Alias
{ {
protected $alias; protected $alias;
protected $facade; protected $facade;
protected $extends = null; protected $extends = null;
protected $classType = 'class'; protected $classType = 'class';
protected $short;
protected $namespace = '__root'; protected $namespace = '__root';
protected $root = null; protected $root = null;
protected $classes = array(); protected $classes = array();
@@ -42,7 +42,6 @@ class Alias
$facade = '\\' . ltrim($facade, '\\'); $facade = '\\' . ltrim($facade, '\\');
$this->facade = $facade; $this->facade = $facade;
$this->detectRoot(); $this->detectRoot();
if ((!$this->isTrait() && $this->root)) { if ((!$this->isTrait() && $this->root)) {
@@ -55,7 +54,9 @@ class Alias
$this->detectNamespace(); $this->detectNamespace();
$this->detectClassType(); $this->detectClassType();
if($facade === '\Illuminate\Database\Eloquent\Model'){
$this->usedMethods = array('decrement', 'increment');
}
} }
/** /**
@@ -114,6 +115,12 @@ class Alias
return $this->alias; return $this->alias;
} }
/**
* Return the short name (without namespace)
*/
public function getShortName(){
return $this->short;
}
/** /**
* Get the namespace from the alias * Get the namespace from the alias
* *
@@ -145,6 +152,8 @@ class Alias
$nsParts = explode('\\', $this->alias); $nsParts = explode('\\', $this->alias);
$this->short = array_pop($nsParts); $this->short = array_pop($nsParts);
$this->namespace = implode('\\', $nsParts); $this->namespace = implode('\\', $nsParts);
}else{
$this->short = $this->alias;
} }
} }
@@ -184,7 +193,6 @@ class Alias
//If it doesn't exist, skip it //If it doesn't exist, skip it
if (!class_exists($root) && !interface_exists($root)) { if (!class_exists($root) && !interface_exists($root)) {
$this->error("Class $root is not found.");
return; return;
} }
@@ -253,7 +261,7 @@ class Alias
if (!in_array($method->name, $this->usedMethods)) { if (!in_array($method->name, $this->usedMethods)) {
// Only add the methods to the output when the root is not the same as the class. // Only add the methods to the output when the root is not the same as the class.
// And don't add the __*() methods // And don't add the __*() methods
if ($this->extends !== $class && $method->name !== '__clone') { if ($this->extends !== $class && substr($method->name, 0, 2) !== '__') {
$this->methods[] = new Method($method, $this->alias, $reflection, $method->name, $this->interfaces); $this->methods[] = new Method($method, $this->alias, $reflection, $method->name, $this->interfaces);
} }
$this->usedMethods[] = $method->name; $this->usedMethods[] = $method->name;
+15 -5
View File
@@ -82,6 +82,14 @@ class GeneratorCommand extends Command
); );
} else { } else {
$filename = $this->argument('filename'); $filename = $this->argument('filename');
$format = $this->option('format');
// Strip the php extension
if (substr($filename, -4, 4) == '.php') {
$filename = substr($filename, 0, -4);
}
$filename .= '.' . $format;
if ($this->option('memory')) { if ($this->option('memory')) {
$this->useMemoryDriver(); $this->useMemoryDriver();
@@ -100,7 +108,7 @@ class GeneratorCommand extends Command
} }
$generator = new Generator($this->config, $this->view, $this->getOutput(), $helpers); $generator = new Generator($this->config, $this->view, $this->getOutput(), $helpers);
$content = $generator->generate(); $content = $generator->generate($format);
$written = $this->files->put($filename, $content); $written = $this->files->put($filename, $content);
if ($written !== false) { if ($written !== false) {
@@ -131,12 +139,11 @@ class GeneratorCommand extends Command
*/ */
protected function getArguments() protected function getArguments()
{ {
$filename = $this->config->get('laravel-ide-helper::filename');
return array( return array(
array( array(
'filename', 'filename', InputArgument::OPTIONAL, 'The path to the helper file', $filename
InputArgument::OPTIONAL,
'The path to the helper file',
$this->config->get('laravel-ide-helper::filename')
), ),
); );
} }
@@ -148,7 +155,10 @@ class GeneratorCommand extends Command
*/ */
protected function getOptions() protected function getOptions()
{ {
$format = $this->config->get('laravel-ide-helper::format');
return array( return array(
array('format', "F", InputOption::VALUE_OPTIONAL, 'The format for the IDE Helper', $format),
array('helpers', "H", InputOption::VALUE_NONE, 'Include the helper files'), array('helpers', "H", InputOption::VALUE_NONE, 'Include the helper files'),
array('memory', "M", InputOption::VALUE_NONE, 'Use sqlite memory driver'), array('memory', "M", InputOption::VALUE_NONE, 'Use sqlite memory driver'),
array('sublime', "S", InputOption::VALUE_NONE, 'DEPRECATED: Use different style for SublimeText CodeIntel'), array('sublime', "S", InputOption::VALUE_NONE, 'DEPRECATED: Use different style for SublimeText CodeIntel'),
+41 -17
View File
@@ -150,8 +150,6 @@ class ModelsCommand extends Command
if (in_array($name, $ignore)) { if (in_array($name, $ignore)) {
$this->comment("Ignoring model '$name'"); $this->comment("Ignoring model '$name'");
continue; continue;
} else {
$this->comment("Loading model '$name'");
} }
$this->properties = array(); $this->properties = array();
$this->methods = array(); $this->methods = array();
@@ -159,31 +157,35 @@ class ModelsCommand extends Command
try { try {
// handle abstract classes, interfaces, ... // handle abstract classes, interfaces, ...
$reflectionClass = new \ReflectionClass($name); $reflectionClass = new \ReflectionClass($name);
if (!$reflectionClass->IsInstantiable()) {
throw new \Exception($name . ' is not instanciable.'); if (!$reflectionClass->isSubclassOf('Illuminate\Database\Eloquent\Model')) {
} elseif (!$reflectionClass->isSubclassOf('Illuminate\Database\Eloquent\Model')) {
$this->comment("Class '$name' is not a model");
continue; continue;
} }
$model = new $name(); $this->comment("Loading model '$name'");
if (!$reflectionClass->IsInstantiable()) {
throw new \Exception($name . ' is not instantiable.');
}
$model = $this->laravel->make($name);
if ($hasDoctrine) { if ($hasDoctrine) {
$this->getPropertiesFromTable($model); $this->getPropertiesFromTable($model);
} }
$this->getPropertiesFromMethods($model); $this->getPropertiesFromMethods($model);
$output .= $this->createPhpDocs($name); $output .= $this->createPhpDocs($name);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->error("Exception: " . $e->getMessage() . "\nCould not analyze class $name."); $this->error("Exception: " . $e->getMessage() . "\nCould not analyze class $name.");
} }
} else {
$this->error("Class $name does not exist");
} }
} }
if (!$hasDoctrine) { if (!$hasDoctrine) {
$this->error( $this->error(
"Warning: 'doctrine/dbal: ~2.3' is required to load database information. Please require that in your composer.json and run 'composer update'." 'Warning: `"doctrine/dbal": "~2.3"` is required to load database information. Please require that in your composer.json and run `composer update`.'
); );
} }
@@ -254,8 +256,8 @@ class ModelsCommand extends Command
} }
} }
$comment = $column->getComment();
$this->setProperty($name, $type, true, true); $this->setProperty($name, $type, true, true, $comment);
$this->setMethod( $this->setMethod(
Str::camel("where_" . $name), Str::camel("where_" . $name),
'\Illuminate\Database\Query\Builder|\\' . get_class($model), '\Illuminate\Database\Query\Builder|\\' . get_class($model),
@@ -331,9 +333,9 @@ class ModelsCommand extends Command
$search = '$this->' . $relation . '('; $search = '$this->' . $relation . '(';
if ($pos = stripos($code, $search)) { if ($pos = stripos($code, $search)) {
$code = substr($code, $pos + strlen($search)); $code = substr($code, $pos + strlen($search));
$arguments = explode(',', substr($code, 0, stripos($code, ')'))); $arguments = explode(',', substr($code, 0, strpos($code, ');')));
//Remove quotes, ensure 1 \ in front of the model //Remove quotes, ensure 1 \ in front of the model
$returnModel = "\\" . ltrim(trim($arguments[0], " \"'"), "\\"); $returnModel = $this->getClassName($arguments[0], $model);
if ($relation === "belongsToMany" or $relation === 'hasMany' or $relation === 'morphMany' or $relation === 'morphToMany') { if ($relation === "belongsToMany" or $relation === 'hasMany' or $relation === 'morphMany' or $relation === 'morphToMany') {
//Collection or array of models (because Collection is Arrayable) //Collection or array of models (because Collection is Arrayable)
$this->setProperty( $this->setProperty(
@@ -359,14 +361,16 @@ class ModelsCommand extends Command
* @param string|null $type * @param string|null $type
* @param bool|null $read * @param bool|null $read
* @param bool|null $write * @param bool|null $write
* @param string|null $comment
*/ */
protected function setProperty($name, $type = null, $read = null, $write = null) protected function setProperty($name, $type = null, $read = null, $write = null, $comment='')
{ {
if (!isset($this->properties[$name])) { if (!isset($this->properties[$name])) {
$this->properties[$name] = array(); $this->properties[$name] = array();
$this->properties[$name]['type'] = 'mixed'; $this->properties[$name]['type'] = 'mixed';
$this->properties[$name]['read'] = false; $this->properties[$name]['read'] = false;
$this->properties[$name]['write'] = false; $this->properties[$name]['write'] = false;
$this->properties[$name]['comment'] = (string) $comment;
} }
if ($type !== null) { if ($type !== null) {
$this->properties[$name]['type'] = $type; $this->properties[$name]['type'] = $type;
@@ -433,7 +437,7 @@ class ModelsCommand extends Command
} else { } else {
$attr = 'property-read'; $attr = 'property-read';
} }
$tag = Tag::createInstance("@{$attr} {$property['type']} {$name}", $phpdoc); $tag = Tag::createInstance("@{$attr} {$property['type']} {$name} {$property['comment']}", $phpdoc);
$phpdoc->appendTag($tag); $phpdoc->appendTag($tag);
} }
@@ -442,7 +446,7 @@ class ModelsCommand extends Command
continue; continue;
} }
$arguments = implode(', ', $method['arguments']); $arguments = implode(', ', $method['arguments']);
$tag = Tag::createInstance("@method static {$method['type']} {$name}({$arguments}) ", $phpdoc); $tag = Tag::createInstance("@method static {$method['type']} {$name}({$arguments})", $phpdoc);
$phpdoc->appendTag($tag); $phpdoc->appendTag($tag);
} }
@@ -507,4 +511,24 @@ class ModelsCommand extends Command
return $paramsWithDefault; return $paramsWithDefault;
} }
/**
* @param string $className
* @param \Illuminate\Database\Eloquent\Model $model
* @return string
*/
private function getClassName($className, $model)
{
// If the class name was resolved via get_class($this) or static::class
if (strpos($className, 'get_class($this)') !== false || strpos($className, 'static::class') !== false) {
return get_class($model);
}
// If the class name was resolved via ::class (PHP 5.5+)
if (strpos($className, '::class') !== false) {
$end = -1 * strlen('::class');
return substr($className, 0, $end);
}
return "\\" . ltrim(trim($className, " \"'"), "\\") ;
}
} }
+49 -10
View File
@@ -50,15 +50,31 @@ class Generator
$this->extra = array_merge($this->extra, $this->config->get('laravel-ide-helper::extra')); $this->extra = array_merge($this->extra, $this->config->get('laravel-ide-helper::extra'));
$this->magic = array_merge($this->magic, $this->config->get('laravel-ide-helper::magic')); $this->magic = array_merge($this->magic, $this->config->get('laravel-ide-helper::magic'));
$this->interfaces = array_merge($this->interfaces, $this->config->get('laravel-ide-helper::interfaces')); $this->interfaces = array_merge($this->interfaces, $this->config->get('laravel-ide-helper::interfaces'));
// Make all interface classes absolute
foreach ($this->interfaces as &$interface) {
$interface = '\\' . ltrim($interface, '\\');
}
$this->helpers = $helpers; $this->helpers = $helpers;
} }
/** /**
* Generate the helper file contents; * Generate the helper file contents;
* *
* @param string $format The format to generate the helper in (php/json)
* @return string; * @return string;
*/ */
public function generate() public function generate($format = 'php')
{
// Check if the generator for this format exists
$method = 'generate'.ucfirst($format).'Helper';
if (method_exists($this, $method)) {
return $this->$method();
}
return $this->generatePhpHelper();
}
public function generatePhpHelper()
{ {
$app = app(); $app = app();
return $this->view->make('laravel-ide-helper::ide-helper') return $this->view->make('laravel-ide-helper::ide-helper')
@@ -68,10 +84,37 @@ class Generator
->render(); ->render();
} }
public function generateJsonHelper()
{
$classes = array();
foreach ($this->getNamespaces() as $aliases) {
foreach($aliases as $alias) {
$functions = array();
foreach ($alias->getMethods() as $method) {
$functions[$method->getName()] = '('. $method->getParamsWithDefault().')';
}
$classes[$alias->getAlias()] = array(
'functions' => $functions,
);
}
}
$flags = JSON_FORCE_OBJECT;
if (defined('JSON_PRETTY_PRINT')) {
$flags |= JSON_PRETTY_PRINT;
}
return json_encode(array(
'php' => array(
'classes' => $classes,
),
), $flags);
}
protected function detectDrivers() protected function detectDrivers()
{ {
try{ try{
if (class_exists('Cache')) { if (class_exists('Auth') && is_a('Auth', '\Illuminate\Support\Facades\Auth', true)) {
$class = get_class(\Auth::driver()); $class = get_class(\Auth::driver());
$this->extra['Auth'] = array($class); $this->extra['Auth'] = array($class);
$this->interfaces['\Illuminate\Auth\UserProviderInterface'] = $class; $this->interfaces['\Illuminate\Auth\UserProviderInterface'] = $class;
@@ -79,7 +122,7 @@ class Generator
}catch (\Exception $e) {} }catch (\Exception $e) {}
try{ try{
if (class_exists('DB')) { if (class_exists('DB') && is_a('DB', '\Illuminate\Support\Facades\DB', true)) {
$class = get_class(\DB::connection()); $class = get_class(\DB::connection());
$this->extra['DB'] = array($class); $this->extra['DB'] = array($class);
$this->interfaces['\Illuminate\Database\ConnectionInterface'] = $class; $this->interfaces['\Illuminate\Database\ConnectionInterface'] = $class;
@@ -87,7 +130,7 @@ class Generator
}catch (\Exception $e) {} }catch (\Exception $e) {}
try{ try{
if (class_exists('Cache')) { if (class_exists('Cache') && is_a('Cache', '\Illuminate\Support\Facades\Cache', true)) {
$driver = get_class(\Cache::driver()); $driver = get_class(\Cache::driver());
$store = get_class(\Cache::getStore()); $store = get_class(\Cache::getStore());
$this->extra['Cache'] = array($driver, $store); $this->extra['Cache'] = array($driver, $store);
@@ -96,7 +139,7 @@ class Generator
}catch (\Exception $e) {} }catch (\Exception $e) {}
try{ try{
if (class_exists('Queue')) { if (class_exists('Queue') && is_a('Queue', '\Illuminate\Support\Facades\Queue', true)) {
$class = get_class(\Queue::connection()); $class = get_class(\Queue::connection());
$this->extra['Queue'] = array($class); $this->extra['Queue'] = array($class);
$this->interfaces['\Illuminate\Queue\QueueInterface'] = $class; $this->interfaces['\Illuminate\Queue\QueueInterface'] = $class;
@@ -104,17 +147,13 @@ class Generator
}catch (\Exception $e) {} }catch (\Exception $e) {}
try{ try{
if (class_exists('SSH')){ if (class_exists('SSH') && is_a('SSH', '\Illuminate\Support\Facades\SSH', true)){
$class = get_class(\SSH::connection()); $class = get_class(\SSH::connection());
$this->extra['SSH'] = array($class); $this->extra['SSH'] = array($class);
$this->interfaces['\Illuminate\Remote\ConnectionInterface'] = $class; $this->interfaces['\Illuminate\Remote\ConnectionInterface'] = $class;
} }
}catch (\Exception $e) {} }catch (\Exception $e) {}
// Make all interface classes absolute
foreach ($this->interfaces as &$interface) {
$interface = '\\' . ltrim($interface, '\\');
}
} }
/** /**
+33 -2
View File
@@ -12,8 +12,7 @@ namespace Barryvdh\LaravelIdeHelper;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand; use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand;
use Barryvdh\LaravelIdeHelper\Console\Generator2Command; use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
Use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
class IdeHelperServiceProvider extends ServiceProvider class IdeHelperServiceProvider extends ServiceProvider
{ {
@@ -67,4 +66,36 @@ class IdeHelperServiceProvider extends ServiceProvider
return array('command.ide-helper.generate', 'command.ide-helper.models'); return array('command.ide-helper.generate', 'command.ide-helper.models');
} }
/**
* Register the package's component namespaces.
*
* @param string $package
* @param string $namespace
* @param string $path
* @return void
*/
public function package($package, $namespace = null, $path = null)
{
// Is it possible to register the config?
if (method_exists($this->app['config'], 'package')) {
$this->app['config']->package($package, $path.'/config', $namespace);
} else {
// Load the config for now..
$config = $this->app['files']->getRequire($path .'/config/config.php');
foreach($config as $key => $value){
$this->app['config']->set($namespace.'::'.$key, $value);
}
}
// Register view files
$appView = $this->app['path']."/views/packages/{$package}";
if ($this->app['files']->isDirectory($appView))
{
$this->app['view']->addNamespace($namespace, $appView);
}
$this->app['view']->addNamespace($namespace, $path.'/views');
}
} }
+25 -14
View File
@@ -52,9 +52,9 @@ class Method
//Normalize the description and inherit the docs from parents/interfaces //Normalize the description and inherit the docs from parents/interfaces
try { try {
$this->normalizeDescription(); $this->normalizeParams($this->phpdoc);
$this->normalizeParams(); $this->normalizeReturn($this->phpdoc);
$this->normalizeReturn(); $this->normalizeDescription($this->phpdoc);
} catch (\Exception $e) {} } catch (\Exception $e) {}
//Get the parameters, including formatted default values //Get the parameters, including formatted default values
@@ -136,11 +136,12 @@ class Method
/** /**
* Get the description and get the inherited docs. * Get the description and get the inherited docs.
* *
* @param DocBlock $phpdoc
*/ */
protected function normalizeDescription() protected function normalizeDescription(DocBlock $phpdoc)
{ {
//Get the short + long description from the DocBlock //Get the short + long description from the DocBlock
$description = $this->phpdoc->getText(); $description = $phpdoc->getText();
//Loop through parents/interfaces, to fill in {@inheritdoc} //Loop through parents/interfaces, to fill in {@inheritdoc}
if (strpos($description, '{@inheritdoc}') !== false) { if (strpos($description, '{@inheritdoc}') !== false) {
@@ -148,14 +149,18 @@ class Method
$inheritDescription = $inheritdoc->getText(); $inheritDescription = $inheritdoc->getText();
$description = str_replace('{@inheritdoc}', $inheritDescription, $description); $description = str_replace('{@inheritdoc}', $inheritDescription, $description);
$this->phpdoc->setText($description); $phpdoc->setText($description);
$this->normalizeParams($inheritdoc);
$this->normalizeReturn($inheritdoc);
//Add the tags that are inherited //Add the tags that are inherited
$inheritTags = $inheritdoc->getTags(); $inheritTags = $inheritdoc->getTags();
if ($inheritTags) { if ($inheritTags) {
/** @var Tag $tag */
foreach ($inheritTags as $tag) { foreach ($inheritTags as $tag) {
$tag->setDocBlock(); $tag->setDocBlock();
$this->phpdoc->appendTag($tag); $phpdoc->appendTag($tag);
} }
} }
} }
@@ -163,11 +168,13 @@ class Method
/** /**
* Normalize the parameters * Normalize the parameters
*
* @param DocBlock $phpdoc
*/ */
protected function normalizeParams() protected function normalizeParams(DocBlock $phpdoc)
{ {
//Get the return type and adjust them for beter autocomplete //Get the return type and adjust them for beter autocomplete
$paramTags = $this->phpdoc->getTagsByName('param'); $paramTags = $phpdoc->getTagsByName('param');
if ($paramTags) { if ($paramTags) {
/** @var ParamTag $tag */ /** @var ParamTag $tag */
foreach($paramTags as $tag){ foreach($paramTags as $tag){
@@ -184,11 +191,13 @@ class Method
/** /**
* Normalize the return tag (make full namespace, replace interfaces) * Normalize the return tag (make full namespace, replace interfaces)
*
* @param DocBlock $phpdoc
*/ */
protected function normalizeReturn() protected function normalizeReturn(DocBlock $phpdoc)
{ {
//Get the return type and adjust them for beter autocomplete //Get the return type and adjust them for beter autocomplete
$returnTags = $this->phpdoc->getTagsByName('return'); $returnTags = $phpdoc->getTagsByName('return');
if ($returnTags) { if ($returnTags) {
/** @var ReturnTag $tag */ /** @var ReturnTag $tag */
$tag = reset($returnTags); $tag = reset($returnTags);
@@ -252,7 +261,7 @@ class Method
$paramStr = '$' . $param->getName(); $paramStr = '$' . $param->getName();
$params[] = $paramStr; $params[] = $paramStr;
if ($param->isOptional()) { if ($param->isOptional()) {
$default = $param->getDefaultValue(); $default = $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null;
if (is_bool($default)) { if (is_bool($default)) {
$default = $default ? 'true' : 'false'; $default = $default ? 'true' : 'false';
} elseif (is_array($default)) { } elseif (is_array($default)) {
@@ -275,7 +284,7 @@ class Method
/** /**
* @param \ReflectionMethod $reflectionMethod * @param \ReflectionMethod $reflectionMethod
* @return string * @return DocBlock
*/ */
protected function getInheritDoc($reflectionMethod) protected function getInheritDoc($reflectionMethod)
{ {
@@ -288,7 +297,9 @@ class Method
$method = $reflectionMethod->getPrototype(); $method = $reflectionMethod->getPrototype();
} }
if ($method) { if ($method) {
$phpdoc = new DocBlock($method); $namespace = $method->getDeclaringClass()->getNamespaceName();
$phpdoc = new DocBlock($method, new Context($namespace));
if (strpos($phpdoc->getText(), '{@inheritdoc}') !== false) { if (strpos($phpdoc->getText(), '{@inheritdoc}') !== false) {
//Not at the end yet, try another parent/interface.. //Not at the end yet, try another parent/interface..
return $this->getInheritDoc($method); return $this->getInheritDoc($method);
+18 -4
View File
@@ -1,17 +1,20 @@
<?php <?php
use Illuminate\Support\Facades\Config;
return array( return array(
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Filename | Filename & Format
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| |
| The default path to the helper file | The default filename (without extension) and the format (php or json)
| |
*/ */
'filename' => '_ide_helper.php', 'filename' => '_ide_helper',
'format' => 'php',
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
@@ -71,8 +74,19 @@ return array(
'emergency' => 'Monolog\Logger::addEmergency', 'emergency' => 'Monolog\Logger::addEmergency',
) )
), ),
/*
|--------------------------------------------------------------------------
| Interface implementations
|--------------------------------------------------------------------------
|
| These interfaces will be replaced with the implementing class. Some interfaces
| are detected by the helpers, others can be listed below.
|
*/
'interfaces' => array( 'interfaces' => array(
'\Illuminate\Auth\UserInterface' => '\User', '\Illuminate\Auth\UserInterface' => Config::get('auth.model', 'User'),
) )
); );
+2 -2
View File
@@ -16,10 +16,10 @@ namespace <?= $namespace == '__root' ? '' : $namespace ?>{
<?php endif; ?> <?php endif; ?>
<?php foreach($aliases as $alias): ?> <?php foreach($aliases as $alias): ?>
<?= $alias->getClassType() ?> <?= $alias->getAlias() ?> <?= $alias->getExtends() ? 'extends ' . $alias->getExtends() : '' ?>{ <?= $alias->getClassType() ?> <?= $alias->getShortName() ?> <?= $alias->getExtends() ? 'extends ' . $alias->getExtends() : '' ?>{
<?php foreach($alias->getMethods() as $method): ?> <?php foreach($alias->getMethods() as $method): ?>
<?= trim($method->getDocComment()) ?> <?= trim($method->getDocComment(' ')) ?>
public static function <?= $method->getName() ?>(<?= $method->getParamsWithDefault() ?>){<?php if($method->getDeclaringClass() !== $method->getRoot()): ?> public static function <?= $method->getName() ?>(<?= $method->getParamsWithDefault() ?>){<?php if($method->getDeclaringClass() !== $method->getRoot()): ?>