Debug bar
This commit is contained in:
parent
58f79c5012
commit
5c0ed594f3
9 changed files with 149 additions and 11 deletions
46
classes/Factory/DebugBarFactory.php
Normal file
46
classes/Factory/DebugBarFactory.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Alltube\Factory;
|
||||
|
||||
use DebugBar\DataCollector\ConfigCollector;
|
||||
use DebugBar\DataCollector\MemoryCollector;
|
||||
use DebugBar\DataCollector\MessagesCollector;
|
||||
use DebugBar\DataCollector\PhpInfoCollector;
|
||||
use DebugBar\DataCollector\RequestDataCollector;
|
||||
use DebugBar\DebugBar;
|
||||
use DebugBar\DebugBarException;
|
||||
use Slim\Container;
|
||||
|
||||
/**
|
||||
* Class DebugBarFactory
|
||||
* @package Alltube\Factory
|
||||
*/
|
||||
class DebugBarFactory
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Container $container
|
||||
* @return DebugBar
|
||||
* @throws DebugBarException
|
||||
*/
|
||||
public static function create(Container $container): DebugBar
|
||||
{
|
||||
$debugBar = new DebugBar();
|
||||
|
||||
$requestCollector = new RequestDataCollector();
|
||||
$configCollector = new ConfigCollector(get_object_vars($container->get('config')));
|
||||
|
||||
$debugBar->addCollector(new PhpInfoCollector())
|
||||
->addCollector(new MessagesCollector())
|
||||
->addCollector($requestCollector)
|
||||
->addCollector(new MemoryCollector())
|
||||
->addCollector($configCollector);
|
||||
|
||||
$container->get('logger')->add('debugbar', $debugBar->getCollector('messages'));
|
||||
|
||||
$requestCollector->useHtmlVarDumper();
|
||||
$configCollector->useHtmlVarDumper();
|
||||
|
||||
return $debugBar;
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
namespace Alltube\Factory;
|
||||
|
||||
use Consolidation\Log\Logger;
|
||||
use Consolidation\Log\LoggerManager;
|
||||
use Consolidation\Log\LogOutputStyler;
|
||||
use Slim\Container;
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
|
@ -16,9 +17,9 @@ class LoggerFactory
|
|||
|
||||
/**
|
||||
* @param Container $container
|
||||
* @return Logger
|
||||
* @return LoggerManager
|
||||
*/
|
||||
public static function create(Container $container): Logger
|
||||
public static function create(Container $container): LoggerManager
|
||||
{
|
||||
$config = $container->get('config');
|
||||
if ($config->debug) {
|
||||
|
@ -27,9 +28,13 @@ class LoggerFactory
|
|||
$verbosity = ConsoleOutput::VERBOSITY_NORMAL;
|
||||
}
|
||||
|
||||
$loggerManager = new LoggerManager();
|
||||
|
||||
$logger = new Logger(new ConsoleOutput($verbosity));
|
||||
$logger->setLogOutputStyler(new LogOutputStyler());
|
||||
|
||||
return $logger;
|
||||
$loggerManager->add('default', $logger);
|
||||
|
||||
return $loggerManager;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,6 +85,14 @@ class ViewFactory
|
|||
$view->offsetSet('config', $container->get('config'));
|
||||
$view->offsetSet('domain', $uri->withBasePath('')->getBaseUrl());
|
||||
|
||||
if ($container->has('debugbar')) {
|
||||
$view->offsetSet(
|
||||
'debug_render',
|
||||
$container->get('debugbar')
|
||||
->getJavascriptRenderer($uri->getBaseUrl() . '/vendor/maximebf/debugbar/src/DebugBar/Resources/')
|
||||
);
|
||||
}
|
||||
|
||||
return $view;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue