@@ -32,25 +32,31 @@ class Serializer
3232 /** @var int|null The max length of a line. */
3333 protected $ lineLength = null ;
3434
35+ /** @var DocBlock\Tags\Formatter A custom tag formatter. */
36+ protected $ tagFormatter = null ;
37+
3538 /**
3639 * Create a Serializer instance.
3740 *
3841 * @param int $indent The number of times the indent string is repeated.
3942 * @param string $indentString The string to indent the comment with.
4043 * @param bool $indentFirstLine Whether to indent the first line.
4144 * @param int|null $lineLength The max length of a line or NULL to disable line wrapping.
45+ * @param DocBlock\Tags\Formatter $tagFormatter A custom tag formatter, defaults to PassthroughFormatter.
4246 */
43- public function __construct ($ indent = 0 , $ indentString = ' ' , $ indentFirstLine = true , $ lineLength = null )
47+ public function __construct ($ indent = 0 , $ indentString = ' ' , $ indentFirstLine = true , $ lineLength = null , $ tagFormatter = null )
4448 {
4549 Assert::integer ($ indent );
4650 Assert::string ($ indentString );
4751 Assert::boolean ($ indentFirstLine );
4852 Assert::nullOrInteger ($ lineLength );
53+ Assert::nullOrIsInstanceOf ($ tagFormatter , 'phpDocumentor\Reflection\DocBlock\Tags\Formatter ' );
4954
5055 $ this ->indent = $ indent ;
5156 $ this ->indentString = $ indentString ;
5257 $ this ->isFirstLineIndented = $ indentFirstLine ;
5358 $ this ->lineLength = $ lineLength ;
59+ $ this ->tagFormatter = $ tagFormatter ?: new DocBlock \Tags \Formatter \PassthroughFormatter ();
5460 }
5561
5662 /**
@@ -128,8 +134,7 @@ private function getSummaryAndDescriptionTextBlock(DocBlock $docblock, $wrapLeng
128134 private function addTagBlock (DocBlock $ docblock , $ wrapLength , $ indent , $ comment )
129135 {
130136 foreach ($ docblock ->getTags () as $ tag ) {
131- $ formatter = new DocBlock \Tags \Formatter \PassthroughFormatter ();
132- $ tagText = $ formatter ->format ($ tag );
137+ $ tagText = $ this ->tagFormatter ->format ($ tag );
133138 if ($ wrapLength !== null ) {
134139 $ tagText = wordwrap ($ tagText , $ wrapLength );
135140 }
0 commit comments