From e29e0351355684ad51d1358b3be6cace4213d11f Mon Sep 17 00:00:00 2001 From: Jonas De Smet Date: Thu, 1 Feb 2018 15:53:32 +0100 Subject: [PATCH] Add DocBlocks for classes too --- resources/views/helper.php | 1 + src/Alias.php | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/resources/views/helper.php b/resources/views/helper.php index a41a8d9..8bfbfb6 100644 --- a/resources/views/helper.php +++ b/resources/views/helper.php @@ -15,6 +15,7 @@ namespace { + getDocComment(' ')) ?> getClassType() ?> getExtendsClass() ?> { getMethods() as $method): ?> diff --git a/src/Alias.php b/src/Alias.php index 4902f80..12d23cc 100644 --- a/src/Alias.php +++ b/src/Alias.php @@ -10,6 +10,11 @@ namespace Barryvdh\LaravelIdeHelper; +use Barryvdh\Reflection\DocBlock; +use Barryvdh\Reflection\DocBlock\Context; +use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer; +use ReflectionClass; + class Alias { protected $alias; @@ -27,6 +32,7 @@ class Alias protected $valid = false; protected $magicMethods = array(); protected $interfaces = array(); + protected $phpdoc = null; /** * @param string $alias @@ -56,7 +62,13 @@ class Alias $this->detectNamespace(); $this->detectClassType(); $this->detectExtendsNamespace(); - + + if(!empty($this->namespace)) { + //Create a DocBlock and serializer instance + $this->phpdoc = new DocBlock(new ReflectionClass($alias), new Context($this->namespace)); + } + + if ($facade === '\Illuminate\Database\Eloquent\Model') { $this->usedMethods = array('decrement', 'increment'); } @@ -333,6 +345,18 @@ class Alias } } + /** + * Get the docblock for this alias + * + * @param string $prefix + * @return mixed + */ + public function getDocComment($prefix = "\t\t") + { + $serializer = new DocBlockSerializer(1, $prefix); + return ($this->phpdoc) ? $serializer->getDocComment($this->phpdoc) : ''; + } + /** * Output an error. *