5 use phpline\internal\AnsiUtil
;
9 * Provide convenience methods for use on command line interface.
11 * @author Tim Duesterhus
12 * @copyright 2001-2019 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package WoltLabSuite\Core\Util
24 public static function generateTable(array $table)
27 foreach ($table as $row) {
29 foreach ($row as $column) {
30 if (!isset($columnSize[$i])) {
33 $columnSize[$i] = \
max($columnSize[$i], \
mb_strlen(AnsiUtil
::stripAnsi($column)));
40 foreach ($columnSize as $column) {
41 $result .= \
str_repeat('-', $column +
2) . '+';
45 foreach ($table as $row) {
48 foreach ($row as $column) {
49 $paddedString = StringUtil
::pad(
50 AnsiUtil
::stripAnsi($column),
53 (\
is_numeric($column) ? \STR_PAD_LEFT
: \STR_PAD_RIGHT
)
55 $result .= ' ' . \
str_replace(AnsiUtil
::stripAnsi($column), $column, $paddedString) . ' |';
59 $result .= \PHP_EOL
. "+";
60 foreach ($columnSize as $column) {
61 $result .= \
str_repeat('-', $column +
2) . '+';
75 public static function generateList(array $list)
78 foreach ($list as $row) {
79 $parts = \
mb_str_split($row, CLIWCF
::getTerminal()->getWidth() - 2);
80 $result .= '* ' . \
implode(\PHP_EOL
. ' ', $parts) . \PHP_EOL
;
89 * @param int $timestamp
92 public static function formatTime($timestamp)
94 $dateTimeObject = DateUtil
::getDateTimeByTimestamp($timestamp);
95 $date = DateUtil
::format($dateTimeObject, DateUtil
::DATE_FORMAT
);
96 $time = DateUtil
::format($dateTimeObject, DateUtil
::TIME_FORMAT
);
101 \
str_replace('%date%', $date, CLIWCF
::getLanguage()->get('wcf.date.dateTimeFormat'))
108 * @param int $timestamp
111 public static function formatDate($timestamp)
113 return DateUtil
::format(DateUtil
::getDateTimeByTimestamp($timestamp), DateUtil
::DATE_FORMAT
);
117 * Forbid creation of CLIUtil objects.
119 private function __construct()