mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 18:13:11 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
81b7febfc6 | ||
|
|
208043b56f | ||
|
|
4cd891eadc | ||
|
|
7917ba911f | ||
|
|
1f5e436d00 | ||
|
|
fb3280eaff | ||
|
|
800ac05377 | ||
|
|
50059faa6f | ||
|
|
bb8d0169ba | ||
|
|
fe692a4e77 | ||
|
|
c3a622fcc9 | ||
|
|
317ef794a5 | ||
|
|
5c846ca16a | ||
|
|
1d4df779d8 | ||
|
|
8f0d346eaa | ||
|
|
73003c0bea | ||
|
|
f12c785688 | ||
|
|
c0aaabb6d7 | ||
|
|
1e6752a29f | ||
|
|
ab50c245d0 | ||
|
|
ab85ca4c5a | ||
|
|
c94012232f | ||
|
|
b9685a1f83 | ||
|
|
7bc74b1844 | ||
|
|
cfa0333446 | ||
|
|
5c6fa1d43f | ||
|
|
23db0e06ca | ||
|
|
52b3accd70 | ||
|
|
cc07cd3b2c | ||
|
|
3113f58f45 | ||
|
|
d00dc62ed6 | ||
|
|
073d90b791 | ||
|
|
5d4af73c29 | ||
|
|
39ffaa62f4 | ||
|
|
231e125821 | ||
|
|
f446326967 | ||
|
|
57dc033061 | ||
|
|
e2b59c6cb5 | ||
|
|
736f2f387e | ||
|
|
486d9d9c4d | ||
|
|
ac8b868261 | ||
|
|
c0eb7e2d7e | ||
|
|
89a17fc7b9 | ||
|
|
ec43d4e65b | ||
|
|
03cc70759b | ||
|
|
f94743fda5 | ||
|
|
3eabba3e5d | ||
|
|
f2de8d3c65 | ||
|
|
10e16a0bdc | ||
|
|
f135845100 | ||
|
|
3c54b17760 | ||
|
|
9a67d9132f | ||
|
|
bd33e05304 | ||
|
|
83bdb7acd7 | ||
|
|
4fc9c671e8 | ||
|
|
6c18c3f39a | ||
|
|
19aa77ac49 | ||
|
|
25ec6bd1ea |
+5
-5
@@ -10,10 +10,10 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.0",
|
||||
"illuminate/support": "4.x",
|
||||
"illuminate/console": "4.x",
|
||||
"illuminate/filesystem": "4.x",
|
||||
"php": ">=5.4.0",
|
||||
"illuminate/support": "5.0.x",
|
||||
"illuminate/console": "5.0.x",
|
||||
"illuminate/filesystem": "5.0.x",
|
||||
"phpdocumentor/reflection-docblock": "2.0.x",
|
||||
"symfony/class-loader": "~2.3"
|
||||
},
|
||||
@@ -30,7 +30,7 @@
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.11-dev"
|
||||
"dev-master": "2.0-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
<?php
|
||||
<?php
|
||||
|
||||
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',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -40,7 +41,7 @@ return array(
|
||||
*/
|
||||
|
||||
'model_locations' => array(
|
||||
'app/models',
|
||||
'app',
|
||||
),
|
||||
|
||||
|
||||
@@ -54,7 +55,6 @@ return array(
|
||||
*/
|
||||
|
||||
'extra' => array(
|
||||
'Artisan' => array('Illuminate\Foundation\Artisan'),
|
||||
'Eloquent' => array('Illuminate\Database\Eloquent\Builder', 'Illuminate\Database\Query\Builder'),
|
||||
'Session' => array('Illuminate\Session\Store'),
|
||||
),
|
||||
@@ -83,7 +83,7 @@ return array(
|
||||
*/
|
||||
|
||||
'interfaces' => array(
|
||||
'\Illuminate\Auth\UserInterface' => '\User',
|
||||
'\Illuminate\Contracts\Auth\Authenticatable' => config('auth.model', 'App\User'),
|
||||
)
|
||||
|
||||
);
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"providers": [
|
||||
"Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider"
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
## Laravel IDE Helper Generator
|
||||
## Laravel 5 IDE Helper Generator
|
||||
[](https://packagist.org/packages/barryvdh/laravel-ide-helper) [](https://packagist.org/packages/barryvdh/laravel-ide-helper)
|
||||
|
||||
### For Laravel 4.x, check [version 1.11](https://github.com/barryvdh/laravel-ide-helper/tree/1.11)
|
||||
|
||||
### 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!_
|
||||
@@ -14,11 +16,11 @@ Note: You do need CodeIntel for Sublime Text: https://github.com/SublimeCodeInte
|
||||
|
||||
### 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 config/app.php
|
||||
|
||||
'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider',
|
||||
|
||||
@@ -34,13 +36,13 @@ You can configure your composer.json to do this after each commit:
|
||||
"post-update-cmd":[
|
||||
"php artisan clear-compiled",
|
||||
"php artisan ide-helper:generate",
|
||||
"php artisan optimize",
|
||||
"php artisan optimize"
|
||||
]
|
||||
},
|
||||
|
||||
You can also publish the config-file to change implementations (ie. interface to specific class) or set defaults for --helpers or --sublime.
|
||||
|
||||
php artisan config:publish barryvdh/laravel-ide-helper
|
||||
php artisan vendor:publish --provider=barryvdh/laravel-ide-helper --tag=config
|
||||
|
||||
The generator tries to identify the real class, but if it cannot be found, you can define it in the config file.
|
||||
|
||||
@@ -53,7 +55,7 @@ The Illuminate/Support/helpers.php is already set-up, but you can add/remove you
|
||||
|
||||
### Automatic phpDocs for Models
|
||||
|
||||
> **Note:** Since v1.10 you need to require `doctrine/dbal: ~2.3` in your own composer.json.
|
||||
> You need to require `doctrine/dbal: ~2.3` in your own composer.json to get database columns.
|
||||
|
||||
If you don't want to write your properties yourself, you can use the command `ide-helper:models` to generate
|
||||
phpDocs, based on table columns, relations and getters/setters. You can write the comments directly to your Model file, using the `--write (-W)` option. By default, you are asked to overwrite or write to a separate file (\_ide\_helper\_models.php) (You can force No with `--nowrite (-N)`).
|
||||
@@ -82,9 +84,9 @@ By default, models in app/models are scanned. The optional argument tells what m
|
||||
|
||||
You can also scan a different directory, using the --dir option (relative from the base path):
|
||||
|
||||
php artisan ide-helper:models --dir="app/workbench/name/package/models" --dir="app/src/Model"
|
||||
php artisan ide-helper:models --dir="path/to/models" --dir="app/src/Model"
|
||||
|
||||
You can publish the config file (`php artisan config:publish barryvdh/laravel-ide-helper`) and set the default directories.
|
||||
You can publish the config file (`php artisan vendor:publish`) and set the default directories.
|
||||
|
||||
Models can be ignored using the --ignore (-I) option
|
||||
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
<?= '<?php' ?>
|
||||
|
||||
/**
|
||||
* An helper file for Laravel 4, to provide autocomplete information to your IDE
|
||||
* Generated for Laravel <?= $version ?> on <?= date("Y-m-d") ?>.
|
||||
*
|
||||
* @author Barry vd. Heuvel <barryvdh@gmail.com>
|
||||
* @see https://github.com/barryvdh/laravel-ide-helper
|
||||
*/
|
||||
|
||||
<?php foreach($namespaces as $namespace => $aliases): ?>
|
||||
namespace <?= $namespace == '__root' ? '' : $namespace ?>{
|
||||
<?php if($namespace == '__root'): ?>
|
||||
exit("This file should not be included, only analyzed by your IDE");
|
||||
<?= $helpers ?>
|
||||
<?php endif; ?>
|
||||
<?php foreach($aliases as $alias): ?>
|
||||
|
||||
<?= $alias->getClassType() ?> <?= $alias->getAlias() ?> <?= $alias->getExtends() ? 'extends ' . $alias->getExtends() : '' ?>{
|
||||
<?php foreach($alias->getMethods() as $method): ?>
|
||||
|
||||
<?= trim($method->getDocComment()) ?>
|
||||
|
||||
public static function <?= $method->getName() ?>(<?= $method->getParamsWithDefault() ?>){<?php if($method->getDeclaringClass() !== $method->getRoot()): ?>
|
||||
|
||||
//Method inherited from <?= $method->getDeclaringClass() ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?= $method->shouldReturn() ? 'return ': '' ?><?= $method->getRoot() ?>::<?= $method->getName() ?>(<?= $method->getParams() ?>);
|
||||
}
|
||||
<?php endforeach; ?>
|
||||
|
||||
}
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
||||
}
|
||||
|
||||
<?php endforeach; ?>
|
||||
<?= '<?php' ?>
|
||||
|
||||
/**
|
||||
* An helper file for Laravel 5, to provide autocomplete information to your IDE
|
||||
* Generated for Laravel <?= $version ?> on <?= date("Y-m-d") ?>.
|
||||
*
|
||||
* @author Barry vd. Heuvel <barryvdh@gmail.com>
|
||||
* @see https://github.com/barryvdh/laravel-ide-helper
|
||||
*/
|
||||
|
||||
<?php foreach($namespaces as $namespace => $aliases): ?>
|
||||
namespace <?= $namespace == '__root' ? '' : $namespace ?>{
|
||||
<?php if($namespace == '__root'): ?>
|
||||
exit("This file should not be included, only analyzed by your IDE");
|
||||
<?= $helpers ?>
|
||||
<?php endif; ?>
|
||||
<?php foreach($aliases as $alias): ?>
|
||||
|
||||
<?= $alias->getClassType() ?> <?= $alias->getShortName() ?> <?= $alias->getExtends() ? 'extends ' . $alias->getExtends() : '' ?>{
|
||||
<?php foreach($alias->getMethods() as $method): ?>
|
||||
|
||||
<?= trim($method->getDocComment(' ')) ?>
|
||||
|
||||
public static function <?= $method->getName() ?>(<?= $method->getParamsWithDefault() ?>){<?php if($method->getDeclaringClass() !== $method->getRoot()): ?>
|
||||
|
||||
//Method inherited from <?= $method->getDeclaringClass() ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?= $method->shouldReturn() ? 'return ': '' ?><?= $method->getRoot() ?>::<?= $method->getName() ?>(<?= $method->getParams() ?>);
|
||||
}
|
||||
<?php endforeach; ?>
|
||||
|
||||
}
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
||||
}
|
||||
|
||||
<?php endforeach; ?>
|
||||
+14
-6
@@ -12,11 +12,11 @@ namespace Barryvdh\LaravelIdeHelper;
|
||||
|
||||
class Alias
|
||||
{
|
||||
|
||||
protected $alias;
|
||||
protected $facade;
|
||||
protected $extends = null;
|
||||
protected $classType = 'class';
|
||||
protected $short;
|
||||
protected $namespace = '__root';
|
||||
protected $root = null;
|
||||
protected $classes = array();
|
||||
@@ -42,7 +42,6 @@ class Alias
|
||||
$facade = '\\' . ltrim($facade, '\\');
|
||||
$this->facade = $facade;
|
||||
|
||||
|
||||
$this->detectRoot();
|
||||
|
||||
if ((!$this->isTrait() && $this->root)) {
|
||||
@@ -54,8 +53,10 @@ class Alias
|
||||
$this->addClass($this->root);
|
||||
$this->detectNamespace();
|
||||
$this->detectClassType();
|
||||
|
||||
|
||||
|
||||
if($facade === '\Illuminate\Database\Eloquent\Model'){
|
||||
$this->usedMethods = array('decrement', 'increment');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,6 +115,12 @@ class Alias
|
||||
return $this->alias;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the short name (without namespace)
|
||||
*/
|
||||
public function getShortName(){
|
||||
return $this->short;
|
||||
}
|
||||
/**
|
||||
* Get the namespace from the alias
|
||||
*
|
||||
@@ -145,6 +152,8 @@ class Alias
|
||||
$nsParts = explode('\\', $this->alias);
|
||||
$this->short = array_pop($nsParts);
|
||||
$this->namespace = implode('\\', $nsParts);
|
||||
}else{
|
||||
$this->short = $this->alias;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,7 +193,6 @@ class Alias
|
||||
|
||||
//If it doesn't exist, skip it
|
||||
if (!class_exists($root) && !interface_exists($root)) {
|
||||
$this->error("Class $root is not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -253,7 +261,7 @@ class Alias
|
||||
if (!in_array($method->name, $this->usedMethods)) {
|
||||
// Only add the methods to the output when the root is not the same as the class.
|
||||
// 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->usedMethods[] = $method->name;
|
||||
|
||||
@@ -59,7 +59,7 @@ class GeneratorCommand extends Command
|
||||
* @param \Illuminate\View\Factory $view
|
||||
*/
|
||||
public function __construct(
|
||||
ConfigRepository $config,
|
||||
/*ConfigRepository */ $config,
|
||||
Filesystem $files, /* Illuminate\View\Factory */
|
||||
$view
|
||||
) {
|
||||
@@ -82,6 +82,14 @@ class GeneratorCommand extends Command
|
||||
);
|
||||
} else {
|
||||
$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')) {
|
||||
$this->useMemoryDriver();
|
||||
@@ -89,8 +97,8 @@ class GeneratorCommand extends Command
|
||||
|
||||
|
||||
$helpers = '';
|
||||
if ($this->option('helpers') || ($this->config->get('laravel-ide-helper::include_helpers'))) {
|
||||
foreach ($this->config->get('laravel-ide-helper::helper_files', array()) as $helper) {
|
||||
if ($this->option('helpers') || ($this->config->get('ide-helper.include_helpers'))) {
|
||||
foreach ($this->config->get('ide-helper.helper_files', array()) as $helper) {
|
||||
if (file_exists($helper)) {
|
||||
$helpers .= str_replace(array('<?php', '?>'), '', $this->files->get($helper));
|
||||
}
|
||||
@@ -100,7 +108,7 @@ class GeneratorCommand extends Command
|
||||
}
|
||||
|
||||
$generator = new Generator($this->config, $this->view, $this->getOutput(), $helpers);
|
||||
$content = $generator->generate();
|
||||
$content = $generator->generate($format);
|
||||
$written = $this->files->put($filename, $content);
|
||||
|
||||
if ($written !== false) {
|
||||
@@ -131,12 +139,11 @@ class GeneratorCommand extends Command
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
$filename = $this->config->get('ide-helper.filename');
|
||||
|
||||
return array(
|
||||
array(
|
||||
'filename',
|
||||
InputArgument::OPTIONAL,
|
||||
'The path to the helper file',
|
||||
$this->config->get('laravel-ide-helper::filename')
|
||||
'filename', InputArgument::OPTIONAL, 'The path to the helper file', $filename
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -148,7 +155,10 @@ class GeneratorCommand extends Command
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
$format = $this->config->get('ide-helper.format');
|
||||
|
||||
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('memory', "M", InputOption::VALUE_NONE, 'Use sqlite memory driver'),
|
||||
array('sublime', "S", InputOption::VALUE_NONE, 'DEPRECATED: Use different style for SublimeText CodeIntel'),
|
||||
|
||||
@@ -60,7 +60,7 @@ class ModelsCommand extends Command
|
||||
$filename = $this->option('filename');
|
||||
$this->write = $this->option('write');
|
||||
$this->dirs = array_merge(
|
||||
$this->laravel['config']->get('laravel-ide-helper::model_locations'),
|
||||
$this->laravel['config']->get('ide-helper.model_locations'),
|
||||
$this->option('dir')
|
||||
);
|
||||
$model = $this->argument('model');
|
||||
@@ -150,8 +150,6 @@ class ModelsCommand extends Command
|
||||
if (in_array($name, $ignore)) {
|
||||
$this->comment("Ignoring model '$name'");
|
||||
continue;
|
||||
} else {
|
||||
$this->comment("Loading model '$name'");
|
||||
}
|
||||
$this->properties = array();
|
||||
$this->methods = array();
|
||||
@@ -159,33 +157,35 @@ class ModelsCommand extends Command
|
||||
try {
|
||||
// handle abstract classes, interfaces, ...
|
||||
$reflectionClass = new \ReflectionClass($name);
|
||||
if (!$reflectionClass->IsInstantiable()) {
|
||||
throw new \Exception($name . ' is not instanciable.');
|
||||
} elseif (!$reflectionClass->isSubclassOf('Illuminate\Database\Eloquent\Model')) {
|
||||
$this->comment("Class '$name' is not a model");
|
||||
|
||||
if (!$reflectionClass->isSubclassOf('Illuminate\Database\Eloquent\Model')) {
|
||||
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) {
|
||||
$this->getPropertiesFromTable($model);
|
||||
}
|
||||
|
||||
$this->getPropertiesFromMethods($model);
|
||||
$output .= $this->createPhpDocs($name);
|
||||
} catch (\Exception $e) {
|
||||
$this->error("Exception: " . $e->getMessage() . "\nCould not analyze class $name.");
|
||||
}
|
||||
} elseif (interface_exists($name) || (function_exists('trait_exists') && trait_exists($name))) {
|
||||
$this->info("Skipping interface/trait $name");
|
||||
} else {
|
||||
$this->error("Class $name does not exist");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!$hasDoctrine) {
|
||||
$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`.'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -256,8 +256,8 @@ class ModelsCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->setProperty($name, $type, true, true);
|
||||
$comment = $column->getComment();
|
||||
$this->setProperty($name, $type, true, true, $comment);
|
||||
$this->setMethod(
|
||||
Str::camel("where_" . $name),
|
||||
'\Illuminate\Database\Query\Builder|\\' . get_class($model),
|
||||
@@ -333,9 +333,9 @@ class ModelsCommand extends Command
|
||||
$search = '$this->' . $relation . '(';
|
||||
if ($pos = stripos($code, $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
|
||||
$returnModel = "\\" . ltrim(trim($arguments[0], " \"'"), "\\");
|
||||
$returnModel = $this->getClassName($arguments[0], $model);
|
||||
if ($relation === "belongsToMany" or $relation === 'hasMany' or $relation === 'morphMany' or $relation === 'morphToMany') {
|
||||
//Collection or array of models (because Collection is Arrayable)
|
||||
$this->setProperty(
|
||||
@@ -361,14 +361,16 @@ class ModelsCommand extends Command
|
||||
* @param string|null $type
|
||||
* @param bool|null $read
|
||||
* @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])) {
|
||||
$this->properties[$name] = array();
|
||||
$this->properties[$name]['type'] = 'mixed';
|
||||
$this->properties[$name]['read'] = false;
|
||||
$this->properties[$name]['write'] = false;
|
||||
$this->properties[$name]['comment'] = (string) $comment;
|
||||
}
|
||||
if ($type !== null) {
|
||||
$this->properties[$name]['type'] = $type;
|
||||
@@ -435,7 +437,7 @@ class ModelsCommand extends Command
|
||||
} else {
|
||||
$attr = 'property-read';
|
||||
}
|
||||
$tag = Tag::createInstance("@{$attr} {$property['type']} {$name}", $phpdoc);
|
||||
$tag = Tag::createInstance("@{$attr} {$property['type']} {$name} {$property['comment']}", $phpdoc);
|
||||
$phpdoc->appendTag($tag);
|
||||
}
|
||||
|
||||
@@ -444,7 +446,7 @@ class ModelsCommand extends Command
|
||||
continue;
|
||||
}
|
||||
$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);
|
||||
}
|
||||
|
||||
@@ -509,4 +511,24 @@ class ModelsCommand extends Command
|
||||
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, " \"'"), "\\") ;
|
||||
}
|
||||
}
|
||||
|
||||
+60
-15
@@ -36,7 +36,7 @@ class Generator
|
||||
* @param \Symfony\Component\Console\Output\OutputInterface $output
|
||||
* @param string $helpers
|
||||
*/
|
||||
public function __construct(ConfigRepository $config,
|
||||
public function __construct(/*ConfigRepository */ $config,
|
||||
/* Illuminate\View\Factory */ $view,
|
||||
OutputInterface $output = null,
|
||||
$helpers = ''
|
||||
@@ -47,31 +47,74 @@ class Generator
|
||||
// Find the drivers to add to the extra/interfaces
|
||||
$this->detectDrivers();
|
||||
|
||||
$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->interfaces = array_merge($this->interfaces, $this->config->get('laravel-ide-helper::interfaces'));
|
||||
$this->extra = array_merge($this->extra, $this->config->get('ide-helper.extra'));
|
||||
$this->magic = array_merge($this->magic, $this->config->get('ide-helper.magic'));
|
||||
$this->interfaces = array_merge($this->interfaces, $this->config->get('ide-helper.interfaces'));
|
||||
// Make all interface classes absolute
|
||||
foreach ($this->interfaces as &$interface) {
|
||||
$interface = '\\' . ltrim($interface, '\\');
|
||||
}
|
||||
$this->helpers = $helpers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the helper file contents;
|
||||
*
|
||||
* @param string $format The format to generate the helper in (php/json)
|
||||
* @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();
|
||||
return $this->view->make('laravel-ide-helper::ide-helper')
|
||||
return $this->view->make('ide-helper::helper')
|
||||
->with('namespaces', $this->getNamespaces())
|
||||
->with('helpers', $this->helpers)
|
||||
->with('version', $app::VERSION)
|
||||
->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()
|
||||
{
|
||||
try{
|
||||
if (class_exists('Auth')) {
|
||||
if (class_exists('Auth') && is_a('Auth', '\Illuminate\Support\Facades\Auth', true)) {
|
||||
$class = get_class(\Auth::driver());
|
||||
$this->extra['Auth'] = array($class);
|
||||
$this->interfaces['\Illuminate\Auth\UserProviderInterface'] = $class;
|
||||
@@ -79,7 +122,7 @@ class Generator
|
||||
}catch (\Exception $e) {}
|
||||
|
||||
try{
|
||||
if (class_exists('DB')) {
|
||||
if (class_exists('DB') && is_a('DB', '\Illuminate\Support\Facades\DB', true)) {
|
||||
$class = get_class(\DB::connection());
|
||||
$this->extra['DB'] = array($class);
|
||||
$this->interfaces['\Illuminate\Database\ConnectionInterface'] = $class;
|
||||
@@ -87,7 +130,7 @@ class Generator
|
||||
}catch (\Exception $e) {}
|
||||
|
||||
try{
|
||||
if (class_exists('Cache')) {
|
||||
if (class_exists('Cache') && is_a('Cache', '\Illuminate\Support\Facades\Cache', true)) {
|
||||
$driver = get_class(\Cache::driver());
|
||||
$store = get_class(\Cache::getStore());
|
||||
$this->extra['Cache'] = array($driver, $store);
|
||||
@@ -96,7 +139,7 @@ class Generator
|
||||
}catch (\Exception $e) {}
|
||||
|
||||
try{
|
||||
if (class_exists('Queue')) {
|
||||
if (class_exists('Queue') && is_a('Queue', '\Illuminate\Support\Facades\Queue', true)) {
|
||||
$class = get_class(\Queue::connection());
|
||||
$this->extra['Queue'] = array($class);
|
||||
$this->interfaces['\Illuminate\Queue\QueueInterface'] = $class;
|
||||
@@ -104,17 +147,13 @@ class Generator
|
||||
}catch (\Exception $e) {}
|
||||
|
||||
try{
|
||||
if (class_exists('SSH')){
|
||||
if (class_exists('SSH') && is_a('SSH', '\Illuminate\Support\Facades\SSH', true)){
|
||||
$class = get_class(\SSH::connection());
|
||||
$this->extra['SSH'] = array($class);
|
||||
$this->interfaces['\Illuminate\Remote\ConnectionInterface'] = $class;
|
||||
}
|
||||
}catch (\Exception $e) {}
|
||||
|
||||
// Make all interface classes absolute
|
||||
foreach ($this->interfaces as &$interface) {
|
||||
$interface = '\\' . ltrim($interface, '\\');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,6 +167,12 @@ class Generator
|
||||
|
||||
// Get all aliases
|
||||
foreach (AliasLoader::getInstance()->getAliases() as $name => $facade) {
|
||||
|
||||
// Skip the Redis facade, if not available (otherwise Fatal PHP Error)
|
||||
if ($facade == 'Illuminate\Support\Facades\Redis' && !class_exists('Predis\Client')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$magicMethods = array_key_exists($name, $this->magic) ? $this->magic[$name] : array();
|
||||
$alias = new Alias($name, $facade, $magicMethods, $this->interfaces);
|
||||
if ($alias->isValid()) {
|
||||
|
||||
@@ -12,8 +12,7 @@ namespace Barryvdh\LaravelIdeHelper;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand;
|
||||
use Barryvdh\LaravelIdeHelper\Console\Generator2Command;
|
||||
Use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||
|
||||
class IdeHelperServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -32,7 +31,11 @@ class IdeHelperServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->package('barryvdh/laravel-ide-helper', 'laravel-ide-helper', __DIR__);
|
||||
$viewPath = __DIR__.'/../resources/views';
|
||||
$this->loadViewsFrom($viewPath, 'ide-helper');
|
||||
|
||||
$configPath = __DIR__ . '/../config/ide-helper.php';
|
||||
$this->publishes([$configPath => config_path('ide-helper.php')], 'config');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,6 +45,9 @@ class IdeHelperServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$configPath = __DIR__ . '/../config/ide-helper.php';
|
||||
$this->mergeConfigFrom($configPath, 'ide-helper');
|
||||
|
||||
$this->app['command.ide-helper.generate'] = $this->app->share(
|
||||
function ($app) {
|
||||
return new GeneratorCommand($app['config'], $app['files'], $app['view']);
|
||||
|
||||
+1
-1
@@ -261,7 +261,7 @@ class Method
|
||||
$paramStr = '$' . $param->getName();
|
||||
$params[] = $paramStr;
|
||||
if ($param->isOptional()) {
|
||||
$default = $param->getDefaultValue();
|
||||
$default = $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null;
|
||||
if (is_bool($default)) {
|
||||
$default = $default ? 'true' : 'false';
|
||||
} elseif (is_array($default)) {
|
||||
|
||||
Reference in New Issue
Block a user