Refactored DependencyFactory for Profiler

This commit is contained in:
Philipp Holzer 2019-02-17 21:12:12 +01:00
parent cdcf1667d7
commit 5e5c39b0e1
No known key found for this signature in database
GPG key ID: 517BE60E2CE5C8A5
12 changed files with 65 additions and 47 deletions

View file

@ -4,18 +4,20 @@ namespace Friendica\Factory;
use Friendica\Core\Config\Cache;
use Friendica\Database;
use Friendica\Util\Profiler;
class DBFactory
{
/**
* Initialize the DBA connection
*
* @param Cache\ConfigCache $configCache The configuration cache
* @param Cache\IConfigCache $configCache The configuration cache
* @param Profiler $profiler The profiler
* @param array $server The $_SERVER variables
*
* @throws \Exception if connection went bad
*/
public static function init(Cache\ConfigCache $configCache, array $server)
public static function init(Cache\IConfigCache $configCache, Profiler $profiler, array $server)
{
if (Database\DBA::connected()) {
return;
@ -46,7 +48,7 @@ class DBFactory
$db_data = $server['MYSQL_DATABASE'];
}
if (Database\DBA::connect($configCache, $db_host, $db_user, $db_pass, $db_data, $charset)) {
if (Database\DBA::connect($configCache, $profiler, $db_host, $db_user, $db_pass, $db_data, $charset)) {
// Loads DB_UPDATE_VERSION constant
Database\DBStructure::definition($configCache->get('system', 'basepath'), false);
}

View file

@ -25,12 +25,13 @@ class DependencyFactory
$basedir = BasePath::create($directory, $_SERVER);
$configLoader = new Cache\ConfigCacheLoader($basedir);
$configCache = Factory\ConfigFactory::createCache($configLoader);
Factory\DBFactory::init($configCache, $_SERVER);
$profiler = Factory\ProfilerFactory::create($configCache);
Factory\DBFactory::init($configCache, $profiler, $_SERVER);
$config = Factory\ConfigFactory::createConfig($configCache);
// needed to call PConfig::init()
Factory\ConfigFactory::createPConfig($configCache);
Factory\LoggerFactory::create($channel, $config);
$logger = Factory\LoggerFactory::create($channel, $config);
return new App($config, $isBackend);
return new App($config, $logger, $profiler, $isBackend);
}
}

View file

@ -42,6 +42,8 @@ class LoggerFactory
if ($debugging) {
$loglevel = self::mapLegacyConfigDebugLevel((string)$level);
static::addStreamHandler($logger, $stream, $loglevel);
} else {
static::addVoidHandler($logger);
}
Logger::init($logger);
@ -153,4 +155,11 @@ class LoggerFactory
throw new InternalServerErrorException('Logger instance incompatible for MonologFactory');
}
}
public static function addVoidHandler($logger)
{
if ($logger instanceof Monolog\Logger) {
$logger->pushHandler(new Monolog\Handler\NullHandler());
}
}
}

View file

@ -2,24 +2,25 @@
namespace Friendica\Factory;
use Friendica\Core\Config\ConfigCache;
use Friendica\Core\Config\Cache\IConfigCache;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
class ProfilerFactory
{
/**
* Creates a Profiler for the current execution
*
* @param LoggerInterface $logger The logger for saving the profiling data
* @param ConfigCache $configCache The configuration cache
* @param IConfigCache $configCache The configuration cache
*
* @return Profiler
*/
public static function create(LoggerInterface $logger, ConfigCache $configCache)
public static function create(IConfigCache $configCache)
{
$enabled = $configCache->get('system', 'profiler', false);
$renderTime = $configCache->get('rendertime', 'callstack', false);
return new Profiler($logger, $enabled, $renderTime);
$enabled = $configCache->get('system', 'profiler');
$enabled = isset($enabled) && $enabled !== '!<unset>!';
$renderTime = $configCache->get('rendertime', 'callstack');
$renderTime = isset($renderTime) && $renderTime !== '!<unset>!';
return new Profiler($enabled, $renderTime);
}
}