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 / Generator / DocBlockGenerator.php
blob78f0b7febfcb0906abf6d14c50a6a0c58573301e
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\Generator;
12 use Zend\Code\Generator\DocBlock\Tag as DocBlockTag;
13 use Zend\Code\Reflection\DocBlockReflection;
15 class DocBlockGenerator extends AbstractGenerator
17 /**
18 * @var string
20 protected $shortDescription = null;
22 /**
23 * @var string
25 protected $longDescription = null;
27 /**
28 * @var array
30 protected $tags = array();
32 /**
33 * @var string
35 protected $indentation = '';
37 /**
38 * @var bool
40 protected $wordwrap = true;
42 /**
43 * Build a DocBlock generator object from a reflection object
45 * @param DocBlockReflection $reflectionDocBlock
46 * @return DocBlockGenerator
48 public static function fromReflection(DocBlockReflection $reflectionDocBlock)
50 $docBlock = new static();
52 $docBlock->setSourceContent($reflectionDocBlock->getContents());
53 $docBlock->setSourceDirty(false);
55 $docBlock->setShortDescription($reflectionDocBlock->getShortDescription());
56 $docBlock->setLongDescription($reflectionDocBlock->getLongDescription());
58 foreach ($reflectionDocBlock->getTags() as $tag) {
59 $docBlock->setTag(DocBlockTag::fromReflection($tag));
62 return $docBlock;
65 /**
66 * Generate from array
68 * @configkey shortdescription string The short description for this doc block
69 * @configkey longdescription string The long description for this doc block
70 * @configkey tags array
72 * @throws Exception\InvalidArgumentException
73 * @param array $array
74 * @return DocBlockGenerator
76 public static function fromArray(array $array)
78 $docBlock = new static();
80 foreach ($array as $name => $value) {
81 // normalize key
82 switch (strtolower(str_replace(array('.', '-', '_'), '', $name))) {
83 case 'shortdescription':
84 $docBlock->setShortDescription($value);
85 case 'longdescription':
86 $docBlock->setLongDescription($value);
87 break;
88 case 'tags':
89 $docBlock->setTags($value);
90 break;
94 return $docBlock;
97 /**
98 * @param string $shortDescription
99 * @param string $longDescription
100 * @param array $tags
102 public function __construct($shortDescription = null, $longDescription = null, array $tags = array())
104 if ($shortDescription) {
105 $this->setShortDescription($shortDescription);
107 if ($longDescription) {
108 $this->setLongDescription($longDescription);
110 if (is_array($tags) && $tags) {
111 $this->setTags($tags);
116 * @param string $shortDescription
117 * @return DocBlockGenerator
119 public function setShortDescription($shortDescription)
121 $this->shortDescription = $shortDescription;
122 return $this;
126 * @return string
128 public function getShortDescription()
130 return $this->shortDescription;
134 * @param string $longDescription
135 * @return DocBlockGenerator
137 public function setLongDescription($longDescription)
139 $this->longDescription = $longDescription;
140 return $this;
144 * @return string
146 public function getLongDescription()
148 return $this->longDescription;
152 * @param array $tags
153 * @return DocBlockGenerator
155 public function setTags(array $tags)
157 foreach ($tags as $tag) {
158 $this->setTag($tag);
161 return $this;
165 * @param array|DocBlockTag $tag
166 * @throws Exception\InvalidArgumentException
167 * @return DocBlockGenerator
169 public function setTag($tag)
171 if (is_array($tag)) {
172 $tag = new DocBlockTag($tag);
173 } elseif (!$tag instanceof DocBlockTag) {
174 throw new Exception\InvalidArgumentException(sprintf(
175 '%s expects either an array of method options or an instance of %s\DocBlock\Tag',
176 __METHOD__,
177 __NAMESPACE__
181 $this->tags[] = $tag;
182 return $this;
186 * @return DocBlockTag[]
188 public function getTags()
190 return $this->tags;
194 * Set the word wrap
196 * @param bool $value
197 * @return \Zend\Code\Generator\DocBlockGenerator
199 public function setWordWrap($value)
201 $this->wordwrap = (bool) $value;
202 return $this;
206 * Get the word wrap
208 * @return bool
210 public function getWordWrap()
212 return $this->wordwrap;
216 * @return string
218 public function generate()
220 if (!$this->isSourceDirty()) {
221 return $this->docCommentize(trim($this->getSourceContent()));
224 $output = '';
225 if (null !== ($sd = $this->getShortDescription())) {
226 $output .= $sd . self::LINE_FEED . self::LINE_FEED;
228 if (null !== ($ld = $this->getLongDescription())) {
229 $output .= $ld . self::LINE_FEED . self::LINE_FEED;
232 foreach ($this->getTags() as $tag) {
233 $output .= $tag->generate() . self::LINE_FEED;
236 return $this->docCommentize(trim($output));
240 * @param string $content
241 * @return string
243 protected function docCommentize($content)
245 $indent = $this->getIndentation();
246 $output = $indent . '/**' . self::LINE_FEED;
247 $content = $this->getWordWrap() == true ? wordwrap($content, 80, self::LINE_FEED) : $content;
248 $lines = explode(self::LINE_FEED, $content);
249 foreach ($lines as $line) {
250 $output .= $indent . ' *';
251 if ($line) {
252 $output .= " $line";
254 $output .= self::LINE_FEED;
256 $output .= $indent . ' */' . self::LINE_FEED;
258 return $output;