-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArrayStyle.php
61 lines (49 loc) · 1.58 KB
/
ArrayStyle.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
declare(strict_types=1);
namespace Here\Styles;
use Here\Abstracts\VarPrinter;
use Here\Config;
use System\Console\Style\Style;
class ArrayStyle extends VarPrinter
{
/**
* @param Style $style
*/
public function __construct($style)
{
parent::__construct($style);
$this->max_line = (int) Config::get('print.var.max', 5);
}
public function render(): Style
{
/** @var array<int|string, mixed> */
$var = $this->var;
$this->style
->push('array:')->textBlue()
->push(count($var))->textBlue()
->push(' [')->textYellow()
;
foreach ($var as $key => $value) {
$this->current_line++;
if ($this->current_line > $this->max_line) {
$this->style->newLines()->repeat(' ', $this->tab_size * 2)->push('...')->textDim();
break;
}
$this->style->newLines();
$this->style->repeat(' ', $this->tab_size * 2);
$this->style->push($key)->textLightGreen();
$this->style->push(' => ')->textYellow();
$style = is_array($value)
? new ArrayStyle($this->style)
: new VarStyle($this->style);
$style->ref($value)
->tabSize($this->tab_size + 1)
->currentLine($this->current_line)
;
$this->style = $style->render();
}
$this->style->newLines()->repeat(' ', ($this->tab_size * 2) - 2);
$this->style->push(']')->textYellow();
return $this->style;
}
}