mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 18:13:11 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0b324b8cc | ||
|
|
dab594804b | ||
|
|
83d5fe048d | ||
|
|
77b1bc923e | ||
|
|
9090aeb766 | ||
|
|
a5c16b0751 |
@@ -1,4 +1,4 @@
|
|||||||
## Laravel IDE Helper & Generator
|
## Laravel IDE Helper Generator
|
||||||
|
|
||||||
### Complete phpDocs, directly from the source
|
### Complete phpDocs, directly from the source
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ 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
|
||||||
*
|
*
|
||||||
@@ -136,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':
|
||||||
@@ -180,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){
|
||||||
@@ -242,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();
|
||||||
@@ -270,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']){
|
||||||
@@ -289,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