mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 01:57:13 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a9dae91e4d | ||
|
|
645926fd37 | ||
|
|
0b70167182 | ||
|
|
138b3deeb1 | ||
|
|
9f265f0178 | ||
|
|
26e02d295f | ||
|
|
bfe955ce1f | ||
|
|
50e760bac1 | ||
|
|
e882cdf84d | ||
|
|
c1286d5a9e | ||
|
|
b92d24429d | ||
|
|
f77f5ae770 | ||
|
|
82ffa52d79 | ||
|
|
d8ed55be7a |
+12
-2
@@ -14,14 +14,24 @@
|
||||
"illuminate/support": "4.x",
|
||||
"illuminate/console": "4.x",
|
||||
"illuminate/filesystem": "4.x",
|
||||
"phpdocumentor/reflection-docblock": "2.0.0",
|
||||
"symfony/class-loader": "~2.3",
|
||||
"phpdocumentor/reflection-docblock": "2.0.x",
|
||||
"symfony/class-loader": "~2.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/dbal": "~2.3"
|
||||
},
|
||||
"suggest": {
|
||||
"doctrine/dbal": "Load information from the database about models for phpdocs (~2.3)"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Barryvdh\\LaravelIdeHelper": "src/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.x-dev"
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"providers": [
|
||||
"Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider"
|
||||
]
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
### 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!_
|
||||
|
||||
This packages generates a file that your IDE can understand, so it can provide accurate autocompletion. Generation is done, based on the files in your project, so they are alway up-to-date.
|
||||
If you don't want to generate it, you can add a pre-generated file to the root folder of your laravel project. (But this isn't as up-to-date as self generated files)
|
||||
|
||||
@@ -51,10 +53,10 @@ 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.
|
||||
|
||||
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. Still in beta, so please provide feedback if you want.
|
||||
You can now also 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)`).
|
||||
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)`).
|
||||
Please make sure to backup your models, before writing the info.
|
||||
It should keep the existing comments and only append new properties/methods. The existing phpdoc is replaced, or added if not found.
|
||||
With the `--reset (-R)` option, the existing phpdocs are ignored, only the newly found columns/relations are saved as phpdocs.
|
||||
|
||||
@@ -138,6 +138,10 @@ class GeneratorCommand extends Command {
|
||||
$aliases = $aliasLoader->getAliases();
|
||||
|
||||
foreach($aliases as $alias => $facade){
|
||||
//Check if the facade is not a Trait
|
||||
if(function_exists('trait_exists') && trait_exists($facade)){
|
||||
continue;
|
||||
}
|
||||
$facade = '\\'.ltrim($facade, '\\');
|
||||
$root = $this->getRoot($facade);
|
||||
if(!$root){
|
||||
|
||||
@@ -126,6 +126,8 @@ class ModelsCommand extends Command {
|
||||
*/
|
||||
\n\n";
|
||||
|
||||
$hasDoctrine = interface_exists('Doctrine\DBAL\Driver');
|
||||
|
||||
if(empty($loadModels)){
|
||||
$models = $this->loadModels();
|
||||
}else{
|
||||
@@ -158,7 +160,9 @@ class ModelsCommand extends Command {
|
||||
}
|
||||
|
||||
$model = new $name();
|
||||
$this->getPropertiesFromTable($model);
|
||||
if($hasDoctrine){
|
||||
$this->getPropertiesFromTable($model);
|
||||
}
|
||||
$this->getPropertiesFromMethods($model);
|
||||
$output .= $this->createPhpDocs($name);
|
||||
}catch(\Exception $e){
|
||||
@@ -169,6 +173,10 @@ class ModelsCommand extends Command {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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'.");
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
||||
@@ -287,14 +295,14 @@ class ModelsCommand extends Command {
|
||||
$begin = strpos($code, 'function(');
|
||||
$code = substr($code, $begin, strrpos($code, '}') - $begin + 1);
|
||||
|
||||
foreach(array('hasMany', 'belongsToMany', 'hasOne', 'belongsTo') as $relation){
|
||||
foreach(array('hasMany', 'belongsToMany', 'hasOne', 'belongsTo', 'morphTo', 'morphMany', 'morphToMany') as $relation){
|
||||
$search = '$this->'.$relation.'(';
|
||||
if($pos = stripos($code, $search)){
|
||||
$code = substr($code, $pos + strlen($search));
|
||||
$arguments = explode(',', substr($code, 0, stripos($code, ')')));
|
||||
//Remove quotes, ensure 1 \ in front of the model
|
||||
$returnModel = "\\".ltrim(trim($arguments[0], " \"'"), "\\");
|
||||
if($relation === "belongsToMany" or $relation === 'hasMany'){
|
||||
if($relation === "belongsToMany" or $relation === 'hasMany' or $relation === 'morphMany' or $relation === 'morphToMany'){
|
||||
//Collection or array of models (because Collection is Arrayable)
|
||||
$this->setProperty($method, '\Illuminate\Database\Eloquent\Collection|'.$returnModel.'[]', true, null);
|
||||
}else{
|
||||
|
||||
Reference in New Issue
Block a user