Commit 817c4128 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Possibilité d'afficher un tableau de données en mode CLI

parent 0ddc98a6
Loading
Loading
Loading
Loading
+58 −0
Changes for admin/src/Console.php: 58 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -124,6 +124,64 @@ class Console implements \BddAdmin\Logger\LoggerInterface



    public function printArray(array $a)
    {
        $lengths = [];

        if (isset($a[0])) {
            $head = $a[0];
            foreach ($head as $k => $null) {
                $head[$k] = $k;
                if (($lengths[$k] ?? 0) < mb_strlen($k)) {
                    $lengths[$k] = mb_strlen($k);
                }
            }
        } else {
            $head = [];
        }

        foreach ($a as $l) {
            foreach ($l as $k => $v) {
                if (($lengths[$k] ?? 0) < mb_strlen($v)) {
                    $lengths[$k] = mb_strlen($v);
                }
            }
        }


        $this->print('|');
        foreach ($head as $k => $v) {
            $this->print(str_pad('', $lengths[$k], '-') . ' | ');
        }
        $this->println('');
        if ($head) {
            $this->print('|');
            foreach ($head as $k => $v) {
                $this->print(str_pad($v, $lengths[$k], ' ') . ' | ');
            }
            $this->println('');
            $this->print('|');
            foreach ($head as $k => $v) {
                $this->print(str_pad('', $lengths[$k], '-') . ' | ');
            }
            $this->println('');
        }
        foreach ($a as $n => $l) {
            $this->print('|');
            foreach ($l as $k => $v) {
                $this->print(str_pad($v, $lengths[$k], ' ') . ' | ');
            }
            $this->println('');
        }
        $this->print('|');
        foreach ($head as $k => $v) {
            $this->print(str_pad('', $lengths[$k], '-') . ' | ');
        }
        $this->println('');
    }



    public function msg($message, bool $rewrite = false)
    {
        if ($this->logCurrentLevel <= $this->logLevel) {