1 | <?php |
||
51 | class Description |
||
52 | { |
||
53 | /** @var string */ |
||
54 | private $bodyTemplate; |
||
55 | |||
56 | /** @var Tag[] */ |
||
57 | private $tags; |
||
58 | |||
59 | /** |
||
60 | * Initializes a Description with its body (template) and a listing of the tags used in the body template. |
||
61 | * |
||
62 | * @param string $bodyTemplate |
||
63 | * @param Tag[] $tags |
||
64 | */ |
||
65 | 3 | public function __construct($bodyTemplate, array $tags = []) |
|
66 | { |
||
67 | 3 | Assert::string($bodyTemplate); |
|
68 | |||
69 | 2 | $this->bodyTemplate = $bodyTemplate; |
|
70 | 2 | $this->tags = $tags; |
|
71 | 2 | } |
|
72 | |||
73 | /** |
||
74 | * Renders this description as a string where the provided formatter will format the tags in the expected string |
||
75 | * format. |
||
76 | * |
||
77 | * @param Formatter|null $formatter |
||
78 | * |
||
79 | * @return string |
||
80 | */ |
||
81 | 2 | public function render(Formatter $formatter = null) |
|
82 | { |
||
83 | 2 | if ($formatter === null) { |
|
84 | 2 | $formatter = new PassthroughFormatter(); |
|
85 | } |
||
86 | |||
87 | 2 | $tags = []; |
|
88 | 2 | foreach ($this->tags as $tag) { |
|
89 | 2 | $tags[] = '{' . $formatter->format($tag) . '}'; |
|
90 | } |
||
91 | 2 | return vsprintf($this->bodyTemplate, $tags); |
|
92 | } |
||
93 | |||
94 | /** |
||
95 | * Returns a plain string representation of this description. |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | 1 | public function __toString() |
|
103 | } |
||
104 |