diff --git a/build/kint.phar b/build/kint.phar index 898c5ffb1..5f7b89006 100644 Binary files a/build/kint.phar and b/build/kint.phar differ diff --git a/src/Kint.php b/src/Kint.php index e2145b062..701283c28 100644 --- a/src/Kint.php +++ b/src/Kint.php @@ -150,6 +150,7 @@ class Kint 'Kint\\Parser\\ClosurePlugin', 'Kint\\Parser\\ColorPlugin', 'Kint\\Parser\\DateTimePlugin', + 'Kint\\Parser\\EnumPlugin', 'Kint\\Parser\\FsPathPlugin', 'Kint\\Parser\\IteratorPlugin', 'Kint\\Parser\\JsonPlugin', diff --git a/src/Parser/ClassStaticsPlugin.php b/src/Parser/ClassStaticsPlugin.php index 89601af2f..7d2673f84 100644 --- a/src/Parser/ClassStaticsPlugin.php +++ b/src/Parser/ClassStaticsPlugin.php @@ -30,6 +30,7 @@ use Kint\Zval\Value; use ReflectionClass; use ReflectionProperty; +use UnitEnum; class ClassStaticsPlugin extends Plugin { @@ -56,6 +57,11 @@ public function parse(&$var, Value &$o, $trigger) $consts = []; foreach ($reflection->getConstants() as $name => $val) { + // Skip enum constants + if ($var instanceof UnitEnum && $val instanceof UnitEnum && $o->classname == \get_class($val)) { + continue; + } + $const = Value::blank($name, '\\'.$class.'::'.$name); $const->const = true; $const->depth = $o->depth + 1; diff --git a/src/Parser/EnumPlugin.php b/src/Parser/EnumPlugin.php new file mode 100644 index 000000000..3fe25f4eb --- /dev/null +++ b/src/Parser/EnumPlugin.php @@ -0,0 +1,86 @@ +contents = []; + + foreach ($var->cases() as $case) { + $base_obj = Value::blank($class.'::'.$case->name, '\\'.$class.'::'.$case->name); + $base_obj->depth = $o->depth + 1; + + if ($var instanceof BackedEnum) { + $c = $case->value; + $cases->contents[] = $this->parser->parse($c, $base_obj); + } else { + $cases->contents[] = $base_obj; + } + } + + self::$cache[$class] = $cases; + } + + $object = new EnumValue($var); + $object->transplant($o); + + $object->addRepresentation(self::$cache[$class], 0); + + $o = $object; + } +} diff --git a/src/Renderer/Text/EnumPlugin.php b/src/Renderer/Text/EnumPlugin.php new file mode 100644 index 000000000..efb5ba5d1 --- /dev/null +++ b/src/Renderer/Text/EnumPlugin.php @@ -0,0 +1,44 @@ +depth) { + $out .= $this->renderer->colorTitle($this->renderer->renderTitle($o)).PHP_EOL; + } + + $out .= $this->renderer->renderHeader($o).PHP_EOL; + + return $out; + } +} diff --git a/src/Renderer/TextRenderer.php b/src/Renderer/TextRenderer.php index 0cfba527c..3421e132b 100644 --- a/src/Renderer/TextRenderer.php +++ b/src/Renderer/TextRenderer.php @@ -42,6 +42,7 @@ class TextRenderer extends Renderer 'microtime' => 'Kint\\Renderer\\Text\\MicrotimePlugin', 'recursion' => 'Kint\\Renderer\\Text\\RecursionPlugin', 'trace' => 'Kint\\Renderer\\Text\\TracePlugin', + 'enum' => 'Kint\\Renderer\\Text\\EnumPlugin', ]; /** @@ -55,6 +56,7 @@ class TextRenderer extends Renderer 'Kint\\Parser\\MicrotimePlugin', 'Kint\\Parser\\StreamPlugin', 'Kint\\Parser\\TracePlugin', + 'Kint\\Parser\\EnumPlugin', ]; /** diff --git a/src/Zval/EnumValue.php b/src/Zval/EnumValue.php new file mode 100644 index 000000000..018eb68f0 --- /dev/null +++ b/src/Zval/EnumValue.php @@ -0,0 +1,62 @@ +enumval = $enumval; + } + + public function getValueShort() + { + if ($this->enumval instanceof BackedEnum) { + if (\is_string($this->enumval->value)) { + return '"'.$this->enumval->value.'"'; + } + if (\is_int($this->enumval->value)) { + return (string) $this->enumval->value; + } + } + } + + public function getType() + { + return $this->classname.'::'.$this->enumval->name; + } + + public function getSize() + { + } +}