Skip to content

Commit

Permalink
🚧 wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed Jun 3, 2019
1 parent d833cfd commit 9363c4d
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 129 deletions.
4 changes: 2 additions & 2 deletions Chevereto-Chevere/src/Command/InspectCommand.php
Expand Up @@ -15,12 +15,12 @@

use const Chevereto\Chevere\App\PATH;
use Chevereto\Chevere\App;
use Chevereto\Chevere\VarDumper\VarDumper;
use Chevereto\Chevere\Load;
use Chevereto\Chevere\Message;
use Chevereto\Chevere\Path;
use Chevereto\Chevere\Command;
use Chevereto\Chevere\File;
use Chevereto\Chevere\Dump\Dump;
use Chevereto\Chevere\Utils\Str;
use Reflector;
use ReflectionMethod;
Expand Down Expand Up @@ -146,7 +146,7 @@ protected function processParametersArguments(): void
}
$res = $resource[$parameter->getName()] ?? null;
if (isset($res)) {
$aux .= ' '.Dump::wrap(Dump::_OPERATOR, '--description '.$res['description'].' --regex '.$res['regex']);
$aux .= ' '.VarDumper::wrap(VarDumper::_OPERATOR, '--description '.$res['description'].' --regex '.$res['regex']);
}
$this->arguments[] = "#$i $aux";
++$i;
Expand Down
4 changes: 2 additions & 2 deletions Chevereto-Chevere/src/Command/RunCommand.php
Expand Up @@ -13,7 +13,7 @@
namespace Chevereto\Chevere\Command;

use Chevereto\Chevere\App;
use Chevereto\Chevere\Dump\DumpPlain;
use Chevereto\Chevere\VarDumper\PlainVarDumper;
use Chevereto\Chevere\File;
use Chevereto\Chevere\Path;
use Chevereto\Chevere\Command;
Expand Down Expand Up @@ -65,7 +65,7 @@ public function callback(App $app): int
if (is_callable($callable)) {
// TODO: Must fix the argument typehint, maybe do combo with DI
$return = $callable(...$input->getOption('argument'));
$cli->getIo()->block(DumpPlain::out($return), 'RETURN', 'fg=black;bg=green', ' ', true);
$cli->getIo()->block(PlainVarDumper::out($return), 'RETURN', 'fg=black;bg=green', ' ', true);
} else {
$arguments = $input->getOption('argument');
// argument was declared as array
Expand Down
10 changes: 5 additions & 5 deletions Chevereto-Chevere/src/Dumper.php
Expand Up @@ -13,7 +13,7 @@

namespace Chevereto\Chevere;

use Chevereto\Chevere\Dump\Dump;
use Chevereto\Chevere\VarDumper\VarDumper;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
Expand Down Expand Up @@ -166,12 +166,12 @@ protected function handleClass(): void

protected function appendClass(string $class, string $type): void
{
$this->output .= Dump::wrap('_class', $class).$type;
$this->output .= VarDumper::wrap('_class', $class).$type;
}

protected function appendFunction(string $function): void
{
$this->output .= Dump::wrap('_function', $function.'()');
$this->output .= VarDumper::wrap('_function', $function.'()');
}

protected function handleFile(): void
Expand All @@ -183,7 +183,7 @@ protected function handleFile(): void

protected function appendFilepath(string $file, int $line): void
{
$this->output .= "\n".Dump::wrap('_file', Path::normalize($file).':'.$line);
$this->output .= "\n".VarDumper::wrap('_file', Path::normalize($file).':'.$line);
}

protected function handleArgs(): void
Expand All @@ -197,7 +197,7 @@ protected function handleArgs(): void

protected function appendArg(int $pos, $value): void
{
$this->output .= 'Arg#'.$pos.' '.Dump::out($value, 0)."\n\n";
$this->output .= 'Arg#'.$pos.' '.VarDumper::out($value, 0)."\n\n";
}

protected function handleProccessOutput(): void
Expand Down
8 changes: 4 additions & 4 deletions Chevereto-Chevere/src/ErrorHandler/Formatter.php
Expand Up @@ -18,8 +18,8 @@
use const Chevereto\Chevere\CORE_NS_HANDLE;
use Chevereto\Chevere\Console;
use Chevereto\Chevere\Path;
use Chevereto\Chevere\Dump\Dump;
use Chevereto\Chevere\Dump\DumpPlain;
use Chevereto\Chevere\VarDumper\VarDumper;
use Chevereto\Chevere\VarDumper\PlainVarDumper;
use Chevereto\Chevere\Utils\Str;
use Symfony\Component\Console\Output\OutputInterface;

Expand Down Expand Up @@ -259,8 +259,8 @@ protected function processContentGlobals()
$k = '_'.$v;
$v = isset($GLOBALS[$k]) ? $GLOBALS[$k] : null;
if ($v) {
$this->setRichContentSection($k, ['$'.$k, $this->wrapStringHr('<pre>'.Dump::out($v).'</pre>')]);
$this->setPlainContentSection($k, ['$'.$k, strip_tags($this->wrapStringHr(DumpPlain::out($v)))]);
$this->setRichContentSection($k, ['$'.$k, $this->wrapStringHr('<pre>'.VarDumper::out($v).'</pre>')]);
$this->setPlainContentSection($k, ['$'.$k, strip_tags($this->wrapStringHr(PlainVarDumper::out($v)))]);
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions Chevereto-Chevere/src/ErrorHandler/Stack.php
Expand Up @@ -13,7 +13,7 @@

namespace Chevereto\Chevere\ErrorHandler;

use Chevereto\Chevere\Dump\Dump;
use Chevereto\Chevere\VarDumper\VarDumper;

/**
* Handles the ErrorHandler Exception stack trace.
Expand Down Expand Up @@ -107,14 +107,14 @@ protected function setRichTable(TraceEntry $entry): void
array_pop($this->richTable);
// Dump types map
foreach ([
'%f%' => Dump::_FILE,
'%l%' => Dump::_FILE,
'%fl%' => Dump::_FILE,
'%c%' => Dump::_CLASS,
'%t%' => Dump::_OPERATOR,
'%m%' => Dump::_FUNCTION,
'%f%' => VarDumper::_FILE,
'%l%' => VarDumper::_FILE,
'%fl%' => VarDumper::_FILE,
'%c%' => VarDumper::_CLASS,
'%t%' => VarDumper::_OPERATOR,
'%m%' => VarDumper::_FUNCTION,
] as $k => $v) {
$this->richTable[$k] = isset($this->plainTable[$k]) ? Dump::wrap($v, $this->plainTable[$k]) : null;
$this->richTable[$k] = isset($this->plainTable[$k]) ? VarDumper::wrap($v, $this->plainTable[$k]) : null;
}
$this->richTable['%a%'] = $entry->getRichArgs();
}
Expand Down
14 changes: 7 additions & 7 deletions Chevereto-Chevere/src/ErrorHandler/TraceEntry.php
Expand Up @@ -17,8 +17,8 @@
use Chevereto\Chevere\Core;
use Chevereto\Chevere\Path;
use Chevereto\Chevere\Utils\Str;
use Chevereto\Chevere\Dump\Dump;
use Chevereto\Chevere\Dump\DumpPlain;
use Chevereto\Chevere\VarDumper\VarDumper;
use Chevereto\Chevere\VarDumper\PlainVarDumper;

/**
* TraceEntry prepares the Exception trace for being used with our Stack.
Expand Down Expand Up @@ -91,8 +91,8 @@ protected function setFrameArguments()
{
foreach ($this->entry['args'] as $k => $v) {
$aux = 'Arg#'.($k + 1).' ';
$plainArgs[] = $aux.DumpPlain::out($v, null, [App::class]);
$richArgs[] = $aux.Dump::out($v, null, [App::class]);
$richArgs[] = $aux.VarDumper::out($v, null, [App::class]);
$plainArgs[] = $aux.PlainVarDumper::out($v, null, [App::class]);
}
if (isset($plainArgs)) {
$this->plainArgs = "\n".implode("\n", $plainArgs);
Expand All @@ -102,16 +102,16 @@ protected function setFrameArguments()

protected function handleProcessAnonClass()
{
if (isset($this->entry['class']) && Str::startsWith(Dump::ANON_CLASS, $this->entry['class'])) {
if (isset($this->entry['class']) && Str::startsWith(VarDumper::ANON_CLASS, $this->entry['class'])) {
$this->processAnonClass();
}
}

protected function processAnonClass()
{
$entryFile = Str::replaceFirst(Dump::ANON_CLASS, null, $this->entry['class']);
$entryFile = Str::replaceFirst(VarDumper::ANON_CLASS, null, $this->entry['class']);
$this->entry['file'] = substr($entryFile, 0, strpos($entryFile, '.php') + 4);
$this->entry['class'] = Dump::ANON_CLASS;
$this->entry['class'] = VarDumper::ANON_CLASS;
$this->entry['line'] = null;
}

Expand Down
21 changes: 0 additions & 21 deletions Chevereto-Chevere/src/Interfaces/DumpInterface.php
Expand Up @@ -14,8 +14,6 @@

interface DumpInterface
{
public function __toString(): string;

/**
* Dumps information about a variable.
*
Expand All @@ -26,23 +24,4 @@ public function __toString(): string;
* @return string parsed dump string
*/
public static function out($var, int $indent = null, array $dontDump = [], int $depth = 0): string;

/**
* Get color for palette key.
*
* @param string $key color palette key
*
* @return string color
*/
public static function getColorForKey(string $key): ?string;

/**
* Wrap dump data into HTML.
*
* @param string $key Type or algo key (see constants)
* @param mixed $dump dump data
*
* @return string wrapped dump data
*/
public static function wrap(string $key, $dump): ?string;
}
51 changes: 51 additions & 0 deletions Chevereto-Chevere/src/VarDumper/Pallete.php
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

/*
* This file is part of Chevere.
*
* (c) Rodolfo Berrios <rodolfo@chevereto.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Chevereto\Chevere\VarDumper;

abstract class Pallete
{
/**
* Color palette used in HTML.
*/
const PALETTE = [
VarDumper::TYPE_STRING => '#e67e22', // orange
VarDumper::TYPE_FLOAT => '#f1c40f', // yellow
VarDumper::TYPE_INTEGER => '#f1c40f', // yellow
VarDumper::TYPE_BOOLEAN => '#9b59b6', // purple
VarDumper::TYPE_NULL => '#7f8c8d', // grey
VarDumper::TYPE_OBJECT => '#e74c3c', // red
VarDumper::TYPE_ARRAY => '#2ecc71', // green
VarDumper::_FILE => null,
VarDumper::_CLASS => '#3498db', // blue
VarDumper::_OPERATOR => '#7f8c8d', // grey
VarDumper::_FUNCTION => '#9b59b6', // purple
];

/**
* Color palette used in CLI.
*/
const CONSOLE = [
VarDumper::TYPE_STRING => 'color_136', // yellow
VarDumper::TYPE_FLOAT => 'color_136', // yellow
VarDumper::TYPE_INTEGER => 'color_136', // yellow
VarDumper::TYPE_BOOLEAN => 'color_127', // purple
VarDumper::TYPE_NULL => 'color_245', // grey
VarDumper::TYPE_OBJECT => 'color_167', // red
VarDumper::TYPE_ARRAY => 'color_41', // green
VarDumper::_FILE => null,
VarDumper::_CLASS => 'color_147', // blue
VarDumper::_OPERATOR => 'color_245', // grey
VarDumper::_FUNCTION => 'color_127', // purple
];
}
Expand Up @@ -11,15 +11,16 @@
* file that was distributed with this source code.
*/

namespace Chevereto\Chevere\Dump;
namespace Chevereto\Chevere\VarDumper;

class DumpPlain extends Dump
/**
* Exactly the same as Dump but stripping any format decorators.
*/
abstract class PlainVarDumper extends VarDumper
{
public static function out($expression, int $indent = null, array $dontDump = [], $depth = 0): string
{
$return = parent::out(...func_get_args());

return strip_tags($return);
return strip_tags(parent::out(...func_get_args()));
}

public static function wrap(string $key, $dump = null): string
Expand Down

0 comments on commit 9363c4d

Please sign in to comment.