mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 01:57:13 +00:00
Compare commits
9
Commits
v1.0.0-beta2
...
v1.0.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0b324b8cc | ||
|
|
dab594804b | ||
|
|
83d5fe048d | ||
|
|
77b1bc923e | ||
|
|
9090aeb766 | ||
|
|
a5c16b0751 | ||
|
|
16b3b872a3 | ||
|
|
507775fda6 | ||
|
|
83ab04be40 |
@@ -1,6 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "barryvdh/laravel-ide-helper",
|
"name": "barryvdh/laravel-ide-helper",
|
||||||
"description": "Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.",
|
"description": "Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.",
|
||||||
|
"keywords": ["laravel", "autocomplete", "phpstorm", "netbeans", "sublime", "codeintel", "phpdoc"],
|
||||||
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Barry vd. Heuvel",
|
"name": "Barry vd. Heuvel",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
## Laravel IDE Helper & Generator
|
## Laravel IDE Helper Generator
|
||||||
|
|
||||||
### Complete phpDocs, directly from the source
|
### Complete phpDocs, directly from the source
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ Add the helper file to your laravel folder (not in a public folder). The file is
|
|||||||
|
|
||||||
Require this package in your composer.json:
|
Require this package in your composer.json:
|
||||||
|
|
||||||
"barryvdh/laravel-ide-helper": "dev-master"
|
"barryvdh/laravel-ide-helper": "1.*"
|
||||||
|
|
||||||
And add the ServiceProvider to the providers array in app/config/app.php
|
And add the ServiceProvider to the providers array in app/config/app.php
|
||||||
|
|
||||||
@@ -67,3 +67,6 @@ Also, all relations are Eloquent|Eloquent[] by default, you can change them to t
|
|||||||
After copying the phpdocs to your model, you can clear the file, so your IDE only uses the real source.
|
After copying the phpdocs to your model, you can clear the file, so your IDE only uses the real source.
|
||||||
|
|
||||||
|
|
||||||
|
### License
|
||||||
|
|
||||||
|
The Laravel IDE Helper Generator is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)
|
||||||
@@ -1,4 +1,14 @@
|
|||||||
<?php namespace Barryvdh\LaravelIdeHelper;
|
<?php
|
||||||
|
/**
|
||||||
|
* Laravel IDE Helper Generator
|
||||||
|
*
|
||||||
|
* @author Barry vd. Heuvel <[email protected]>
|
||||||
|
* @copyright 2013 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link https://github.com/barryvdh/laravel-ide-helper
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
|||||||
@@ -1,4 +1,14 @@
|
|||||||
<?php namespace Barryvdh\LaravelIdeHelper;
|
<?php
|
||||||
|
/**
|
||||||
|
* Laravel IDE Helper Generator
|
||||||
|
*
|
||||||
|
* @author Barry vd. Heuvel <[email protected]>
|
||||||
|
* @copyright 2013 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link https://github.com/barryvdh/laravel-ide-helper
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper;
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,22 @@
|
|||||||
<?php namespace Barryvdh\LaravelIdeHelper;
|
<?php
|
||||||
|
/**
|
||||||
|
* Laravel IDE Helper Generator
|
||||||
|
*
|
||||||
|
* @author Barry vd. Heuvel <[email protected]>
|
||||||
|
* @copyright 2013 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link https://github.com/barryvdh/laravel-ide-helper
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\ClassLoader\ClassMapGenerator;
|
use Symfony\Component\ClassLoader\ClassMapGenerator;
|
||||||
|
use phpDocumentor\Reflection\DocBlock;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\Context;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\Tag;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\Serializer as DocBlockSerializer;
|
||||||
/**
|
/**
|
||||||
* A command to generate autocomplete information for your IDE
|
* A command to generate autocomplete information for your IDE
|
||||||
*
|
*
|
||||||
@@ -126,17 +140,23 @@ class ModelsCommand extends Command {
|
|||||||
return $models;
|
return $models;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the properties from the database table.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Database\Eloquent\Model $model
|
||||||
|
*/
|
||||||
protected function getPropertiesFromTable($model){
|
protected function getPropertiesFromTable($model){
|
||||||
$table = $model->getTable();
|
$table = $model->getTable();
|
||||||
$schema = $model->getConnection()->getDoctrineSchemaManager($table);
|
$schema = $model->getConnection()->getDoctrineSchemaManager($table);
|
||||||
|
$schema->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
|
||||||
|
|
||||||
$columns = $schema->listTableColumns($table);
|
$columns = $schema->listTableColumns($table);
|
||||||
|
|
||||||
$properties = array();
|
|
||||||
if($columns){
|
if($columns){
|
||||||
foreach ($columns as $column) {
|
foreach ($columns as $column) {
|
||||||
$name = $column->getName();
|
$name = $column->getName();
|
||||||
$type = $column->getType()->getName();
|
$type = $column->getType()->getName();
|
||||||
|
|
||||||
switch($type){
|
switch($type){
|
||||||
case 'string':
|
case 'string':
|
||||||
case 'text':
|
case 'text':
|
||||||
@@ -170,6 +190,9 @@ class ModelsCommand extends Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Illuminate\Database\Eloquent\Model $model
|
||||||
|
*/
|
||||||
protected function getPropertiesFromMethods($model){
|
protected function getPropertiesFromMethods($model){
|
||||||
$methods = get_class_methods($model);
|
$methods = get_class_methods($model);
|
||||||
if($methods){
|
if($methods){
|
||||||
@@ -232,6 +255,12 @@ class ModelsCommand extends Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @param string|null $type
|
||||||
|
* @param bool|null $read
|
||||||
|
* @param bool|null $write
|
||||||
|
*/
|
||||||
protected function setProperty($name, $type = null, $read = null, $write = null){
|
protected function setProperty($name, $type = null, $read = null, $write = null){
|
||||||
if(!isset($this->properties[$name])){
|
if(!isset($this->properties[$name])){
|
||||||
$this->properties[$name] = array();
|
$this->properties[$name] = array();
|
||||||
@@ -260,18 +289,36 @@ class ModelsCommand extends Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $class
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
protected function createPhpDocs($class){
|
protected function createPhpDocs($class){
|
||||||
|
|
||||||
if(strpos($class, '\\') !== false){
|
$reflection = new \ReflectionClass($class);
|
||||||
$parts = explode('\\', $class);
|
$namespace = $reflection->getNamespaceName();
|
||||||
$class = array_pop($parts);
|
$phpdoc = new DocBlock($reflection, new Context($namespace));
|
||||||
$namespace = implode($parts, '\\');
|
|
||||||
}else{
|
if(!$phpdoc->getText()){
|
||||||
$namespace = '';
|
$phpdoc->setText("Generated properties for $class");
|
||||||
}
|
}
|
||||||
$output = "namespace $namespace{\n";
|
|
||||||
$output .= "\t/**\n\t *\n\t * Generated properties for $class\n\t *\n";
|
$properties = array();
|
||||||
|
$methods = array();
|
||||||
|
foreach($phpdoc->getTags() as $tag){
|
||||||
|
$name = $tag->getName();
|
||||||
|
if($name == "property" || $name == "property-read" || $name == "property-write"){
|
||||||
|
$properties[] =$tag->getVariableName();
|
||||||
|
}elseif($name == "method"){
|
||||||
|
$methods[] = $tag->getMethodName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach($this->properties as $name => $property){
|
foreach($this->properties as $name => $property){
|
||||||
|
$name = "\$$name";
|
||||||
|
if(in_array($name, $properties)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if($property['read'] && $property['write']){
|
if($property['read'] && $property['write']){
|
||||||
$attr = 'property';
|
$attr = 'property';
|
||||||
}elseif($property['write']){
|
}elseif($property['write']){
|
||||||
@@ -279,16 +326,24 @@ class ModelsCommand extends Command {
|
|||||||
}else{
|
}else{
|
||||||
$attr = 'property-read';
|
$attr = 'property-read';
|
||||||
}
|
}
|
||||||
$type = $property['type'];
|
$tag = Tag::createInstance("@{$attr} {$property['type']} {$name}", $phpdoc);
|
||||||
$output .= "\t * @$attr $type \$$name \n";
|
$phpdoc->appendTag($tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($this->methods as $name => $method){
|
foreach($this->methods as $name => $method){
|
||||||
$type = $method['type'];
|
if(in_array($name, $methods)){
|
||||||
$output .= "\t * @method $type $name() \n";
|
continue;
|
||||||
|
}
|
||||||
|
$name = "$name()";
|
||||||
|
$tag = Tag::createInstance("@method {$method['type']} {$name}", $phpdoc);
|
||||||
|
$phpdoc->appendTag($tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
$output .= "\t *\n\t */\n\tclass $class {}\n}\n\n";
|
$serializer = new DocBlockSerializer(1, "\t");
|
||||||
|
$serializer->getDocComment($phpdoc);
|
||||||
|
$docComment = $serializer->getDocComment($phpdoc);
|
||||||
|
|
||||||
|
$output = "namespace {$namespace}{\n{$docComment}\n\tclass {$class} {}\n}\n\n";
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user