|
16 | 16 | use Barryvdh\Reflection\DocBlock\ContextFactory; |
17 | 17 | use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer; |
18 | 18 | use Barryvdh\Reflection\DocBlock\Tag\MethodTag; |
| 19 | +use Barryvdh\Reflection\DocBlock\Tag\TemplateTag; |
19 | 20 | use Closure; |
20 | 21 | use Illuminate\Config\Repository as ConfigRepository; |
21 | 22 | use Illuminate\Database\Eloquent\Builder as EloquentBuilder; |
@@ -48,6 +49,9 @@ class Alias |
48 | 49 | /** @var ConfigRepository */ |
49 | 50 | protected $config; |
50 | 51 |
|
| 52 | + /** @var string[] */ |
| 53 | + protected $templateNames; |
| 54 | + |
51 | 55 | /** |
52 | 56 | * @param ConfigRepository $config |
53 | 57 | * @param string $alias |
@@ -347,7 +351,8 @@ protected function addMagicMethods() |
347 | 351 | $magic, |
348 | 352 | $this->interfaces, |
349 | 353 | $this->classAliases, |
350 | | - $this->getReturnTypeNormalizers($class) |
| 354 | + $this->getReturnTypeNormalizers($class), |
| 355 | + $this->getTemplateNames() |
351 | 356 | ); |
352 | 357 | } |
353 | 358 | $this->usedMethods[] = $magic; |
@@ -379,7 +384,8 @@ protected function detectMethods() |
379 | 384 | $method->name, |
380 | 385 | $this->interfaces, |
381 | 386 | $this->classAliases, |
382 | | - $this->getReturnTypeNormalizers($reflection) |
| 387 | + $this->getReturnTypeNormalizers($reflection), |
| 388 | + $this->getTemplateNames(), |
383 | 389 | ); |
384 | 390 | } |
385 | 391 | $this->usedMethods[] = $method->name; |
@@ -477,39 +483,62 @@ public function getDocComment($prefix = "\t\t") |
477 | 483 | /** |
478 | 484 | * @param $prefix |
479 | 485 | * @return string |
480 | | - * @throws \ReflectionException |
481 | 486 | */ |
482 | 487 | public function getPhpDocTemplates($prefix = "\t\t") |
483 | 488 | { |
484 | 489 | $templateDoc = new DocBlock(''); |
485 | 490 | $serializer = new DocBlockSerializer(1, $prefix); |
486 | 491 |
|
| 492 | + foreach ($this->getTemplateNames() as $templateName) { |
| 493 | + $template = new TemplateTag('template', $templateName); |
| 494 | + $template->setBound('static'); |
| 495 | + $template->setDocBlock($templateDoc); |
| 496 | + $templateDoc->appendTag($template); |
| 497 | + } |
| 498 | + |
| 499 | + return $serializer->getDocComment($templateDoc); |
| 500 | + } |
| 501 | + |
| 502 | + /** |
| 503 | + * @return string[] |
| 504 | + */ |
| 505 | + public function getTemplateNames() |
| 506 | + { |
| 507 | + if (!isset($this->templateNames)) { |
| 508 | + $this->detectTemplateNames(); |
| 509 | + } |
| 510 | + return $this->templateNames; |
| 511 | + } |
| 512 | + |
| 513 | + /** |
| 514 | + * @return void |
| 515 | + * @throws \ReflectionException |
| 516 | + */ |
| 517 | + protected function detectTemplateNames() |
| 518 | + { |
| 519 | + $templateNames = []; |
487 | 520 | foreach ($this->classes as $class) { |
488 | 521 | $reflection = new ReflectionClass($class); |
489 | 522 | $traits = collect($reflection->getTraitNames()); |
490 | 523 |
|
491 | 524 | $phpdoc = new DocBlock($reflection); |
492 | 525 | $templates = $phpdoc->getTagsByName('template'); |
493 | | - /** @var DocBlock\Tag\TemplateTag $template */ |
| 526 | + /** @var TemplateTag $template */ |
494 | 527 | foreach ($templates as $template) { |
495 | | - $template->setBound('static'); |
496 | | - $template->setDocBlock($templateDoc); |
497 | | - $templateDoc->appendTag($template); |
| 528 | + $templateNames[] = $template->getTemplateName(); |
498 | 529 | } |
499 | 530 |
|
500 | 531 | foreach ($traits as $trait) { |
501 | 532 | $phpdoc = new DocBlock(new ReflectionClass($trait)); |
502 | 533 | $templates = $phpdoc->getTagsByName('template'); |
503 | 534 |
|
504 | | - /** @var DocBlock\Tag\TemplateTag $template */ |
| 535 | + /** @var TemplateTag $template */ |
505 | 536 | foreach ($templates as $template) { |
506 | | - $template->setBound('static'); |
507 | | - $template->setDocBlock($templateDoc); |
508 | | - $templateDoc->appendTag($template); |
| 537 | + $templateNames[] = $template->getTemplateName(); |
509 | 538 | } |
510 | 539 | } |
511 | 540 | } |
512 | | - return $serializer->getDocComment($templateDoc); |
| 541 | + $this->templateNames = $templateNames; |
513 | 542 | } |
514 | 543 |
|
515 | 544 | /** |
|
0 commit comments