Skip to content

Commit

Permalink
array version 2
Browse files Browse the repository at this point in the history
  • Loading branch information
nineyang committed Sep 9, 2017
1 parent fb8404a commit 15db7ac
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion example.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
//\dd\Dump::dump('helloworld');

//array
\dd\Dump::dump(['hello', 'world' => 'nine']);
\dd\Dump::dump(['hello', 'world' => ['aa' , 'bb' => ['cc' , 'dd']]]);
9 changes: 5 additions & 4 deletions src/conf/css.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
'.black-color' => "color:#333333",
'.gray-color' => "color:#ccc",
'.font-12' => 'font-size:12px',
'.depth-1' => 'margin-left:10px',
'.depth-2' => 'margin-left:20px',
'.depth-3' => 'margin-left:30px',
'.depth-4' => 'margin-left:40px',
'.depth-0' => 'margin-left:0px',
'.depth-1' => 'margin-left:1rem',
'.depth-2' => 'margin-left:2rem',
'.depth-3' => 'margin-left:3rem',
'.depth-4' => 'margin-left:4rem',
'.nine-div' => 'margin-left:10px;margin-top:10px;'
];
4 changes: 3 additions & 1 deletion src/render/AbstractDump.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ protected function init()
*/
public function returnValue($value = '', $type = 'span', $classArr = ['nine-span'], $params = ['withQuota' => true])
{
if (is_array($value)) {
return implode('', $value);
}
return ($this->returnDecorator($type, $classArr, $value, $params))->value;
}

Expand Down Expand Up @@ -131,7 +134,6 @@ public function display($value = '', $type = null, $classArr = [], $params = [])
}

$divDecorator->display();
die();
}

/**
Expand Down
33 changes: 18 additions & 15 deletions src/render/DumpArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,37 @@ class DumpArray extends AbstractDump
public function __construct($value)
{
parent::__construct($value);
$this->_stack = [];
}

public function render()
{
$this->parseArr($this->value);
$this->display($this->_stack);
$this->display($this->parseArr($this->value));
}

protected function parseArr(array $arr, $depth = 1)
{
// 首先导入array
$this->_stack[] = $this->returnValue("array:" . count($arr), 'span', ['nine-span'], ['withQuota' => false]);
$returnArr = [];
$returnArr[] = $this->returnValue("array:" . count($arr), 'span', ['nine-span'], ['withQuota' => false]);
// 导入一个[
$this->_stack[] = $this->_leftBracket;
$returnArr[] = $this->_leftBracket;
// 导入一个▶
$this->_stack[] = $this->_triangle;

$returnArr[] = $this->_triangle;
$pushValue = "";
foreach ($arr as $key => $value) {
if (is_array($value)) self::parseArr($value, ++$depth);
// 拼接key和value
// 拼接key和value
$key = $this->returnValue($key, 'span', ['nine-span'], ['withQuota' => is_int($key) ? false : true]);
$value = $this->returnValue($value);
$pushValue = $key . $this->_needle . $value;
// 外层包裹一个p
array_push($this->_stack, $this->returnValue($pushValue, 'p' , ["depth-$depth"]));
if (is_array($value)) {
$value = $this->returnValue(self::parseArr($value, $depth + 1));
} else {
$value = $this->returnValue($value);
}
$pushValue .= $key . $this->_needle . $value . "</br>";
}
// 导入一个]
$this->_stack[] = $this->_rightBracket;
// 外层包裹一个p
$returnArr[] = $this->returnValue($pushValue, 'p', ["depth-" . $depth]);
$devideSpan = $this->returnValue("", 'span', ["depth-" . ($depth - 1)], ['withQuota' => false]);
$returnArr[] = $devideSpan . $this->_rightBracket;
return $returnArr;
}
}

0 comments on commit 15db7ac

Please sign in to comment.