@@ -17,7 +17,7 @@ class MultiList extends MessageFormatter
1717 * Format and render multi list
1818 *
1919 * ```php
20- * [
20+ * $data = [
2121 * 'list1 title' => [
2222 * 'name' => 'value text',
2323 * 'name2' => 'value text 2',
@@ -27,11 +27,15 @@ class MultiList extends MessageFormatter
2727 * 'name2' => 'value text 2',
2828 * ],
2929 * ... ...
30- * ]
30+ * ];
31+ *
32+ * MultiList::show($data);
3133 * ```
3234 *
3335 * @param array $data
3436 * @param array $opts
37+ *
38+ * @psalm-param array{beforeWrite: callable, lastNewline: bool} $opts
3539 */
3640 public static function show (array $ data , array $ opts = []): void
3741 {
@@ -45,6 +49,12 @@ public static function show(array $data, array $opts = []): void
4549 unset($ opts ['lastNewline ' ]);
4650 }
4751
52+ $ beforeWrite = null ;
53+ if (isset ($ opts ['beforeWrite ' ])) {
54+ $ beforeWrite = $ opts ['beforeWrite ' ];
55+ unset($ opts ['beforeWrite ' ]);
56+ }
57+
4858 foreach ($ data as $ title => $ list ) {
4959 if ($ ignoreEmpty && !$ list ) {
5060 continue ;
@@ -53,6 +63,13 @@ public static function show(array $data, array $opts = []): void
5363 $ stringList [] = SingleList::show ($ list , (string )$ title , $ opts );
5464 }
5565
56- Console::write (implode ("\n" , $ stringList ), $ lastNewline );
66+ $ str = implode ("\n" , $ stringList );
67+
68+ // before write handler
69+ if ($ beforeWrite ) {
70+ $ str = $ beforeWrite ($ str );
71+ }
72+
73+ Console::write ($ str , $ lastNewline );
5774 }
5875}
0 commit comments