$configCache = Factory\ConfigFactory::createCache($configLoader);
Factory\DBFactory::init($configCache, $_SERVER);
$config = Factory\ConfigFactory::createConfig($configCache);
-$pconfig = Factory\ConfigFactory::createPConfig($configCache);
+// needed to call PConfig::init()
+Factory\ConfigFactory::createPConfig($configCache);
$logger = Factory\LoggerFactory::create('auth_ejabberd', $config);
$profiler = Factory\ProfilerFactory::create($logger, $config);
$configCache = Factory\ConfigFactory::createCache($configLoader);
Factory\DBFactory::init($configCache, $_SERVER);
$config = Factory\ConfigFactory::createConfig($configCache);
-$pconfig = Factory\ConfigFactory::createPConfig($configCache);
+// needed to call PConfig::init()
+Factory\ConfigFactory::createPConfig($configCache);
$logger = Factory\LoggerFactory::create('console', $config);
$profiler = Factory\ProfilerFactory::create($logger, $config);
$configCache = Factory\ConfigFactory::createCache($configLoader);
Factory\DBFactory::init($configCache, $_SERVER);
$config = Factory\ConfigFactory::createConfig($configCache);
-$pconfig = Factory\ConfigFactory::createPConfig($configCache);
+// needed to call PConfig::init()
+Factory\ConfigFactory::createPConfig($configCache);
$logger = Factory\LoggerFactory::create('daemon', $config);
$profiler = Factory\ProfilerFactory::create($logger, $config);
$configCache = Factory\ConfigFactory::createCache($configLoader);
Factory\DBFactory::init($configCache, $_SERVER);
$config = Factory\ConfigFactory::createConfig($configCache);
-$pconfig = Factory\ConfigFactory::createPConfig($configCache);
+// needed to call PConfig::init()
+Factory\ConfigFactory::createPConfig($configCache);
$logger = Factory\LoggerFactory::create('worker', $config);
$profiler = Factory\ProfilerFactory::create($logger, $config);
$configCache = Factory\ConfigFactory::createCache($configLoader);
Factory\DBFactory::init($configCache, $_SERVER);
$config = Factory\ConfigFactory::createConfig($configCache);
-$pconfig = Factory\ConfigFactory::createPConfig($configCache);
+// needed to call PConfig::init()
+Factory\ConfigFactory::createPConfig($configCache);
$logger = Factory\LoggerFactory::create('index', $config);
$profiler = Factory\ProfilerFactory::create($logger, $config);
*/
public $mobileDetect;
- /**
- * @var LoggerInterface The current logger of this App
- */
- private $logger;
-
/**
* @var Configuration The config
*/
return $this->mode;
}
- /**
- * Returns the Logger of the Application
- *
- * @return LoggerInterface The Logger
- * @throws InternalServerErrorException when the logger isn't created
- */
- public function getLogger()
- {
- if (empty($this->logger)) {
- throw new InternalServerErrorException('Logger of the Application is not defined');
- }
-
- return $this->logger;
- }
-
/**
* Reloads the whole app instance
*/
public function reload()
{
- $this->getMode()->determine($this->basePath);
-
$this->determineURLPath();
- if ($this->getMode()->has(App\Mode::DBCONFIGAVAILABLE)) {
- Core\Config::load();
- }
-
- // again because DB-config could change the config
$this->getMode()->determine($this->basePath);
if ($this->getMode()->has(App\Mode::DBAVAILABLE)) {
Core\L10n::init();
$this->process_id = Core\System::processID('log');
-
- Core\Logger::setLogger($this->logger);
}
/**
*/
namespace Friendica\Core;
-use Friendica\Core\Config\ConfigCache;
-use Friendica\Core\Config\IConfigAdapter;
-use Friendica\Core\Config\IConfigCache;
-
/**
* @brief Arbitrary system configuration storage
*
{
if (isset($this->config[$cat][$key])) {
return $this->config[$cat][$key];
+ } elseif ($key == null && isset($this->config[$cat])) {
+ return $this->config[$cat];
} else {
return '!<unset>!';
}
*/
public function has($cat, $key = null)
{
- return isset($this->config[$cat][$key])
- && $this->config[$cat][$key] !== '!<unset>!';
+ return (isset($this->config[$cat][$key]) && $this->config[$cat][$key] !== '!<unset>!') ||
+ ($key == null && isset($this->config[$cat]) && $this->config[$cat] !== '!<unset>!' && is_array($this->config[$cat]));
}
/**
*/
public function hasP($uid, $cat, $key = null)
{
- return isset($this->config[$uid][$cat][$key])
- && $this->config[$uid][$cat][$key] !== '!<unset>!';
+ return (isset($this->config[$uid][$cat][$key]) && $this->config[$uid][$cat][$key] !== '!<unset>!') ||
+ ($key == null && isset($this->config[$uid][$cat]) && $this->config[$uid][$cat] !== '!<unset>!' && is_array($this->config[$uid][$cat]));
}
/**
{
if (isset($this->config[$uid][$cat][$key])) {
return $this->config[$uid][$cat][$key];
+ } elseif ($key == null && isset($this->config[$uid][$cat])) {
+ return $this->config[$uid][$cat];
} else {
return '!<unset>!';
}
namespace Friendica\Core;
use Friendica\BaseObject;
-use Friendica\Factory\LoggerFactory;
-use Friendica\Network\HTTPException\InternalServerErrorException;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
/**
* Sets the default logging handler for Friendica.
- * @todo Can be combined with other handlers too if necessary, could be configurable.
*
* @param LoggerInterface $logger The Logger instance of this Application
- *
- * @throws InternalServerErrorException if the logger factory is incompatible to this logger
*/
public static function setLogger($logger)
{
- $debugging = Config::get('system', 'debugging');
- $logfile = Config::get('system', 'logfile');
- $loglevel = Config::get('system', 'loglevel');
-
- if (!$debugging || !$logfile) {
- return;
- }
-
- $loglevel = self::mapLegacyConfigDebugLevel((string)$loglevel);
-
- LoggerFactory::addStreamHandler($logger, $logfile, $loglevel);
-
self::$logger = $logger;
-
- $logfile = Config::get('system', 'dlogfile');
-
- if (!$logfile) {
- return;
- }
-
- $developIp = Config::get('system', 'dlogip');
-
- self::$devLogger = LoggerFactory::createDev('develop', $developIp);
- LoggerFactory::addStreamHandler(self::$devLogger, $logfile, LogLevel::DEBUG);
}
/**
- * Mapping a legacy level to the PSR-3 compliant levels
- * @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#5-psrlogloglevel
- *
- * @param string $level the level to be mapped
+ * Sets the default dev-logging handler for Friendica.
*
- * @return string the PSR-3 compliant level
+ * @param LoggerInterface $logger The Logger instance of this Application
*/
- private static function mapLegacyConfigDebugLevel($level)
+ public static function setDevLogger($logger)
{
- switch ($level) {
- // legacy WARNING
- case "0":
- return LogLevel::ERROR;
- // legacy INFO
- case "1":
- return LogLevel::WARNING;
- // legacy TRACE
- case "2":
- return LogLevel::NOTICE;
- // legacy DEBUG
- case "3":
- return LogLevel::INFO;
- // legacy DATA
- case "4":
- return LogLevel::DEBUG;
- // legacy ALL
- case "5":
- return LogLevel::DEBUG;
- // default if nothing set
- default:
- return $level;
- }
+ self::$devLogger = $logger;
}
/**
class DBFactory
{
+ /**
+ * Initialize the DBA connection
+ *
+ * @param Cache\ConfigCache $configCache The configuration cache
+ * @param array $server The $_SERVER variables
+ *
+ * @throws \Exception if connection went bad
+ */
public static function init(Cache\ConfigCache $configCache, array $server)
{
if (Database\DBA::connected()) {
$logger->pushProcessor(new Monolog\Processor\UidProcessor());
$logger->pushProcessor(new FriendicaIntrospectionProcessor(LogLevel::DEBUG, [Logger::class, Profiler::class]));
- if (isset($config)) {
- $debugging = $config->get('system', 'debugging');
- $stream = $config->get('system', 'logfile');
- $level = $config->get('system', 'loglevel');
+ $debugging = $config->get('system', 'debugging');
+ $stream = $config->get('system', 'logfile');
+ $level = $config->get('system', 'loglevel');
- if ($debugging) {
- static::addStreamHandler($logger, $stream, $level);
- }
+ if ($debugging) {
+ $loglevel = self::mapLegacyConfigDebugLevel((string)$level);
+ static::addStreamHandler($logger, $stream, $loglevel);
}
+ Logger::setLogger($logger);
+
return $logger;
}
*
* It should never get filled during normal usage of Friendica
*
- * @param string $channel The channel of the logger instance
- * @param string $developerIp The IP of the developer who wants to use the logger
+ * @param string $channel The channel of the logger instance
+ * @param Configuration $config The config
*
* @return LoggerInterface The PSR-3 compliant logger instance
*/
- public static function createDev($channel, $developerIp)
+ public static function createDev($channel, Configuration $config)
{
+ $debugging = $config->get('system', 'debugging');
+ $stream = $config->get('system', 'dlogfile');
+ $developerIp = $config->get('system', 'dlogip');
+
+ if (!isset($developerIp) || !$debugging) {
+ return null;
+ }
+
$logger = new Monolog\Logger($channel);
$logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor());
$logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor());
$logger->pushProcessor(new Monolog\Processor\UidProcessor());
$logger->pushProcessor(new FriendicaIntrospectionProcessor(LogLevel::DEBUG, ['Friendica\\Core\\Logger']));
-
$logger->pushHandler(new FriendicaDevelopHandler($developerIp));
+ static::addStreamHandler($logger, $stream, LogLevel::DEBUG);
+
+ Logger::setDevLogger($logger);
+
return $logger;
}
+ /**
+ * Mapping a legacy level to the PSR-3 compliant levels
+ * @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#5-psrlogloglevel
+ *
+ * @param string $level the level to be mapped
+ *
+ * @return string the PSR-3 compliant level
+ */
+ private static function mapLegacyConfigDebugLevel($level)
+ {
+ switch ($level) {
+ // legacy WARNING
+ case "0":
+ return LogLevel::ERROR;
+ // legacy INFO
+ case "1":
+ return LogLevel::WARNING;
+ // legacy TRACE
+ case "2":
+ return LogLevel::NOTICE;
+ // legacy DEBUG
+ case "3":
+ return LogLevel::INFO;
+ // legacy DATA
+ case "4":
+ return LogLevel::DEBUG;
+ // legacy ALL
+ case "5":
+ return LogLevel::DEBUG;
+ // default if nothing set
+ default:
+ return $level;
+ }
+ }
+
/**
* Adding a handler to a given logger instance
*
throw new InternalServerErrorException('Logger instance incompatible for MonologFactory');
}
}
-
- /**
- * This method enables the test mode of a given logger
- *
- * @param LoggerInterface $logger The logger
- *
- * @return Monolog\Handler\TestHandler the Handling for tests
- *
- * @throws InternalServerErrorException if the logger is incompatible to the logger factory
- */
- public static function enableTest($logger)
- {
- if ($logger instanceof Monolog\Logger) {
- // disable every handler so far
- $logger->pushHandler(new Monolog\Handler\NullHandler());
-
- // enable the test handler
- $fileHandler = new Monolog\Handler\TestHandler();
- $formatter = new Monolog\Formatter\LineFormatter("%datetime% %channel% [%level_name%]: %message% %context% %extra%\n");
- $fileHandler->setFormatter($formatter);
-
- $logger->pushHandler($fileHandler);
-
- return $fileHandler;
- } else {
- throw new InternalServerErrorException('Logger instance incompatible for MonologFactory');
- }
- }
}
$configCache = Factory\ConfigFactory::createCache($configLoader);
Factory\DBFactory::init($configCache, $_SERVER);
$config = Factory\ConfigFactory::createConfig($configCache);
- $pconfig = Factory\ConfigFactory::createPConfig($configCache);
+ Factory\ConfigFactory::createPConfig($configCache);
$logger = Factory\LoggerFactory::create('test', $config);
$profiler = Factory\ProfilerFactory::create($logger, $config);
$this->app = new App($config, $logger, $profiler, false);
$configCache = new ConfigCache();
$this->assertFalse($configCache->has('system', 'test'));
+ $this->assertFalse($configCache->has('system'));
$configCache->set('system', 'test', 'it');
$this->assertTrue($configCache->has('system', 'test'));
+ $this->assertTrue($configCache->has('system'));
+ }
- $this->assertFalse($configCache->has('system', null));
- $configCache->set('system', null, 'it');
- $this->assertTrue($configCache->has('system', null));
+ /**
+ * Test the get() method with a category
+ */
+ public function testGetCat()
+ {
+ $configCache = new ConfigCache([
+ 'system' => [
+ 'key1' => 'value1',
+ 'key2' => 'value2',
+ ],
+ 'config' => [
+ 'key3' => 'value3',
+ ],
+ ]);
+
+ $this->assertTrue($configCache->has('system'));
+
+ $this->assertEquals([
+ 'key1' => 'value1',
+ 'key2' => 'value2',
+ ], $configCache->get('system'));
}
/**
}
+ /**
+ * Test the getP() method with a category
+ */
+ public function testGetPCat()
+ {
+ $configCache = new ConfigCache();
+ $uid = 345;
+
+ $configCache->loadP($uid, [
+ 'system' => [
+ 'key1' => 'value1',
+ 'key2' => 'value2',
+ ],
+ 'config' => [
+ 'key3' => 'value3',
+ ],
+ ]);
+
+ $this->assertTrue($configCache->hasP($uid,'system'));
+
+ $this->assertEquals([
+ 'key1' => 'value1',
+ 'key2' => 'value2',
+ ], $configCache->get($uid, 'system'));
+ }
+
/**
* Test the deleteP() method
* @dataProvider dataTests
$uid = 345;
$this->assertFalse($configCache->hasP($uid, 'system', 'test'));
+ $this->assertFalse($configCache->hasP($uid, 'system'));
$configCache->setP($uid, 'system', 'test', 'it');
$this->assertTrue($configCache->hasP($uid, 'system', 'test'));
-
- $this->assertFalse($configCache->hasP($uid, 'system', null));
- $configCache->setP($uid, 'system', null, 'it');
- $this->assertTrue($configCache->hasP($uid, 'system', null));
+ $this->assertTrue($configCache->hasP($uid, 'system'));
}
}