@@ -32,25 +32,31 @@ class Serializer
32
32
/** @var int|null The max length of a line. */
33
33
protected $ lineLength = null ;
34
34
35
+ /** @var DocBlock\Tags\Formatter A custom tag formatter. */
36
+ protected $ tagFormatter = null ;
37
+
35
38
/**
36
39
* Create a Serializer instance.
37
40
*
38
41
* @param int $indent The number of times the indent string is repeated.
39
42
* @param string $indentString The string to indent the comment with.
40
43
* @param bool $indentFirstLine Whether to indent the first line.
41
44
* @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.
42
46
*/
43
- public function __construct ($ indent = 0 , $ indentString = ' ' , $ indentFirstLine = true , $ lineLength = null )
47
+ public function __construct ($ indent = 0 , $ indentString = ' ' , $ indentFirstLine = true , $ lineLength = null , $ tagFormatter = null )
44
48
{
45
49
Assert::integer ($ indent );
46
50
Assert::string ($ indentString );
47
51
Assert::boolean ($ indentFirstLine );
48
52
Assert::nullOrInteger ($ lineLength );
53
+ Assert::nullOrIsInstanceOf ($ tagFormatter , 'phpDocumentor\Reflection\DocBlock\Tags\Formatter ' );
49
54
50
55
$ this ->indent = $ indent ;
51
56
$ this ->indentString = $ indentString ;
52
57
$ this ->isFirstLineIndented = $ indentFirstLine ;
53
58
$ this ->lineLength = $ lineLength ;
59
+ $ this ->tagFormatter = $ tagFormatter ?: new DocBlock \Tags \Formatter \PassthroughFormatter ();
54
60
}
55
61
56
62
/**
@@ -128,8 +134,7 @@ private function getSummaryAndDescriptionTextBlock(DocBlock $docblock, $wrapLeng
128
134
private function addTagBlock (DocBlock $ docblock , $ wrapLength , $ indent , $ comment )
129
135
{
130
136
foreach ($ docblock ->getTags () as $ tag ) {
131
- $ formatter = new DocBlock \Tags \Formatter \PassthroughFormatter ();
132
- $ tagText = $ formatter ->format ($ tag );
137
+ $ tagText = $ this ->tagFormatter ->format ($ tag );
133
138
if ($ wrapLength !== null ) {
134
139
$ tagText = wordwrap ($ tagText , $ wrapLength );
135
140
}
0 commit comments