Initial Commit

This commit is contained in:
2018-10-15 00:37:28 -05:00
commit b0bd5569c0
7508 changed files with 849336 additions and 0 deletions

View File

@@ -0,0 +1,84 @@
<?php
namespace BeyondCode\DumpServer;
use Illuminate\Console\Command;
use InvalidArgumentException;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\VarDumper\Dumper\CliDumper;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
use Symfony\Component\VarDumper\Server\DumpServer;
use Symfony\Component\VarDumper\Command\Descriptor\CliDescriptor;
use Symfony\Component\VarDumper\Command\Descriptor\HtmlDescriptor;
class DumpServerCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $signature = 'dump-server {--format=cli : The output format (cli,html).}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Start the dump server to collect dump information.';
/**
* The Dump server.
*
* @var \Symfony\Component\VarDumper\Server\DumpServer
*/
protected $server;
/**
* DumpServerCommand constructor.
*
* @param \Symfony\Component\VarDumper\Server\DumpServer $server
* @return void
*/
public function __construct(DumpServer $server)
{
$this->server = $server;
parent::__construct();
}
/**
* Handle the command.
*
* @return void
*/
public function handle()
{
switch ($format = $this->option('format')) {
case 'cli':
$descriptor = new CliDescriptor(new CliDumper);
break;
case 'html':
$descriptor = new HtmlDescriptor(new HtmlDumper);
break;
default:
throw new InvalidArgumentException(sprintf('Unsupported format "%s".', $format));
}
$io = new SymfonyStyle($this->input, $this->output);
$errorIo = $io->getErrorStyle();
$errorIo->title('Laravel Var Dump Server');
$this->server->start();
$errorIo->success(sprintf('Server listening on %s', $this->server->getHost()));
$errorIo->comment('Quit the server with CONTROL-C.');
$this->server->listen(function (Data $data, array $context, int $clientId) use ($descriptor, $io) {
$descriptor->describe($io, $data, $context, $clientId);
});
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace BeyondCode\DumpServer;
use Illuminate\Support\ServiceProvider;
use Symfony\Component\VarDumper\VarDumper;
use Symfony\Component\VarDumper\Server\Connection;
use Symfony\Component\VarDumper\Server\DumpServer;
use Symfony\Component\VarDumper\Dumper\ContextProvider\SourceContextProvider;
class DumpServerServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/../config/config.php' => config_path('debug-server.php'),
], 'config');
}
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'debug-server');
$this->app->bind('command.dumpserver', DumpServerCommand::class);
$this->commands([
'command.dumpserver',
]);
$host = $this->app['config']->get('debug-server.host');
$this->app->when(DumpServer::class)->needs('$host')->give($host);
$connection = new Connection($host, [
'request' => new RequestContextProvider($this->app['request']),
'source' => new SourceContextProvider('utf-8', base_path()),
]);
VarDumper::setHandler(function ($var) use ($connection) {
(new Dumper($connection))->dump($var);
});
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace BeyondCode\DumpServer;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\CliDumper;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
use Symfony\Component\VarDumper\Server\Connection;
class Dumper
{
/**
* The connection.
*
* @var \Symfony\Component\VarDumper\Server\Connection|null
*/
private $connection;
/**
* Dumper constructor.
*
* @param \Symfony\Component\VarDumper\Server\Connection|null $connection
* @return void
*/
public function __construct(Connection $connection = null)
{
$this->connection = $connection;
}
/**
* Dump a value with elegance.
*
* @param mixed $value
* @return void
*/
public function dump($value)
{
if (class_exists(CliDumper::class)) {
$data = (new VarCloner)->cloneVar($value);
if ($this->connection === null || $this->connection->write($data) === false) {
$dumper = in_array(PHP_SAPI, ['cli', 'phpdbg']) ? new CliDumper : new HtmlDumper;
$dumper->dump($data);
}
} else {
var_dump($value);
}
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace BeyondCode\DumpServer;
use Illuminate\Http\Request;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\ContextProvider\ContextProviderInterface;
class RequestContextProvider implements ContextProviderInterface
{
/**
* The current request.
*
* @var \Illuminate\Http\Request|null
*/
private $currentRequest;
/**
* The variable cloner.
*
* @var \Symfony\Component\VarDumper\Cloner\VarCloner
*/
private $cloner;
/**
* RequestContextProvider constructor.
*
* @param \Illuminate\Http\Request|null $currentRequest
* @return void
*/
public function __construct(Request $currentRequest = null)
{
$this->currentRequest = $currentRequest;
$this->cloner = new VarCloner;
$this->cloner->setMaxItems(0);
}
/**
* Get the context.
*
* @return array|null
*/
public function getContext(): ?array
{
if ($this->currentRequest === null) {
return null;
}
$controller = null;
if ($route = $this->currentRequest->route()) {
$controller = $route->controller;
if (! $controller && ! is_string($route->action['uses'])) {
$controller = $route->action['uses'];
}
}
return [
'uri' => $this->currentRequest->getUri(),
'method' => $this->currentRequest->getMethod(),
'controller' => $controller ? $this->cloner->cloneVar(class_basename($controller)) : $controller,
'identifier' => spl_object_hash($this->currentRequest),
];
}
}