123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- <?php
- namespace phpDocumentor\Reflection;
- use phpDocumentor\Reflection\DocBlock\Tag;
- use Webmozart\Assert\Assert;
- final class DocBlock
- {
-
- private $summary = '';
-
- private $description = null;
-
- private $tags = [];
-
- private $context = null;
-
- private $location = null;
-
- private $isTemplateStart = false;
-
- private $isTemplateEnd = false;
-
- public function __construct(
- $summary = '',
- DocBlock\Description $description = null,
- array $tags = [],
- Types\Context $context = null,
- Location $location = null,
- $isTemplateStart = false,
- $isTemplateEnd = false
- ) {
- Assert::string($summary);
- Assert::boolean($isTemplateStart);
- Assert::boolean($isTemplateEnd);
- Assert::allIsInstanceOf($tags, Tag::class);
- $this->summary = $summary;
- $this->description = $description ?: new DocBlock\Description('');
- foreach ($tags as $tag) {
- $this->addTag($tag);
- }
- $this->context = $context;
- $this->location = $location;
- $this->isTemplateEnd = $isTemplateEnd;
- $this->isTemplateStart = $isTemplateStart;
- }
-
- public function getSummary()
- {
- return $this->summary;
- }
-
- public function getDescription()
- {
- return $this->description;
- }
-
- public function getContext()
- {
- return $this->context;
- }
-
- public function getLocation()
- {
- return $this->location;
- }
-
- public function isTemplateStart()
- {
- return $this->isTemplateStart;
- }
-
- public function isTemplateEnd()
- {
- return $this->isTemplateEnd;
- }
-
- public function getTags()
- {
- return $this->tags;
- }
-
- public function getTagsByName($name)
- {
- Assert::string($name);
- $result = [];
-
- foreach ($this->getTags() as $tag) {
- if ($tag->getName() !== $name) {
- continue;
- }
- $result[] = $tag;
- }
- return $result;
- }
-
- public function hasTag($name)
- {
- Assert::string($name);
-
- foreach ($this->getTags() as $tag) {
- if ($tag->getName() === $name) {
- return true;
- }
- }
- return false;
- }
-
- public function removeTag(Tag $tagToRemove)
- {
- foreach ($this->tags as $key => $tag) {
- if ($tag === $tagToRemove) {
- unset($this->tags[$key]);
- break;
- }
- }
- }
-
- private function addTag(Tag $tag)
- {
- $this->tags[] = $tag;
- }
- }
|