Skip to content

Commit

Permalink
Merge pull request #2 from Ghostff/HTML_Esc
Browse files Browse the repository at this point in the history
HTML characters escape
  • Loading branch information
Ghostff authored Jan 2, 2018
2 parents 79545b5 + 4d3b607 commit 500777d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Pretty Data Dump
A pretty version of php [var_dump](http://php.net/manual/en/function.var-dump.php). This class displays structured information about one or more expressions that includes its type and value.

_Check out [Dump5](https://github.com/Ghostff/Dump5) for PHP 5+_

# Installation
You can download the Latest [release version ](https://github.com/Ghostff/pretty_data_dump/releases/) as a standalone, alternatively you can use [Composer](https://getcomposer.org/)
```json
Expand Down
43 changes: 23 additions & 20 deletions src/Dump.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ private function output(string $data): void
break;
}
}
$file = $bt['file'] . '(line:' . $bt['line'] . ')';
$file = "{$bt['file']}(line:{$bt['line']})";
if (! $this->isCli)
{
echo '<code><small>' . $file . '</small><br />' . $data . '</code>';
Expand Down Expand Up @@ -333,7 +333,7 @@ private function color($value, string $name): ?string
*/
private function counter(int $size, int $type = 0): string
{
return $this->color('(' . ($type ? 'length' : 'size') . '=' . $size . ')', 'size');
return $this->color('(' . ($type ? 'length' : 'size') . "={$size})", 'size');
}

/**
Expand All @@ -345,7 +345,7 @@ private function counter(int $size, int $type = 0): string
*/
private function type(string $type, string $before = ' '): string
{
return $before . $this->color($type, 'type');
return "{$before}{$this->color($type, 'type')}";
}

/**
Expand Down Expand Up @@ -391,11 +391,11 @@ private function arrayIndex(string $key, bool $parent = false): string
{
if (!$parent)
{
return $this->color("'$key'", 'multi_array_key') . ' ' . $this->color('=', 'multi_array_arrow') . ' ';
return $this->color("'$key'", 'multi_array_key') . " {$this->color('=', 'multi_array_arrow')} ";
}
else
{
return $this->color("'$key'", 'single_array_key') . ' ' . $this->color('=>', 'single_array_arrow') . ' ';
return $this->color("'$key'", 'single_array_key') . " {$this->color('=>', 'single_array_arrow')} ";
}
}

Expand Down Expand Up @@ -473,24 +473,20 @@ private function formatObject($object)
{
if ($prop->isPrivate())
{
$tmp .= $this->breakLine() . $this->indent($this->indent) . $this->color('private', 'property_visibility')
. $this->pad(2) . ' ' . $this->color(':', 'property_arrow') . ' ';
$tmp .= "{$this->breakLine()}{$this->indent($this->indent)}{$this->color('private', 'property_visibility')}{$this->pad(2)} {$this->color(':', 'property_arrow')} ";
}
elseif ($prop->isProtected())
{
$tmp .= $this->breakLine() . $this->indent($this->indent) . $this->color('protected', 'property_visibility') . ' '
. $this->color(':', 'property_arrow') . ' ';
$tmp .= "{$this->breakLine()}{$this->indent($this->indent)}{$this->color('protected', 'property_visibility')} {$this->color(':', 'property_arrow')} ";
}
elseif ($prop->isPublic())
{
$tmp .= $this->breakLine() . $this->indent($this->indent) . $this->color('public', 'property_visibility')
. $this->pad(3) . ' ' . $this->color(':', 'property_arrow') . ' ';
$tmp .= "{$this->breakLine()}{$this->indent($this->indent)}{$this->color('public', 'property_visibility')}{$this->pad(3)} {$this->color(':', 'property_arrow')} ";
}

$prop->setAccessible(true);
$tmp .= $this->color('\'' . $prop->getName() . '\'', 'property_name') . ' '
. $this->color('=>', 'property_arrow') . ' '
. $this->evaluate([$prop->getValue($object)], true, true);
$tmp .= $this->color("'{$prop->getName()}'", 'property_name')
. " {$this->color('=>', 'property_arrow')} {$this->evaluate(array($prop->getValue($object)), true, true)}";
}

if ($tmp != '')
Expand All @@ -503,7 +499,7 @@ private function formatObject($object)

$tmp = str_replace([':name', ':id', ':content'], [
$reflection->getName(),
$this->color('#' . $this->refcount($object), 'size'),
$this->color("#{$this->refcount($object)}", 'size'),
$tmp
], $this->color('object (:name) [:id] [:content]', 'object'));

Expand All @@ -528,19 +524,26 @@ private function evaluate(array $args, bool $called = false, bool $from_obj = fa
switch ($type)
{
case 'string':
$tmp .= $this->color('\'' . $each . '\'', $type) . ' ' . $this->counter(strlen($each), 1) . $this->type($type);

if (! $this->isCli)
{
$each = nl2br(str_replace(array('<', ' '), array('&lt;', '&nbsp;'), $each));
}

$tmp .= $this->color("'{$each}'", $type)
. "{$this->counter(strlen($each), 1)}{$this->type($type)}";
break;
case 'integer':
$tmp .= $this->color((string) $each, $type) . $this->type($type);
$tmp .= "{$this->color((string) $each, $type)}{$this->type($type)}";
break;
case 'double':
$tmp .= $this->color((string) $each, $type) . $this->type($type);
$tmp .= "{$this->color((string) $each, $type)}{$this->type($type)}";
break;
case 'NULL':
$tmp .= $this->color('null', 'null') . $this->type($type);
$tmp .= "{$this->color('null', 'null')}{$this->type($type)}";
break;
case 'boolean':
$tmp .= $this->color($each ? 'true' : 'false', $type) . $this->type($type);
$tmp .= "{$this->color($each ? 'true' : 'false', $type)}{$this->type($type)}";
break;
case 'array':
$tmp .= str_replace([':size', ':content'], [
Expand Down

0 comments on commit 500777d

Please sign in to comment.