|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * phpDocumentor |
| 4 | + * |
| 5 | + * PHP Version 5.3 |
| 6 | + * |
| 7 | + * @author Mike van Riel <[email protected]> |
| 8 | + * @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com) |
| 9 | + * @license http://www.opensource.org/licenses/mit-license.php MIT |
| 10 | + * @link http://phpdoc.org |
| 11 | + */ |
| 12 | + |
| 13 | +namespace phpDocumentor\Reflection\DocBlock; |
| 14 | + |
| 15 | +use phpDocumentor\Reflection\DocBlock; |
| 16 | + |
| 17 | +/** |
| 18 | + * Serializes a DocBlock instance |
| 19 | + * |
| 20 | + * @author Barry vd. Heuvel <[email protected]> |
| 21 | + * @license http://www.opensource.org/licenses/mit-license.php MIT |
| 22 | + * @link http://phpdoc.org |
| 23 | + */ |
| 24 | +class Serializer |
| 25 | +{ |
| 26 | + |
| 27 | + /** @var string The string to indent the comment with */ |
| 28 | + protected $indentString; |
| 29 | + |
| 30 | + /** @var int The number of times $indentString is repeated */ |
| 31 | + protected $indent; |
| 32 | + |
| 33 | + /** @var bool Indent the first line */ |
| 34 | + protected $indentFirstLine; |
| 35 | + |
| 36 | + /** @var int The max length of a description line. */ |
| 37 | + protected $lineLength = null; |
| 38 | + |
| 39 | + /** |
| 40 | + * Create a Serializer instance. |
| 41 | + * |
| 42 | + * @param string $indentString |
| 43 | + * @param int $indent |
| 44 | + * @param bool $indentFirstLine |
| 45 | + * @internal param string $indentationString The indentation string. |
| 46 | + */ |
| 47 | + public function __construct($indentString = ' ', $indent = 4, $indentFirstLine = true) |
| 48 | + { |
| 49 | + $this->indentString = $indentString; |
| 50 | + $this->indent = $indent; |
| 51 | + $this->indentFirstLine = $indentFirstLine; |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * @param $indentationString |
| 56 | + * @return $this |
| 57 | + */ |
| 58 | + public function setIndentationString($indentationString) |
| 59 | + { |
| 60 | + $this->indentation = $indentationString; |
| 61 | + return $this; |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * @param $indent |
| 66 | + * @return $this |
| 67 | + */ |
| 68 | + public function setIndent($indent){ |
| 69 | + $this->indent = $indent; |
| 70 | + return $this; |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * @param $indentFirstLine |
| 75 | + * @return $this |
| 76 | + */ |
| 77 | + public function setIndentFirstLine($indentFirstLine){ |
| 78 | + $this->indentFirstLine = $indentFirstLine; |
| 79 | + return $this; |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * @param $lineLength |
| 84 | + * @return $this |
| 85 | + */ |
| 86 | + public function setLineLength($lineLength){ |
| 87 | + $this->lineLength = $lineLength; |
| 88 | + return $this; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Generate a DocBlock Comment |
| 93 | + * |
| 94 | + * @param DocBlock The DocBlock to serialize |
| 95 | + * @return string |
| 96 | + */ |
| 97 | + public function getDocComment($phpdoc){ |
| 98 | + |
| 99 | + $indent = ''; |
| 100 | + for($i=0;$i<$this->indent;$i++){ |
| 101 | + $indent .= $this->indentString; |
| 102 | + } |
| 103 | + $firstIndent = $this->indentFirstLine ? $indent : ''; |
| 104 | + |
| 105 | + $description = $phpdoc->getText(); |
| 106 | + if($this->lineLength){ |
| 107 | + $description = wordwrap($description, $this->lineLength); |
| 108 | + } |
| 109 | + $description = str_replace("\n", "\n$indent * ", $description); |
| 110 | + |
| 111 | + $comment = "$firstIndent/**\n$indent * $description\n$indent *\n"; |
| 112 | + |
| 113 | + /** @var Tag $tag */ |
| 114 | + foreach ($phpdoc->getTags() as $tag) { |
| 115 | + $comment .= $indent.' * @'. $tag->getName() . " " . $tag->getContent() . "\n"; |
| 116 | + } |
| 117 | + |
| 118 | + $comment .= $indent.' */'; |
| 119 | + |
| 120 | + return $comment; |
| 121 | + } |
| 122 | +} |
0 commit comments