Config FollowUp
- New Configuration (Config is now only holding the instance) - New PConfiguration (PConfig is now only holding the instance) - Config & PConfig-Adapter don't need "ConfigCache" anymore - DB-Connection is now outside App->reload() for better dependency-chaining
This commit is contained in:
parent
c36a0eabdb
commit
eafcf3592d
59 changed files with 1754 additions and 1038 deletions
|
@ -2,51 +2,66 @@
|
|||
|
||||
namespace Friendica\Factory;
|
||||
|
||||
use Friendica\Core;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\Config\Adapter;
|
||||
use Friendica\Core\Config\Cache;
|
||||
|
||||
class ConfigFactory
|
||||
{
|
||||
/**
|
||||
* @param Config\ConfigCacheLoader $loader The Config Cache loader (INI/config/.htconfig)
|
||||
* @param Cache\ConfigCacheLoader $loader The Config Cache loader (INI/config/.htconfig)
|
||||
*
|
||||
* @return Config\ConfigCache
|
||||
* @return Cache\ConfigCache
|
||||
*/
|
||||
public static function createCache(Config\ConfigCacheLoader $loader)
|
||||
public static function createCache(Cache\ConfigCacheLoader $loader)
|
||||
{
|
||||
$configCache = new Config\ConfigCache();
|
||||
$configCache = new Cache\ConfigCache();
|
||||
$loader->loadConfigFiles($configCache);
|
||||
|
||||
return $configCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type The adapter type
|
||||
* @param Config\IConfigCache $config The config cache of this adapter
|
||||
* @param Cache\ConfigCache $configCache The config cache of this adapter
|
||||
*
|
||||
* @return Config\IConfigAdapter
|
||||
* @return Config\Configuration
|
||||
*/
|
||||
public static function createConfig($type, Config\IConfigCache $config)
|
||||
public static function createConfig(Cache\ConfigCache $configCache)
|
||||
{
|
||||
if ($type == 'preload') {
|
||||
return new Config\PreloadConfigAdapter($config);
|
||||
if ($configCache->get('system', 'config_adapter') === 'preload') {
|
||||
$configAdapter = new Adapter\PreloadConfigAdapter();
|
||||
} else {
|
||||
return new Config\JITConfigAdapter($config);
|
||||
$configAdapter = new Adapter\JITConfigAdapter();
|
||||
}
|
||||
|
||||
$configuration = new Config\Configuration($configCache, $configAdapter);
|
||||
|
||||
// Set the config in the static container for legacy usage
|
||||
Core\Config::init($configuration);
|
||||
|
||||
return $configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type The adapter type
|
||||
* @param Config\IPConfigCache $config The config cache of this adapter
|
||||
* @param int $uid The UID of the current user
|
||||
* @param Cache\ConfigCache $configCache The config cache of this adapter
|
||||
* @param int $uid The UID of the current user
|
||||
*
|
||||
* @return Config\IPConfigAdapter
|
||||
* @return Config\PConfiguration
|
||||
*/
|
||||
public static function createPConfig($type, Config\IPConfigCache $config, $uid = null)
|
||||
public static function createPConfig(Cache\ConfigCache $configCache, $uid = null)
|
||||
{
|
||||
if ($type == 'preload') {
|
||||
return new Config\PreloadPConfigAdapter($config, $uid);
|
||||
if ($configCache->get('system', 'config_adapter') === 'preload') {
|
||||
$configAdapter = new Adapter\PreloadPConfigAdapter($uid);
|
||||
} else {
|
||||
return new Config\JITPConfigAdapter($config);
|
||||
$configAdapter = new Adapter\JITPConfigAdapter();
|
||||
}
|
||||
|
||||
$configuration = new Config\PConfiguration($configCache, $configAdapter);
|
||||
|
||||
// Set the config in the static container for legacy usage
|
||||
Core\PConfig::init($configuration);
|
||||
|
||||
return $configuration;
|
||||
}
|
||||
}
|
||||
|
|
48
src/Factory/DBFactory.php
Normal file
48
src/Factory/DBFactory.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Factory;
|
||||
|
||||
use Friendica\Core\Config\Cache;
|
||||
use Friendica\Database;
|
||||
|
||||
class DBFactory
|
||||
{
|
||||
public static function init(Cache\ConfigCache $configCache, array $server)
|
||||
{
|
||||
if (Database\DBA::connected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$db_host = $configCache->get('database', 'hostname');
|
||||
$db_user = $configCache->get('database', 'username');
|
||||
$db_pass = $configCache->get('database', 'password');
|
||||
$db_data = $configCache->get('database', 'database');
|
||||
$charset = $configCache->get('database', 'charset');
|
||||
|
||||
// Use environment variables for mysql if they are set beforehand
|
||||
if (!empty($server['MYSQL_HOST'])
|
||||
&& !empty($server['MYSQL_USERNAME'] || !empty($server['MYSQL_USER']))
|
||||
&& $server['MYSQL_PASSWORD'] !== false
|
||||
&& !empty($server['MYSQL_DATABASE']))
|
||||
{
|
||||
$db_host = $server['MYSQL_HOST'];
|
||||
if (!empty($server['MYSQL_PORT'])) {
|
||||
$db_host .= ':' . $server['MYSQL_PORT'];
|
||||
}
|
||||
if (!empty($server['MYSQL_USERNAME'])) {
|
||||
$db_user = $server['MYSQL_USERNAME'];
|
||||
} else {
|
||||
$db_user = $server['MYSQL_USER'];
|
||||
}
|
||||
$db_pass = (string) $server['MYSQL_PASSWORD'];
|
||||
$db_data = $server['MYSQL_DATABASE'];
|
||||
}
|
||||
|
||||
if (Database\DBA::connect($configCache, $db_host, $db_user, $db_pass, $db_data, $charset)) {
|
||||
// Loads DB_UPDATE_VERSION constant
|
||||
Database\DBStructure::definition($configCache->get('system', 'basepath'), false);
|
||||
}
|
||||
|
||||
unset($db_host, $db_user, $db_pass, $db_data, $charset);
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Friendica\Factory;
|
||||
|
||||
use Friendica\Core\Config\ConfigCache;
|
||||
use Friendica\Core\Config\Configuration;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Friendica\Util\Logger\FriendicaDevelopHandler;
|
||||
|
@ -22,12 +22,12 @@ class LoggerFactory
|
|||
/**
|
||||
* Creates a new PSR-3 compliant logger instances
|
||||
*
|
||||
* @param string $channel The channel of the logger instance
|
||||
* @param ConfigCache $config The config
|
||||
* @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 create($channel, ConfigCache $config = null)
|
||||
public static function create($channel, Configuration $config)
|
||||
{
|
||||
$logger = new Monolog\Logger($channel);
|
||||
$logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue