Skip to content
Permalink
Browse files

wip

  • Loading branch information
rodolfoberrios committed Feb 12, 2020
1 parent 8832913 commit e04cd6f511ef2eab303a31fba2976a6aa70cb79d
Showing with 563 additions and 243 deletions.
  1. +0 −14 .vscode/virtual-folders.folders
  2. +2 −2 components/Instances/BootstrapInstance.php
  3. +5 −8 components/Instances/RuntimeInstance.php
  4. +7 −9 components/Instances/{ScreenContainerInstance.php → WritersInstance.php}
  5. +5 −3 components/VarDump/Interfaces/OutputterInterface.php
  6. +2 −2 components/VarDump/Interfaces/ProcessorInterface.php
  7. +1 −1 components/VarDump/Interfaces/VarDumperInterface.php
  8. +1 −1 components/VarDump/Interfaces/VarFormatInterface.php
  9. +7 −5 components/VarDump/Outputters/ConsoleOutputter.php
  10. +11 −9 components/VarDump/Outputters/HtmlOutputter.php
  11. +49 −25 components/VarDump/Outputters/PlainOutputter.php
  12. +5 −6 components/VarDump/Processors/AbstractProcessor.php
  13. +21 −5 components/VarDump/Processors/ArrayProcessor.php
  14. +8 −2 components/VarDump/Processors/BooleanProcessor.php
  15. +12 −2 components/VarDump/Processors/FloatProcessor.php
  16. +12 −2 components/VarDump/Processors/IntegerProcessor.php
  17. +7 −2 components/VarDump/Processors/NullProcessor.php
  18. +41 −26 components/VarDump/Processors/ObjectProcessor.php
  19. +6 −4 components/VarDump/Processors/ResourceProcessor.php
  20. +12 −2 components/VarDump/Processors/StringProcessor.php
  21. +1 −1 components/VarDump/Tests/Outputters/ConsoleOutputterTest.php
  22. +1 −1 components/VarDump/Tests/Outputters/HtmlOutputterTest.php
  23. +3 −3 components/VarDump/Tests/Outputters/PlainOutputterTest.php
  24. +61 −7 components/VarDump/VarDump.php
  25. +2 −17 components/VarDump/VarDumper.php
  26. +36 −42 components/VarDump/VarFormat.php
  27. +3 −4 resources/functions/screens.php → components/Writers/Interfaces/StreamWriterInterface.php
  28. +18 −0 components/Writers/Interfaces/WritersInterface.php
  29. +27 −0 components/Writers/SilentStreamWriter.php
  30. +32 −0 components/Writers/StreamWriter.php
  31. +40 −0 components/Writers/Test/WritersTest.php
  32. +92 −0 components/Writers/Writers.php
  33. +1 −1 composer.json
  34. +3 −22 phpunit.php
  35. +9 −15 resources/functions/dump.php
  36. +20 −0 resources/functions/writers.php
  37. 0 {components → trash}/Screen/Container.php
  38. 0 {components → trash}/Screen/Formatters/ConsoleFormatter.php
  39. 0 {components → trash}/Screen/Formatters/DebugFormatter.php
  40. 0 {components → trash}/Screen/Formatters/RuntimeFormatter.php
  41. 0 {components → trash}/Screen/Formatters/SilentFormatter.php
  42. 0 {components → trash}/Screen/Interfaces/ContainerInterface.php
  43. 0 {components → trash}/Screen/Interfaces/FormatterInterface.php
  44. 0 {components → trash}/Screen/Interfaces/ScreenContainerInterface.php
  45. 0 {components → trash}/Screen/Interfaces/ScreenInterface.php
  46. 0 {components → trash}/Screen/Screen.php
  47. 0 {components → trash}/Screen/ScreenContainer.php
  48. 0 {components → trash}/Screen/SilentScreen.php
  49. 0 {components → trash}/Screen/Tests/ScreenTest.php
  50. 0 {components → trash}/Screen/Traits/ScreenTrait.php

This file was deleted.

@@ -13,11 +13,11 @@

namespace Chevere\Components\Instances;

use Chevere\Components\Bootstrap\Interfaces\BootstrapInterface;
use LogicException;
use Chevere\Components\Bootstrap\Interfaces\BootstrapInterface;

/**
* A container for the application bootstrap.
* A container for the bootstrap.
*/
final class BootstrapInstance
{
@@ -13,31 +13,28 @@

namespace Chevere\Components\Instances;

use Chevere\Components\Runtime\Interfaces\RuntimeInterface;
use Chevere\Components\Runtime\Runtime;
use LogicException;

/**
* A container for the application Runtime.
* A container for the Runtime.
*/
final class RuntimeInstance
{
private static Runtime $instance;
private static RuntimeInterface $instance;

public function __construct(Runtime $runtime)
public function __construct(RuntimeInterface $runtime)
{
self::$instance = $runtime;
}

public static function type(): string
{
return Runtime::class;
}

public static function get(): Runtime
{
if (!isset(self::$instance)) {
throw new LogicException('No runtime instance present');
}

return self::$instance;
}
}
@@ -17,23 +17,21 @@
use Chevere\Components\Screen\Container;
use Chevere\Components\Screen\Interfaces\ScreenContainerInterface;
use Chevere\Components\Screen\ScreenContainer;
use Chevere\Components\Writers\Interfaces\WritersInterface;

/**
* A container for the application screens.
*/
final class ScreenContainerInstance
final class WritersInstance
{
private static ScreenContainerInterface $instance;
private static WritersInterface $instance;

public function __construct(ScreenContainerInterface $screens)
public function __construct(WritersInterface $writers)
{
self::$instance = $screens;
self::$instance = $writers;
}

public static function get(): ScreenContainerInterface
public static function get(): WritersInterface
{
if (!isset(self::$instance)) {
throw new LogicException('No screen container instance present');
throw new LogicException('No writers instance present');
}

return self::$instance;
@@ -13,13 +13,15 @@

namespace Chevere\Components\VarDump\Interfaces;

use Chevere\Components\Writers\Interfaces\StreamWriterInterface;

interface OutputterInterface
{
public function __construct(VarDumperInterface $dumper);
public function __construct(VarDumperInterface $dumper, StreamWriterInterface $streamWriter);

public function varDumper(): VarDumperInterface;

public function prepare(string $output): string;
public function prepare(): void;

public function toString(): string;
public function emit(): void;
}
@@ -15,7 +15,7 @@

interface ProcessorInterface
{
const MAX_DEPTH = 5;
const MAX_DEPTH = 4;

/**
* Provides access to the instance info.
@@ -27,7 +27,7 @@ public function info(): string;
* Provides access to the instance value.
* The dumped variable value.
*/
public function value(): string;
// public function value(): string;

/**
* Provides access to the instance type.
@@ -25,7 +25,7 @@ interface VarDumperInterface

const OFFSET = 1;

public function __construct(FormatterInterface $formatter, ...$vars);
public function __construct(array $debugBacktrace, FormatterInterface $formatter, ...$vars);

public function formatter(): FormatterInterface;

@@ -113,5 +113,5 @@ public function withProcess(): VarFormatInterface;
/**
* Provides access to the instance $output.
*/
public function toString(): string;
// public function toString(): string;
}
@@ -22,7 +22,7 @@ final class ConsoleOutputter extends PlainOutputter

private string $outputHr;

public function prepare(string $output): string
public function prepare(): void
{
$this->consoleOutput = new ConsoleOutput();
$this->outputHr = (new ConsoleColor)->apply('blue', self::OUTPUT_HR);
@@ -35,12 +35,14 @@ public function prepare(string $output): string
if ($bt['function'] ?? null) {
$maker .= $bt['function'] . '()';
}

return $output .= "\n" . (new ConsoleColor)->apply(['bold', 'red'], $maker) . "\n" . $this->outputHr . "\n";
$this->streamWriter->write(
"\n" . (new ConsoleColor)->apply(['bold', 'red'], $maker)
. "\n" . $this->outputHr . "\n"
);
}

public function callback(string $output): string
public function callback(): void
{
return $output . "\n" . $this->outputHr;
$this->streamWriter->write("\n" . $this->outputHr);
}
}
@@ -19,23 +19,25 @@ final class HtmlOutputter extends PlainOutputter
{
private bool $hasHeader = false;

public function prepare(string $output): string
public function prepare(): void
{
if (headers_sent() === false || headers_list() === []) {
$this->hasHeader = true;
$output .= '<html style="background: ' . VarDumperInterface::BACKGROUND_SHADE . ';"><head></head><body>';
$this->streamWriter->write(
'<html style="background: '
. VarDumperInterface::BACKGROUND_SHADE
. ';"><head></head><body>'
);
}
$output .= '<pre style="' . VarDumperInterface::STYLE . '">';

return $output;
$this->streamWriter->write(
'<pre style="' . VarDumperInterface::STYLE . '">'
);
}

public function callback(string $output): string
public function callback(): void
{
if ($this->hasHeader) {
$output .= '</body></html>';
$this->streamWriter->write('</body></html>');
}

return $output;
}
}
@@ -17,62 +17,82 @@
use Chevere\Components\VarDump\Interfaces\VarDumperInterface;
use Chevere\Components\VarDump\Interfaces\OutputterInterface;
use Chevere\Components\VarDump\VarFormat;
use Chevere\Components\Writers\Interfaces\StreamWriterInterface;

class PlainOutputter implements OutputterInterface
{
protected string $output = '';

protected VarDumperInterface $varDumper;

public function prepare(string $output): string
protected StreamWriterInterface $streamWriter;

public function prepare(): void
{
return $output;
}

public function callback(string $output): string
public function callback(): void
{
return $output;
}

final public function __construct(VarDumperInterface $varDumper)
final public function __construct(VarDumperInterface $varDumper, StreamWriterInterface $streamWriter)
{
$this->varDumper = $varDumper;
$this->streamWriter = $streamWriter;
}

final public function varDumper(): VarDumperInterface
{
return $this->varDumper;
}

final public function toString(): string
final public function streamWriter(): StreamWriterInterface
{
return $this->streamWriter;
}

final public function emit(): void
{
$new = clone $this;
$new->output = $new->prepare($new->output);
$new->prepare();
$new->handleClass();
$new->output .= $new->varDumper->formatter()
->highlight('_function', $new->varDumper->debugBacktrace()[VarDumperInterface::OFFSET]['function'] . '()');
$new->streamWriter->write(
$new->varDumper->formatter()
->highlight(
'_function',
$new->varDumper->debugBacktrace()[VarDumperInterface::OFFSET]['function'] . '()'
)
);
$new->handleFile();
$new->output .= "\n\n";
// $new->streamWriter->write("\n\n");
$new->handleArgs();
$new->output = trim($new->output);

return $new->callback($new->output);
$new->callback();
}

final private function handleClass(): void
{
if (isset($this->varDumper->debugBacktrace()[VarDumperInterface::OFFSET]['class'])) {
$class = $this->varDumper->debugBacktrace()[VarDumperInterface::OFFSET]['class'];
$this->output .= $this->varDumper->formatter()
->highlight('_class', $class) . $this->varDumper->debugBacktrace()[VarDumperInterface::OFFSET]['type'];
$item = $this->varDumper->debugBacktrace()[VarDumperInterface::OFFSET];
$class = $item['class'] ?? null;
if ($class !== null) {
$type = $item['type'];
$this->streamWriter->write(
$this->varDumper->formatter()
->highlight('_class', $class) . $type
);
}
}

final private function handleFile(): void
{
if (isset($this->varDumper->debugBacktrace()[0]['file'])) {
$this->output .= "\n" . $this->varDumper->formatter()
->highlight('_file', $this->varDumper->debugBacktrace()[0]['file'] . ':' . $this->varDumper->debugBacktrace()[0]['line']);
$pos = VarDumperInterface::OFFSET - 1;
$item = $this->varDumper->debugBacktrace()[$pos];
if ($item !== null && isset($item['file'])) {
$this->streamWriter->write(
"\n"
. $this->varDumper->formatter()
->highlight(
'_file',
$item['file'] . ':' . $item['line']
)
);
}
}

@@ -87,8 +107,12 @@ public function callback(string $output): string

final private function appendArg(int $pos, $value): void
{
$varDump = (new VarFormat(new VarDumpeable($value), $this->varDumper->formatter()))
->withProcess();
$this->output .= 'Arg#' . $pos . ' ' . $varDump->toString() . "\n\n";
$varDumpeable = new VarDumpeable($value);
$varFormat = new VarFormat($varDumpeable, $this->varDumper->formatter());
$this->streamWriter->write(
'Arg#' . $pos . ' '
);
$varFormat->withProcess();
$this->streamWriter->write("\n\n");
}
}
@@ -17,12 +17,15 @@
use Chevere\Components\Type\Type;
use Chevere\Components\VarDump\Interfaces\ProcessorInterface;
use Chevere\Components\VarDump\Interfaces\VarFormatInterface;
use Chevere\Components\Writers\Interfaces\StreamWriterInterface;
use InvalidArgumentException;
use TypeError;
use function ChevereFn\varType;

abstract class AbstractProcessor implements ProcessorInterface
{
protected StreamWriterInterface $streamWriter;

protected VarFormatInterface $varFormat;

/** @var string */
@@ -31,8 +34,9 @@ abstract class AbstractProcessor implements ProcessorInterface
/** @var string */
protected string $value = '';

final public function __construct(VarFormatInterface $varFormat)
final public function __construct(StreamWriterInterface $streamWriter, VarFormatInterface $varFormat)
{
$this->streamWriter = $streamWriter;
$this->varFormat = $varFormat;
$this->assertType();
$this->process();
@@ -83,9 +87,4 @@ abstract class AbstractProcessor implements ProcessorInterface
{
return $this->info;
}

final public function value(): string
{
return $this->value;
}
}

0 comments on commit e04cd6f

Please sign in to comment.
You can’t perform that action at this time.