mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 10:07:12 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a9dae91e4d | ||
|
|
645926fd37 | ||
|
|
0b70167182 | ||
|
|
138b3deeb1 | ||
|
|
9f265f0178 | ||
|
|
26e02d295f | ||
|
|
bfe955ce1f | ||
|
|
50e760bac1 | ||
|
|
e882cdf84d | ||
|
|
c1286d5a9e | ||
|
|
b92d24429d | ||
|
|
f77f5ae770 | ||
|
|
82ffa52d79 | ||
|
|
d8ed55be7a | ||
|
|
16f77638f1 | ||
|
|
348ecb361c |
+12
-2
@@ -14,14 +14,24 @@
|
|||||||
"illuminate/support": "4.x",
|
"illuminate/support": "4.x",
|
||||||
"illuminate/console": "4.x",
|
"illuminate/console": "4.x",
|
||||||
"illuminate/filesystem": "4.x",
|
"illuminate/filesystem": "4.x",
|
||||||
"phpdocumentor/reflection-docblock": "2.0.0",
|
"phpdocumentor/reflection-docblock": "2.0.x",
|
||||||
"symfony/class-loader": "~2.3",
|
"symfony/class-loader": "~2.3"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
"doctrine/dbal": "~2.3"
|
"doctrine/dbal": "~2.3"
|
||||||
},
|
},
|
||||||
|
"suggest": {
|
||||||
|
"doctrine/dbal": "Load information from the database about models for phpdocs (~2.3)"
|
||||||
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": {
|
"psr-0": {
|
||||||
"Barryvdh\\LaravelIdeHelper": "src/"
|
"Barryvdh\\LaravelIdeHelper": "src/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "1.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
"minimum-stability": "dev"
|
"minimum-stability": "dev"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"providers": [
|
||||||
|
"Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
### 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!_
|
||||||
|
|
||||||
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.
|
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)
|
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
|
### 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
|
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.
|
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)`).
|
||||||
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)`).
|
|
||||||
Please make sure to backup your models, before writing the info.
|
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.
|
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.
|
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();
|
$aliases = $aliasLoader->getAliases();
|
||||||
|
|
||||||
foreach($aliases as $alias => $facade){
|
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, '\\');
|
$facade = '\\'.ltrim($facade, '\\');
|
||||||
$root = $this->getRoot($facade);
|
$root = $this->getRoot($facade);
|
||||||
if(!$root){
|
if(!$root){
|
||||||
@@ -193,23 +197,25 @@ class GeneratorCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($output as $ns => $body){
|
|
||||||
if ($ns == '__root') $ns = '';
|
|
||||||
$outputString .= "namespace $ns{\n";
|
|
||||||
$outputString .= $body;
|
|
||||||
$outputString .= "}\n\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
//Include the helper file, if requested
|
//Include the helper file, if requested
|
||||||
if(!empty($this->helpers)){
|
if(!empty($this->helpers)){
|
||||||
foreach($this->helpers as $helper){
|
foreach($this->helpers as $helper){
|
||||||
if (file_exists($helper)){
|
if (file_exists($helper)){
|
||||||
$output .= str_replace(array('<?php', '?>'), '', \File::get($helper));
|
$output['__root'] .= str_replace(array('<?php', '?>'), '', \File::get($helper));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($output as $ns => $body){
|
||||||
|
if ($ns == '__root'){
|
||||||
|
$ns = '';
|
||||||
|
}
|
||||||
|
$outputString .= "namespace $ns{\n";
|
||||||
|
$outputString .= $body;
|
||||||
|
$outputString .= "}\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
return $outputString;
|
return $outputString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -126,6 +126,8 @@ class ModelsCommand extends Command {
|
|||||||
*/
|
*/
|
||||||
\n\n";
|
\n\n";
|
||||||
|
|
||||||
|
$hasDoctrine = interface_exists('Doctrine\DBAL\Driver');
|
||||||
|
|
||||||
if(empty($loadModels)){
|
if(empty($loadModels)){
|
||||||
$models = $this->loadModels();
|
$models = $this->loadModels();
|
||||||
}else{
|
}else{
|
||||||
@@ -158,7 +160,9 @@ class ModelsCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$model = new $name();
|
$model = new $name();
|
||||||
$this->getPropertiesFromTable($model);
|
if($hasDoctrine){
|
||||||
|
$this->getPropertiesFromTable($model);
|
||||||
|
}
|
||||||
$this->getPropertiesFromMethods($model);
|
$this->getPropertiesFromMethods($model);
|
||||||
$output .= $this->createPhpDocs($name);
|
$output .= $this->createPhpDocs($name);
|
||||||
}catch(\Exception $e){
|
}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;
|
return $output;
|
||||||
|
|
||||||
@@ -287,14 +295,14 @@ class ModelsCommand extends Command {
|
|||||||
$begin = strpos($code, 'function(');
|
$begin = strpos($code, 'function(');
|
||||||
$code = substr($code, $begin, strrpos($code, '}') - $begin + 1);
|
$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.'(';
|
$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, stripos($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 = "\\".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)
|
//Collection or array of models (because Collection is Arrayable)
|
||||||
$this->setProperty($method, '\Illuminate\Database\Eloquent\Collection|'.$returnModel.'[]', true, null);
|
$this->setProperty($method, '\Illuminate\Database\Eloquent\Collection|'.$returnModel.'[]', true, null);
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
Reference in New Issue
Block a user