*prechod na novsiu verziu ZF
[sport-group.git] / library / Zend / CodeGenerator / Php / Docblock.php
blob3aad8c9f117ab2d454721fff6ecb1a76a13fddc0
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
15 * @category Zend
16 * @package Zend_CodeGenerator
17 * @subpackage PHP
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id: Docblock.php 16971 2009-07-22 18:05:45Z mikaelkael $
23 /**
24 * @see Zend_CodeGenerator_Php_Abstract
26 require_once 'Zend/CodeGenerator/Php/Abstract.php';
28 /**
29 * @see Zend_CodeGenerator_Php_Docblock_Tag
31 require_once 'Zend/CodeGenerator/Php/Docblock/Tag.php';
33 /**
34 * @category Zend
35 * @package Zend_CodeGenerator
36 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
37 * @license http://framework.zend.com/license/new-bsd New BSD License
39 class Zend_CodeGenerator_Php_Docblock extends Zend_CodeGenerator_Php_Abstract
41 /**
42 * @var string
44 protected $_shortDescription = null;
46 /**
47 * @var string
49 protected $_longDescription = null;
51 /**
52 * @var array
54 protected $_tags = array();
56 /**
57 * @var string
59 protected $_indentation = '';
61 /**
62 * fromReflection() - Build a docblock generator object from a reflection object
64 * @param Zend_Reflection_Docblock $reflectionDocblock
65 * @return Zend_CodeGenerator_Php_Docblock
67 public static function fromReflection(Zend_Reflection_Docblock $reflectionDocblock)
69 $docblock = new self();
71 $docblock->setSourceContent($reflectionDocblock->getContents());
72 $docblock->setSourceDirty(false);
74 $docblock->setShortDescription($reflectionDocblock->getShortDescription());
75 $docblock->setLongDescription($reflectionDocblock->getLongDescription());
77 foreach ($reflectionDocblock->getTags() as $tag) {
78 $docblock->setTag(Zend_CodeGenerator_Php_Docblock_Tag::fromReflection($tag));
81 return $docblock;
84 /**
85 * setShortDescription()
87 * @param string $shortDescription
88 * @return Zend_CodeGenerator_Php_Docblock
90 public function setShortDescription($shortDescription)
92 $this->_shortDescription = $shortDescription;
93 return $this;
96 /**
97 * getShortDescription()
99 * @return string
101 public function getShortDescription()
103 return $this->_shortDescription;
107 * setLongDescription()
109 * @param string $longDescription
110 * @return Zend_CodeGenerator_Php_Docblock
112 public function setLongDescription($longDescription)
114 $this->_longDescription = $longDescription;
115 return $this;
119 * getLongDescription()
121 * @return string
123 public function getLongDescription()
125 return $this->_longDescription;
129 * setTags()
131 * @param array $tags
132 * @return Zend_CodeGenerator_Php_Docblock
134 public function setTags(Array $tags)
136 foreach ($tags as $tag) {
137 $this->setTag($tag);
140 return $this;
144 * setTag()
146 * @param array|Zend_CodeGenerator_Php_Docblock_Tag $tag
147 * @return Zend_CodeGenerator_Php_Docblock
149 public function setTag($tag)
151 if (is_array($tag)) {
152 $tag = new Zend_CodeGenerator_Php_Docblock_Tag($tag);
153 } elseif (!$tag instanceof Zend_CodeGenerator_Php_Docblock_Tag) {
154 require_once 'Zend/CodeGenerator/Php/Exception.php';
155 throw new Zend_CodeGenerator_Php_Exception(
156 'setTag() expects either an array of method options or an '
157 . 'instance of Zend_CodeGenerator_Php_Docblock_Tag'
161 $this->_tags[] = $tag;
162 return $this;
166 * getTags
168 * @return array Array of Zend_CodeGenerator_Php_Docblock_Tag
170 public function getTags()
172 return $this->_tags;
176 * generate()
178 * @return string
180 public function generate()
182 if (!$this->isSourceDirty()) {
183 return $this->_docCommentize($this->getSourceContent());
186 $output = '';
187 if (null !== ($sd = $this->getShortDescription())) {
188 $output .= $sd . self::LINE_FEED . self::LINE_FEED;
190 if (null !== ($ld = $this->getLongDescription())) {
191 $output .= $ld . self::LINE_FEED . self::LINE_FEED;
194 foreach ($this->getTags() as $tag) {
195 $output .= $tag->generate() . self::LINE_FEED;
198 return $this->_docCommentize(trim($output));
202 * _docCommentize()
204 * @param string $content
205 * @return string
207 protected function _docCommentize($content)
209 $indent = $this->getIndentation();
210 $output = $indent . '/**' . self::LINE_FEED;
211 $content = wordwrap($content, 80, self::LINE_FEED);
212 $lines = explode(self::LINE_FEED, $content);
213 foreach ($lines as $line) {
214 $output .= $indent . ' * ' . $line . self::LINE_FEED;
216 $output .= $indent . ' */' . self::LINE_FEED;
217 return $output;