Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Code / Reflection / DocBlock / TagManager.php
blob761b39c6a1c1e54aae56baed14c4a0e269cae471
1 <?php
2 /**
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
8 */
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;
16 class TagManager
18 const USE_DEFAULT_PROTOTYPES = 'default';
20 /**
21 * @var array
23 protected $tagNames = array();
25 /**
26 * @var array
28 protected $tags = array();
30 /**
31 * @var GenericTag
33 protected $genericTag = null;
35 /**
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();
49 /**
50 * @return void
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());
64 /**
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;
77 $this->tags[] = $tag;
79 if ($tag instanceof GenericTag) {
80 $this->genericTag = $tag;
84 /**
85 * @param string $tagName
86 * @return bool
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);
94 /**
95 * @param string $tagName
96 * @param string $content
97 * @return GenericTag
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;
114 if ($content) {
115 $newTag->initialize($content);
118 if ($newTag instanceof GenericTag) {
119 $newTag->setName($tagName);
122 return $newTag;