| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_CodeGenerator
- * @subpackage PHP
- * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- /**
- * @see Zend_CodeGenerator_Php_Abstract
- */
- require_once 'Zend/CodeGenerator/Php/Abstract.php';
- /**
- * @see Zend_CodeGenerator_Php_Docblock_Tag
- */
- require_once 'Zend/CodeGenerator/Php/Docblock/Tag.php';
- /**
- * @category Zend
- * @package Zend_CodeGenerator
- * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- class Zend_CodeGenerator_Php_Docblock extends Zend_CodeGenerator_Php_Abstract
- {
- /**
- * @var string
- */
- protected $_shortDescription = null;
- /**
- * @var string
- */
- protected $_longDescription = null;
- /**
- * @var array
- */
- protected $_tags = array();
- /**
- * @var string
- */
- protected $_indentation = '';
- /**
- * fromReflection() - Build a docblock generator object from a reflection object
- *
- * @param Zend_Reflection_Docblock $reflectionDocblock
- * @return Zend_CodeGenerator_Php_Docblock
- */
- public static function fromReflection(Zend_Reflection_Docblock $reflectionDocblock)
- {
- $docblock = new self();
- $docblock->setSourceContent($reflectionDocblock->getContents());
- $docblock->setSourceDirty(false);
- $docblock->setShortDescription($reflectionDocblock->getShortDescription());
- $docblock->setLongDescription($reflectionDocblock->getLongDescription());
- foreach ($reflectionDocblock->getTags() as $tag) {
- $docblock->setTag(Zend_CodeGenerator_Php_Docblock_Tag::fromReflection($tag));
- }
- return $docblock;
- }
- /**
- * setShortDescription()
- *
- * @param string $shortDescription
- * @return Zend_CodeGenerator_Php_Docblock
- */
- public function setShortDescription($shortDescription)
- {
- $this->_shortDescription = $shortDescription;
- return $this;
- }
- /**
- * getShortDescription()
- *
- * @return string
- */
- public function getShortDescription()
- {
- return $this->_shortDescription;
- }
- /**
- * setLongDescription()
- *
- * @param string $longDescription
- * @return Zend_CodeGenerator_Php_Docblock
- */
- public function setLongDescription($longDescription)
- {
- $this->_longDescription = $longDescription;
- return $this;
- }
- /**
- * getLongDescription()
- *
- * @return string
- */
- public function getLongDescription()
- {
- return $this->_longDescription;
- }
- /**
- * setTags()
- *
- * @param array $tags
- * @return Zend_CodeGenerator_Php_Docblock
- */
- public function setTags(Array $tags)
- {
- foreach ($tags as $tag) {
- $this->setTag($tag);
- }
- return $this;
- }
- /**
- * setTag()
- *
- * @param array|Zend_CodeGenerator_Php_Docblock_Tag $tag
- * @return Zend_CodeGenerator_Php_Docblock
- */
- public function setTag($tag)
- {
- if (is_array($tag)) {
- $tag = new Zend_CodeGenerator_Php_Docblock_Tag($tag);
- } elseif (!$tag instanceof Zend_CodeGenerator_Php_Docblock_Tag) {
- require_once 'Zend/CodeGenerator/Php/Exception.php';
- throw new Zend_CodeGenerator_Php_Exception(
- 'setTag() expects either an array of method options or an '
- . 'instance of Zend_CodeGenerator_Php_Docblock_Tag'
- );
- }
- $this->_tags[] = $tag;
- return $this;
- }
- /**
- * getTags
- *
- * @return array Array of Zend_CodeGenerator_Php_Docblock_Tag
- */
- public function getTags()
- {
- return $this->_tags;
- }
- /**
- * generate()
- *
- * @return string
- */
- public function generate()
- {
- if (!$this->isSourceDirty()) {
- return $this->_docCommentize($this->getSourceContent());
- }
- $output = '';
- if (null !== ($sd = $this->getShortDescription())) {
- $output .= $sd . self::LINE_FEED . self::LINE_FEED;
- }
- if (null !== ($ld = $this->getLongDescription())) {
- $output .= $ld . self::LINE_FEED . self::LINE_FEED;
- }
- foreach ($this->getTags() as $tag) {
- $output .= $tag->generate() . self::LINE_FEED;
- }
- return $this->_docCommentize(trim($output));
- }
- /**
- * _docCommentize()
- *
- * @param string $content
- * @return string
- */
- protected function _docCommentize($content)
- {
- $indent = $this->getIndentation();
- $output = $indent . '/**' . self::LINE_FEED;
- $content = wordwrap($content, 80, self::LINE_FEED);
- $lines = explode(self::LINE_FEED, $content);
- foreach ($lines as $line) {
- $output .= $indent . ' *';
- if ($line) {
- $output .= " $line";
- }
- $output .= self::LINE_FEED;
- }
- $output = rtrim($output, ' *' . self::LINE_FEED) . self::LINE_FEED;
- $output .= $indent . ' */' . self::LINE_FEED;
- return $output;
- }
- }
|