Compare commits

...
16 Commits
Author SHA1 Message Date
Barry vd. Heuvel a9dae91e4d Require doctrine for dev 2014-06-29 16:07:17 +02:00
Barry vd. Heuvel 645926fd37 Improve trait check
Fixes #83
2014-06-29 13:34:52 +02:00
Barry vd. Heuvel 0b70167182 Make doctrine optional
Not needed for most people.
2014-06-29 12:35:57 +02:00
Barry vd. Heuvel 138b3deeb1 Loosen reflection-docblock 2014-06-29 12:09:11 +02:00
Barry vd. Heuvel 9f265f0178 Add 1.x-dev branch-alias 2014-06-29 12:03:46 +02:00
Barry vd. Heuvel 26e02d295f Update readme.md 2014-06-25 19:29:03 +02:00
Barry vd. Heuvel bfe955ce1f Add laracasts link 2014-06-25 19:25:35 +02:00
Barry vd. Heuvel 50e760bac1 Merge pull request #85 from ismailbaskin/master
Allowing to this package installed by rtablada/package-installer
2014-06-06 08:56:41 +02:00
Ismail BASKIN e882cdf84d Allowing to this package installed by rtablada/package-installer 2014-06-05 20:19:22 +03:00
Barry vd. Heuvel c1286d5a9e Skip traits
See #83
2014-06-05 09:44:37 +02:00
Barry vd. Heuvel b92d24429d Enable
Might be useful after all ;)
2014-05-20 10:41:24 +02:00
Barry vd. Heuvel f77f5ae770 Disable where field
Maybe make it optional? Feels kind of bloated..
2014-04-25 13:47:00 +02:00
Barry vd. Heuvel 82ffa52d79 Merge pull request #77 from ukautz/feature-polymorphic
Added property methods for polymorphic relations
2014-04-22 14:29:06 +02:00
Ulrich Kautz d8ed55be7a Added property methods for polymorphic relations 2014-04-22 14:25:44 +02:00
Barry vd. Heuvel 16f77638f1 Move helpers to root
To get them in the namespace.
2014-03-20 16:20:31 +01:00
Barry vd. Heuvel 348ecb361c Fix helper files.
Fixes #72
2014-03-20 16:15:55 +01:00
5 changed files with 48 additions and 17 deletions
+12 -2
View File
@@ -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"
} }
+5
View File
@@ -0,0 +1,5 @@
{
"providers": [
"Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider"
]
}
+5 -3
View File
@@ -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){
@@ -194,22 +198,24 @@ 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){
@@ -170,6 +174,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{