3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Code\Reflection\DocBlock
;
12 use Zend\Code\Reflection\DocBlock\Tag\GenericTag
;
13 use Zend\Code\Reflection\DocBlock\Tag\TagInterface
;
14 use Zend\Code\Reflection\Exception
;
18 const USE_DEFAULT_PROTOTYPES
= 'default';
23 protected $tagNames = array();
28 protected $tags = array();
33 protected $genericTag = null;
36 * @param TagInterface[] $prototypes
38 public function __construct($prototypes = null)
40 if (is_array($prototypes)) {
41 foreach ($prototypes as $prototype) {
42 $this->addTagPrototype($prototype);
44 } elseif ($prototypes === self
::USE_DEFAULT_PROTOTYPES
) {
45 $this->useDefaultPrototypes();
52 public function useDefaultPrototypes()
54 $this->addTagPrototype(new Tag\
ParamTag());
55 $this->addTagPrototype(new Tag\
ReturnTag());
56 $this->addTagPrototype(new Tag\
MethodTag());
57 $this->addTagPrototype(new Tag\
PropertyTag());
58 $this->addTagPrototype(new Tag\
AuthorTag());
59 $this->addTagPrototype(new Tag\
LicenseTag());
60 $this->addTagPrototype(new Tag\
ThrowsTag());
61 $this->addTagPrototype(new Tag\
GenericTag());
65 * @param TagInterface $tag
66 * @throws Exception\InvalidArgumentException
68 public function addTagPrototype(TagInterface
$tag)
70 $tagName = str_replace(array('-', '_'), '', $tag->getName());
72 if (in_array($tagName, $this->tagNames
)) {
73 throw new Exception\
InvalidArgumentException('A tag with this name already exists in this manager');
76 $this->tagNames
[] = $tagName;
79 if ($tag instanceof GenericTag
) {
80 $this->genericTag
= $tag;
85 * @param string $tagName
88 public function hasTag($tagName)
90 // otherwise, only if its name exists as a key
91 return in_array(str_replace(array('-', '_'), '', $tagName), $this->tagNames
);
95 * @param string $tagName
96 * @param string $content
98 * @throws Exception\RuntimeException
100 public function createTag($tagName, $content = null)
102 $tagName = str_replace(array('-', '_'), '', $tagName);
104 if (!$this->hasTag($tagName) && !isset($this->genericTag
)) {
105 throw new Exception\
RuntimeException('This tag name is not supported by this tag manager');
108 $index = array_search($tagName, $this->tagNames
);
110 /* @var TagInterface $tag */
111 $tag = ($index !== false) ?
$this->tags
[$index] : $this->genericTag
;
113 $newTag = clone $tag;
115 $newTag->initialize($content);
118 if ($newTag instanceof GenericTag
) {
119 $newTag->setName($tagName);