Restructure (P)Config to follow new paradigm
This commit is contained in:
parent
68046573a4
commit
ab83d0dd27
|
@ -25,10 +25,10 @@ use Exception;
|
||||||
use Friendica\App\Arguments;
|
use Friendica\App\Arguments;
|
||||||
use Friendica\App\BaseURL;
|
use Friendica\App\BaseURL;
|
||||||
use Friendica\App\Module;
|
use Friendica\App\Module;
|
||||||
use Friendica\Factory\ConfigFactory;
|
use Friendica\Core\Config\Factory\ConfigFactory;
|
||||||
use Friendica\Module\Maintenance;
|
use Friendica\Module\Maintenance;
|
||||||
use Friendica\Security\Authentication;
|
use Friendica\Security\Authentication;
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
use Friendica\Core\Config\IConfig;
|
use Friendica\Core\Config\IConfig;
|
||||||
use Friendica\Core\PConfig\IPConfig;
|
use Friendica\Core\PConfig\IPConfig;
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
|
@ -39,7 +39,6 @@ use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Profile;
|
use Friendica\Model\Profile;
|
||||||
use Friendica\Module\Special\HTTPException as ModuleHTTPException;
|
use Friendica\Module\Special\HTTPException as ModuleHTTPException;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Util\ConfigFileLoader;
|
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\HTTPSignature;
|
use Friendica\Util\HTTPSignature;
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
namespace Friendica\App;
|
namespace Friendica\App;
|
||||||
|
|
||||||
use Detection\MobileDetect;
|
use Detection\MobileDetect;
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
use Friendica\Util\BasePath;
|
use Friendica\Util\BasePath;
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ use Asika\SimpleConsole\Console;
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\App\BaseURL;
|
use Friendica\App\BaseURL;
|
||||||
use Friendica\Core\Config\IConfig;
|
use Friendica\Core\Config\IConfig;
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
use Friendica\Core\Installer;
|
use Friendica\Core\Installer;
|
||||||
use Friendica\Core\Theme;
|
use Friendica\Core\Theme;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
|
@ -36,7 +36,7 @@ class AutomaticInstallation extends Console
|
||||||
{
|
{
|
||||||
/** @var App\Mode */
|
/** @var App\Mode */
|
||||||
private $appMode;
|
private $appMode;
|
||||||
/** @var Cache */
|
/** @var \Friendica\Core\Config\Cache\Cache */
|
||||||
private $configCache;
|
private $configCache;
|
||||||
/** @var IConfig */
|
/** @var IConfig */
|
||||||
private $config;
|
private $config;
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
namespace Friendica\Console;
|
namespace Friendica\Console;
|
||||||
|
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
use Friendica\Core\Update;
|
use Friendica\Core\Update;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
use Friendica\Database\DBStructure;
|
use Friendica\Database\DBStructure;
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Core\Config;
|
namespace Friendica\Core\Config\Cache;
|
||||||
|
|
||||||
use ParagonIE\HiddenString\HiddenString;
|
use ParagonIE\HiddenString\HiddenString;
|
||||||
|
|
|
@ -19,11 +19,11 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Util;
|
namespace Friendica\Core\Config\Cache;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Friendica\Core\Addon;
|
use Friendica\Core\Addon;
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ConfigFileLoader loads config-files and stores them in a ConfigCache ( @see Cache )
|
* The ConfigFileLoader loads config-files and stores them in a ConfigCache ( @see Cache )
|
|
@ -19,14 +19,13 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Factory;
|
namespace Friendica\Core\Config\Factory;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
use Friendica\Model\Config\Config as ConfigModel;
|
use Friendica\Core\Config\Model\Config as ConfigModel;
|
||||||
use Friendica\Model\Config\PConfig as PConfigModel;
|
use Friendica\Core\Config\Cache\ConfigFileLoader;
|
||||||
use Friendica\Util\ConfigFileLoader;
|
|
||||||
|
|
||||||
class ConfigFactory
|
class ConfigFactory
|
||||||
{
|
{
|
||||||
|
@ -55,7 +54,7 @@ class ConfigFactory
|
||||||
* @param string $basePath The basepath of FRIENDICA
|
* @param string $basePath The basepath of FRIENDICA
|
||||||
* @param array $serer the $_SERVER array
|
* @param array $serer the $_SERVER array
|
||||||
*
|
*
|
||||||
* @return ConfigFileLoader
|
* @return \Friendica\Core\Config\Cache\ConfigFileLoader
|
||||||
*/
|
*/
|
||||||
public function createConfigFileLoader(string $basePath, array $server = [])
|
public function createConfigFileLoader(string $basePath, array $server = [])
|
||||||
{
|
{
|
||||||
|
@ -70,7 +69,7 @@ class ConfigFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ConfigFileLoader $loader The Config Cache loader (INI/config/.htconfig)
|
* @param \Friendica\Core\Config\Cache\ConfigFileLoader $loader The Config Cache loader (INI/config/.htconfig)
|
||||||
*
|
*
|
||||||
* @return Cache
|
* @return Cache
|
||||||
*
|
*
|
||||||
|
@ -85,38 +84,20 @@ class ConfigFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Cache $configCache The config cache of this adapter
|
* @param \Friendica\Core\Config\Cache\Cache $configCache The config cache of this adapter
|
||||||
* @param ConfigModel $configModel The configuration model
|
* @param ConfigModel $configModel The configuration model
|
||||||
*
|
*
|
||||||
* @return Config\IConfig
|
* @return Config\IConfig
|
||||||
*/
|
*/
|
||||||
public function createConfig(Cache $configCache, ConfigModel $configModel)
|
public function create(Cache $configCache, ConfigModel $configModel)
|
||||||
{
|
{
|
||||||
if ($configCache->get('system', 'config_adapter') === 'preload') {
|
if ($configCache->get('system', 'config_adapter') === 'preload') {
|
||||||
$configuration = new Config\PreloadConfig($configCache, $configModel);
|
$configuration = new Config\Type\PreloadConfig($configCache, $configModel);
|
||||||
} else {
|
} else {
|
||||||
$configuration = new Config\JitConfig($configCache, $configModel);
|
$configuration = new Config\Type\JitConfig($configCache, $configModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return $configuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Cache $configCache The config cache
|
|
||||||
* @param \Friendica\Core\PConfig\Cache $pConfigCache The personal config cache
|
|
||||||
* @param PConfigModel $configModel The configuration model
|
|
||||||
*
|
|
||||||
* @return \Friendica\Core\PConfig\IPConfig
|
|
||||||
*/
|
|
||||||
public function createPConfig(Cache $configCache, \Friendica\Core\PConfig\Cache $pConfigCache, PConfigModel $configModel)
|
|
||||||
{
|
|
||||||
if ($configCache->get('system', 'config_adapter') === 'preload') {
|
|
||||||
$configuration = new \Friendica\Core\PConfig\PreloadPConfig($pConfigCache, $configModel);
|
|
||||||
} else {
|
|
||||||
$configuration = new \Friendica\Core\PConfig\JitPConfig($pConfigCache, $configModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $configuration;
|
return $configuration;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,6 +21,8 @@
|
||||||
|
|
||||||
namespace Friendica\Core\Config;
|
namespace Friendica\Core\Config;
|
||||||
|
|
||||||
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for accessing system wide configurations
|
* Interface for accessing system wide configurations
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -19,14 +19,36 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Model\Config;
|
namespace Friendica\Core\Config\Model;
|
||||||
|
|
||||||
|
use Friendica\Database\Database;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Config model backend, which is using the general DB-model backend for configs
|
* The Config model backend, which is using the general DB-model backend for configs
|
||||||
*/
|
*/
|
||||||
class Config extends DbaConfig
|
class Config
|
||||||
{
|
{
|
||||||
|
/** @var Database */
|
||||||
|
protected $dba;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Database $dba The database connection of this model
|
||||||
|
*/
|
||||||
|
public function __construct(Database $dba)
|
||||||
|
{
|
||||||
|
$this->dba = $dba;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the model is currently connected
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isConnected()
|
||||||
|
{
|
||||||
|
return $this->dba->isConnected();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads all configuration values and returns the loaded category as an array.
|
* Loads all configuration values and returns the loaded category as an array.
|
||||||
*
|
*
|
||||||
|
@ -49,7 +71,7 @@ class Config extends DbaConfig
|
||||||
while ($config = $this->dba->fetch($configs)) {
|
while ($config = $this->dba->fetch($configs)) {
|
||||||
|
|
||||||
$key = $config['k'];
|
$key = $config['k'];
|
||||||
$value = $this->toConfigValue($config['v']);
|
$value = DbaUtils::toConfigValue($config['v']);
|
||||||
|
|
||||||
// just save it in case it is set
|
// just save it in case it is set
|
||||||
if (isset($value)) {
|
if (isset($value)) {
|
||||||
|
@ -82,7 +104,7 @@ class Config extends DbaConfig
|
||||||
|
|
||||||
$config = $this->dba->selectFirst('config', ['v'], ['cat' => $cat, 'k' => $key]);
|
$config = $this->dba->selectFirst('config', ['v'], ['cat' => $cat, 'k' => $key]);
|
||||||
if ($this->dba->isResult($config)) {
|
if ($this->dba->isResult($config)) {
|
||||||
$value = $this->toConfigValue($config['v']);
|
$value = DbaUtils::toConfigValue($config['v']);
|
||||||
|
|
||||||
// just return it in case it is set
|
// just return it in case it is set
|
||||||
if (isset($value)) {
|
if (isset($value)) {
|
||||||
|
@ -122,7 +144,7 @@ class Config extends DbaConfig
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$dbvalue = $this->toDbValue($value);
|
$dbvalue = DbaUtils::toDbValue($value);
|
||||||
|
|
||||||
$result = $this->dba->update('config', ['v' => $dbvalue], ['cat' => $cat, 'k' => $key], true);
|
$result = $this->dba->update('config', ['v' => $dbvalue], ['cat' => $cat, 'k' => $key], true);
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Core\Config\Model;
|
||||||
|
|
||||||
|
class DbaUtils
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Formats a DB value to a config value
|
||||||
|
* - null = The db-value isn't set
|
||||||
|
* - bool = The db-value is either '0' or '1'
|
||||||
|
* - array = The db-value is a serialized array
|
||||||
|
* - string = The db-value is a string
|
||||||
|
*
|
||||||
|
* Keep in mind that there aren't any numeric/integer config values in the database
|
||||||
|
*
|
||||||
|
* @param null|string $value
|
||||||
|
*
|
||||||
|
* @return null|array|string
|
||||||
|
*/
|
||||||
|
public static function toConfigValue($value)
|
||||||
|
{
|
||||||
|
if (!isset($value)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (true) {
|
||||||
|
// manage array value
|
||||||
|
case preg_match("|^a:[0-9]+:{.*}$|s", $value):
|
||||||
|
return unserialize($value);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats a config value to a DB value (string)
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function toDbValue($value): string
|
||||||
|
{
|
||||||
|
// if not set, save an empty string
|
||||||
|
if (!isset($value)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (true) {
|
||||||
|
// manage arrays
|
||||||
|
case is_array($value):
|
||||||
|
return serialize($value);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return (string)$value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,16 +19,16 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Core;
|
namespace Friendica\Core\Config\Type;
|
||||||
|
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
use Friendica\Core\Config\IConfig;
|
use Friendica\Core\Config\IConfig;
|
||||||
use Friendica\Model;
|
use Friendica\Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is responsible for all system-wide configuration values in Friendica
|
* This class is responsible for all system-wide configuration values in Friendica
|
||||||
* There are two types of storage
|
* There are two types of storage
|
||||||
* - The Config-Files (loaded into the FileCache @see Cache\ConfigCache)
|
* - The Config-Files (loaded into the FileCache @see ConfigCache)
|
||||||
* - The Config-DB-Table (per Config-DB-model @see Model\Config\Config)
|
* - The Config-DB-Table (per Config-DB-model @see Model\Config\Config)
|
||||||
*/
|
*/
|
||||||
abstract class BaseConfig implements IConfig
|
abstract class BaseConfig implements IConfig
|
||||||
|
@ -39,15 +39,15 @@ abstract class BaseConfig implements IConfig
|
||||||
protected $configCache;
|
protected $configCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Model\Config\Config
|
* @var \Friendica\Core\Config\Model\Config
|
||||||
*/
|
*/
|
||||||
protected $configModel;
|
protected $configModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Cache $configCache The configuration cache (based on the config-files)
|
* @param Cache $configCache The configuration cache (based on the config-files)
|
||||||
* @param Model\Config\Config $configModel The configuration model
|
* @param \Friendica\Core\Config\Model\Config $configModel The configuration model
|
||||||
*/
|
*/
|
||||||
public function __construct(Cache $configCache, Model\Config\Config $configModel)
|
public function __construct(Cache $configCache, \Friendica\Core\Config\Model\Config $configModel)
|
||||||
{
|
{
|
||||||
$this->configCache = $configCache;
|
$this->configCache = $configCache;
|
||||||
$this->configModel = $configModel;
|
$this->configModel = $configModel;
|
|
@ -19,10 +19,10 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Core\Config;
|
namespace Friendica\Core\Config\Type;
|
||||||
|
|
||||||
use Friendica\Core\BaseConfig;
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
use Friendica\Model;
|
use Friendica\Core\Config\Model\Config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class implements the Just-In-Time configuration, which will cache
|
* This class implements the Just-In-Time configuration, which will cache
|
||||||
|
@ -40,9 +40,9 @@ class JitConfig extends BaseConfig
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Cache $configCache The configuration cache (based on the config-files)
|
* @param Cache $configCache The configuration cache (based on the config-files)
|
||||||
* @param Model\Config\Config $configModel The configuration model
|
* @param Config $configModel The configuration model
|
||||||
*/
|
*/
|
||||||
public function __construct(Cache $configCache, Model\Config\Config $configModel)
|
public function __construct(Cache $configCache, Config $configModel)
|
||||||
{
|
{
|
||||||
parent::__construct($configCache, $configModel);
|
parent::__construct($configCache, $configModel);
|
||||||
$this->db_loaded = [];
|
$this->db_loaded = [];
|
|
@ -19,10 +19,10 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Core\Config;
|
namespace Friendica\Core\Config\Type;
|
||||||
|
|
||||||
use Friendica\Core\BaseConfig;
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
use Friendica\Model;
|
use Friendica\Core\Config\Model\Config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class implements the preload configuration, which will cache
|
* This class implements the preload configuration, which will cache
|
||||||
|
@ -37,9 +37,9 @@ class PreloadConfig extends BaseConfig
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Cache $configCache The configuration cache (based on the config-files)
|
* @param Cache $configCache The configuration cache (based on the config-files)
|
||||||
* @param Model\Config\Config $configModel The configuration model
|
* @param Config $configModel The configuration model
|
||||||
*/
|
*/
|
||||||
public function __construct(Cache $configCache, Model\Config\Config $configModel)
|
public function __construct(Cache $configCache, Config $configModel)
|
||||||
{
|
{
|
||||||
parent::__construct($configCache, $configModel);
|
parent::__construct($configCache, $configModel);
|
||||||
$this->config_loaded = false;
|
$this->config_loaded = false;
|
|
@ -23,7 +23,7 @@ namespace Friendica\Core;
|
||||||
|
|
||||||
use DOMDocument;
|
use DOMDocument;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
use Friendica\Database\DBStructure;
|
use Friendica\Database\DBStructure;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
@ -278,7 +278,7 @@ class Installer
|
||||||
$cmd = "$phppath -v";
|
$cmd = "$phppath -v";
|
||||||
$result = trim(shell_exec($cmd));
|
$result = trim(shell_exec($cmd));
|
||||||
$passed2 = (strpos($result, "(cli)") !== false);
|
$passed2 = (strpos($result, "(cli)") !== false);
|
||||||
list($result) = explode("\n", $result);
|
[$result] = explode("\n", $result);
|
||||||
$help = "";
|
$help = "";
|
||||||
if (!$passed2) {
|
if (!$passed2) {
|
||||||
$help .= DI::l10n()->t("PHP executable is not the php cli binary \x28could be cgi-fgci version\x29") . EOL;
|
$help .= DI::l10n()->t("PHP executable is not the php cli binary \x28could be cgi-fgci version\x29") . EOL;
|
||||||
|
@ -678,7 +678,7 @@ class Installer
|
||||||
/**
|
/**
|
||||||
* Setup the default cache for a new installation
|
* Setup the default cache for a new installation
|
||||||
*
|
*
|
||||||
* @param Cache $configCache The configuration cache
|
* @param \Friendica\Core\Config\Cache\Cache $configCache The configuration cache
|
||||||
* @param string $basePath The determined basepath
|
* @param string $basePath The determined basepath
|
||||||
*
|
*
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Core\PConfig;
|
namespace Friendica\Core\PConfig\Cache;
|
||||||
|
|
||||||
use ParagonIE\HiddenString\HiddenString;
|
use ParagonIE\HiddenString\HiddenString;
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||||
|
*
|
||||||
|
* @license GNU AGPL version 3 or any later version
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Friendica\Core\PConfig\Factory;
|
||||||
|
|
||||||
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
|
use Friendica\Core\PConfig\IPConfig;
|
||||||
|
use Friendica\Core\PConfig\Model\PConfig as PConfigModel;
|
||||||
|
use Friendica\Core\PConfig\Type;
|
||||||
|
|
||||||
|
class PConfigFactory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param Cache $configCache The config cache
|
||||||
|
* @param \Friendica\Core\PConfig\Cache\Cache $pConfigCache The personal config cache
|
||||||
|
* @param PConfigModel $configModel The configuration model
|
||||||
|
*
|
||||||
|
* @return IPConfig
|
||||||
|
*/
|
||||||
|
public function create(Cache $configCache, \Friendica\Core\PConfig\Cache\Cache $pConfigCache, PConfigModel $configModel)
|
||||||
|
{
|
||||||
|
if ($configCache->get('system', 'config_adapter') === 'preload') {
|
||||||
|
$configuration = new Type\PreloadPConfig($pConfigCache, $configModel);
|
||||||
|
} else {
|
||||||
|
$configuration = new Type\JitPConfig($pConfigCache, $configModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $configuration;
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,6 +21,8 @@
|
||||||
|
|
||||||
namespace Friendica\Core\PConfig;
|
namespace Friendica\Core\PConfig;
|
||||||
|
|
||||||
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for accessing user specific configurations
|
* Interface for accessing user specific configurations
|
||||||
*/
|
*/
|
||||||
|
@ -95,7 +97,7 @@ interface IPConfig
|
||||||
/**
|
/**
|
||||||
* Returns the Config Cache
|
* Returns the Config Cache
|
||||||
*
|
*
|
||||||
* @return Cache
|
* @return \Friendica\Core\PConfig\Cache\Cache
|
||||||
*/
|
*/
|
||||||
function getCache();
|
function getCache();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,14 +19,37 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Model\Config;
|
namespace Friendica\Core\PConfig\Model;
|
||||||
|
|
||||||
|
use Friendica\Core\Config\Model\DbaUtils;
|
||||||
|
use Friendica\Database\Database;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Config model backend for users, which is using the general DB-model backend for user-configs
|
* The Config model backend for users, which is using the general DB-model backend for user-configs
|
||||||
*/
|
*/
|
||||||
class PConfig extends DbaConfig
|
class PConfig
|
||||||
{
|
{
|
||||||
|
/** @var Database */
|
||||||
|
protected $dba;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Database $dba The database connection of this model
|
||||||
|
*/
|
||||||
|
public function __construct(Database $dba)
|
||||||
|
{
|
||||||
|
$this->dba = $dba;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the model is currently connected
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isConnected()
|
||||||
|
{
|
||||||
|
return $this->dba->isConnected();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads all configuration values and returns the loaded category as an array.
|
* Loads all configuration values and returns the loaded category as an array.
|
||||||
*
|
*
|
||||||
|
@ -49,7 +72,7 @@ class PConfig extends DbaConfig
|
||||||
|
|
||||||
while ($config = $this->dba->fetch($configs)) {
|
while ($config = $this->dba->fetch($configs)) {
|
||||||
$key = $config['k'];
|
$key = $config['k'];
|
||||||
$value = $this->toConfigValue($config['v']);
|
$value = DbaUtils::toConfigValue($config['v']);
|
||||||
|
|
||||||
// just save it in case it is set
|
// just save it in case it is set
|
||||||
if (isset($value)) {
|
if (isset($value)) {
|
||||||
|
@ -83,7 +106,7 @@ class PConfig extends DbaConfig
|
||||||
|
|
||||||
$config = $this->dba->selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $key]);
|
$config = $this->dba->selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $key]);
|
||||||
if ($this->dba->isResult($config)) {
|
if ($this->dba->isResult($config)) {
|
||||||
$value = $this->toConfigValue($config['v']);
|
$value = DbaUtils::toConfigValue($config['v']);
|
||||||
|
|
||||||
// just return it in case it is set
|
// just return it in case it is set
|
||||||
if (isset($value)) {
|
if (isset($value)) {
|
||||||
|
@ -125,7 +148,7 @@ class PConfig extends DbaConfig
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$dbvalue = $this->toDbValue($value);
|
$dbvalue = DbaUtils::toDbValue($value);
|
||||||
|
|
||||||
$result = $this->dba->update('pconfig', ['v' => $dbvalue], ['uid' => $uid, 'cat' => $cat, 'k' => $key], true);
|
$result = $this->dba->update('pconfig', ['v' => $dbvalue], ['uid' => $uid, 'cat' => $cat, 'k' => $key], true);
|
||||||
|
|
|
@ -19,9 +19,9 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Core;
|
namespace Friendica\Core\PConfig\Type;
|
||||||
|
|
||||||
use Friendica\Core\PConfig\Cache;
|
use Friendica\Core\PConfig\Cache\Cache;
|
||||||
use Friendica\Core\PConfig\IPConfig;
|
use Friendica\Core\PConfig\IPConfig;
|
||||||
use Friendica\Model;
|
use Friendica\Model;
|
||||||
|
|
||||||
|
@ -35,20 +35,20 @@ use Friendica\Model;
|
||||||
abstract class BasePConfig implements IPConfig
|
abstract class BasePConfig implements IPConfig
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Cache
|
* @var \Friendica\Core\PConfig\Cache\Cache
|
||||||
*/
|
*/
|
||||||
protected $configCache;
|
protected $configCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Model\Config\PConfig
|
* @var \Friendica\Core\PConfig\Model\PConfig
|
||||||
*/
|
*/
|
||||||
protected $configModel;
|
protected $configModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Cache $configCache The configuration cache
|
* @param \Friendica\Core\PConfig\Cache\Cache $configCache The configuration cache
|
||||||
* @param Model\Config\PConfig $configModel The configuration model
|
* @param \Friendica\Core\PConfig\Model\PConfig $configModel The configuration model
|
||||||
*/
|
*/
|
||||||
public function __construct(Cache $configCache, Model\Config\PConfig $configModel)
|
public function __construct(Cache $configCache, \Friendica\Core\PConfig\Model\PConfig $configModel)
|
||||||
{
|
{
|
||||||
$this->configCache = $configCache;
|
$this->configCache = $configCache;
|
||||||
$this->configModel = $configModel;
|
$this->configModel = $configModel;
|
||||||
|
@ -57,7 +57,7 @@ abstract class BasePConfig implements IPConfig
|
||||||
/**
|
/**
|
||||||
* Returns the Config Cache
|
* Returns the Config Cache
|
||||||
*
|
*
|
||||||
* @return Cache
|
* @return \Friendica\Core\PConfig\Cache\Cache
|
||||||
*/
|
*/
|
||||||
public function getCache()
|
public function getCache()
|
||||||
{
|
{
|
|
@ -19,9 +19,9 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Core\PConfig;
|
namespace Friendica\Core\PConfig\Type;
|
||||||
|
|
||||||
use Friendica\Core\BasePConfig;
|
use Friendica\Core\PConfig\Cache\Cache;
|
||||||
use Friendica\Model;
|
use Friendica\Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,9 +40,9 @@ class JitPConfig extends BasePConfig
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Cache $configCache The configuration cache
|
* @param Cache $configCache The configuration cache
|
||||||
* @param Model\Config\PConfig $configModel The configuration model
|
* @param \Friendica\Core\PConfig\Model\PConfig $configModel The configuration model
|
||||||
*/
|
*/
|
||||||
public function __construct(Cache $configCache, Model\Config\PConfig $configModel)
|
public function __construct(Cache $configCache, \Friendica\Core\PConfig\Model\PConfig $configModel)
|
||||||
{
|
{
|
||||||
parent::__construct($configCache, $configModel);
|
parent::__construct($configCache, $configModel);
|
||||||
$this->db_loaded = [];
|
$this->db_loaded = [];
|
|
@ -19,9 +19,9 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Core\PConfig;
|
namespace Friendica\Core\PConfig\Type;
|
||||||
|
|
||||||
use Friendica\Core\BasePConfig;
|
use Friendica\Core\PConfig\Cache\Cache;
|
||||||
use Friendica\Model;
|
use Friendica\Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,10 +36,10 @@ class PreloadPConfig extends BasePConfig
|
||||||
private $config_loaded;
|
private $config_loaded;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Cache $configCache The configuration cache
|
* @param \Friendica\Core\PConfig\Cache\Cache $configCache The configuration cache
|
||||||
* @param Model\Config\PConfig $configModel The configuration model
|
* @param \Friendica\Core\PConfig\Model\PConfig $configModel The configuration model
|
||||||
*/
|
*/
|
||||||
public function __construct(Cache $configCache, Model\Config\PConfig $configModel)
|
public function __construct(Cache $configCache, \Friendica\Core\PConfig\Model\PConfig $configModel)
|
||||||
{
|
{
|
||||||
parent::__construct($configCache, $configModel);
|
parent::__construct($configCache, $configModel);
|
||||||
$this->config_loaded = [];
|
$this->config_loaded = [];
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
namespace Friendica\Database;
|
namespace Friendica\Database;
|
||||||
|
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
|
|
|
@ -1,105 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
|
||||||
*
|
|
||||||
* @license GNU AGPL version 3 or any later version
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Friendica\Model\Config;
|
|
||||||
|
|
||||||
use Friendica\Database\Database;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The DB-based model of (P-)Config values
|
|
||||||
* Encapsulates db-calls in case of config queries
|
|
||||||
*/
|
|
||||||
abstract class DbaConfig
|
|
||||||
{
|
|
||||||
/** @var Database */
|
|
||||||
protected $dba;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Database $dba The database connection of this model
|
|
||||||
*/
|
|
||||||
public function __construct(Database $dba)
|
|
||||||
{
|
|
||||||
$this->dba = $dba;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the model is currently connected
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isConnected()
|
|
||||||
{
|
|
||||||
return $this->dba->isConnected();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Formats a DB value to a config value
|
|
||||||
* - null = The db-value isn't set
|
|
||||||
* - bool = The db-value is either '0' or '1'
|
|
||||||
* - array = The db-value is a serialized array
|
|
||||||
* - string = The db-value is a string
|
|
||||||
*
|
|
||||||
* Keep in mind that there aren't any numeric/integer config values in the database
|
|
||||||
*
|
|
||||||
* @param null|string $value
|
|
||||||
*
|
|
||||||
* @return null|array|string
|
|
||||||
*/
|
|
||||||
protected function toConfigValue($value)
|
|
||||||
{
|
|
||||||
if (!isset($value)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (true) {
|
|
||||||
// manage array value
|
|
||||||
case preg_match("|^a:[0-9]+:{.*}$|s", $value):
|
|
||||||
return unserialize($value);
|
|
||||||
|
|
||||||
default:
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Formats a config value to a DB value (string)
|
|
||||||
*
|
|
||||||
* @param mixed $value
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function toDbValue($value)
|
|
||||||
{
|
|
||||||
// if not set, save an empty string
|
|
||||||
if (!isset($value)) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (true) {
|
|
||||||
// manage arrays
|
|
||||||
case is_array($value):
|
|
||||||
return serialize($value);
|
|
||||||
|
|
||||||
default:
|
|
||||||
return (string)$value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -22,18 +22,18 @@
|
||||||
namespace Friendica\Module\Admin;
|
namespace Friendica\Module\Admin;
|
||||||
|
|
||||||
use Friendica\Core\Addon;
|
use Friendica\Core\Addon;
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
use Friendica\Core\Logger;
|
use Friendica\Core\Logger;
|
||||||
use Friendica\Core\Renderer;
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\Core\Update;
|
use Friendica\Core\Update;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\Database\DBStructure;
|
use Friendica\Database\DBStructure;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Factory\ConfigFactory;
|
use Friendica\Core\Config\Factory\ConfigFactory;
|
||||||
use Friendica\Model\Register;
|
use Friendica\Model\Register;
|
||||||
use Friendica\Module\BaseAdmin;
|
use Friendica\Module\BaseAdmin;
|
||||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||||
use Friendica\Util\ConfigFileLoader;
|
use Friendica\Core\Config\Cache\ConfigFileLoader;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
|
|
||||||
class Summary extends BaseAdmin
|
class Summary extends BaseAdmin
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace Friendica\Module;
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\BaseModule;
|
use Friendica\BaseModule;
|
||||||
use Friendica\Core;
|
use Friendica\Core;
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
use Friendica\Core\Renderer;
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\Core\Theme;
|
use Friendica\Core\Theme;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
namespace Friendica\Util;
|
namespace Friendica\Util;
|
||||||
|
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
use Friendica\Core\Config\IConfig;
|
use Friendica\Core\Config\IConfig;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
|
@ -78,7 +78,7 @@ class Profiler implements ContainerInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Cache $configCache The configuration cache
|
* @param \Friendica\Core\Config\Cache\Cache $configCache The configuration cache
|
||||||
*/
|
*/
|
||||||
public function __construct(Cache $configCache)
|
public function __construct(Cache $configCache)
|
||||||
{
|
{
|
||||||
|
|
|
@ -37,6 +37,7 @@ use Dice\Dice;
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Core\Cache;
|
use Friendica\Core\Cache;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
|
use Friendica\Core\PConfig;
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Core\Lock\ILock;
|
use Friendica\Core\Lock\ILock;
|
||||||
use Friendica\Core\Process;
|
use Friendica\Core\Process;
|
||||||
|
@ -73,8 +74,8 @@ return [
|
||||||
$_SERVER
|
$_SERVER
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
Util\ConfigFileLoader::class => [
|
Config\Cache\ConfigFileLoader::class => [
|
||||||
'instanceOf' => Factory\ConfigFactory::class,
|
'instanceOf' => Config\Factory\ConfigFactory::class,
|
||||||
'call' => [
|
'call' => [
|
||||||
['createConfigFileLoader', [
|
['createConfigFileLoader', [
|
||||||
[Dice::INSTANCE => '$basepath'],
|
[Dice::INSTANCE => '$basepath'],
|
||||||
|
@ -82,8 +83,8 @@ return [
|
||||||
], Dice::CHAIN_CALL],
|
], Dice::CHAIN_CALL],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
Config\Cache::class => [
|
Config\Cache\Cache::class => [
|
||||||
'instanceOf' => Factory\ConfigFactory::class,
|
'instanceOf' => Config\Factory\ConfigFactory::class,
|
||||||
'call' => [
|
'call' => [
|
||||||
['createCache', [$_SERVER], Dice::CHAIN_CALL],
|
['createCache', [$_SERVER], Dice::CHAIN_CALL],
|
||||||
],
|
],
|
||||||
|
@ -95,15 +96,15 @@ return [
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
Config\IConfig::class => [
|
Config\IConfig::class => [
|
||||||
'instanceOf' => Factory\ConfigFactory::class,
|
'instanceOf' => Config\Factory\ConfigFactory::class,
|
||||||
'call' => [
|
'call' => [
|
||||||
['createConfig', [], Dice::CHAIN_CALL],
|
['create', [], Dice::CHAIN_CALL],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
\Friendica\Core\PConfig\IPConfig::class => [
|
\Friendica\Core\PConfig\IPConfig::class => [
|
||||||
'instanceOf' => Factory\ConfigFactory::class,
|
'instanceOf' => PConfig\Factory\PConfigFactory::class,
|
||||||
'call' => [
|
'call' => [
|
||||||
['createPConfig', [], Dice::CHAIN_CALL],
|
['create', [], Dice::CHAIN_CALL],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
Database::class => [
|
Database::class => [
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
namespace Friendica\Test;
|
namespace Friendica\Test;
|
||||||
|
|
||||||
use Dice\Dice;
|
use Dice\Dice;
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
use Friendica\Core\Config\IConfig;
|
use Friendica\Core\Config\IConfig;
|
||||||
use Friendica\Core\Session;
|
use Friendica\Core\Session;
|
||||||
use Friendica\Core\Session\ISession;
|
use Friendica\Core\Session\ISession;
|
||||||
|
|
|
@ -74,19 +74,19 @@ trait AppMockTrait
|
||||||
$this->dice = \Mockery::mock(Dice::class)->makePartial();
|
$this->dice = \Mockery::mock(Dice::class)->makePartial();
|
||||||
$this->dice = $this->dice->addRules(include __DIR__ . '/../../static/dependencies.config.php');
|
$this->dice = $this->dice->addRules(include __DIR__ . '/../../static/dependencies.config.php');
|
||||||
|
|
||||||
$this->configMock = \Mockery::mock(Config\Cache::class);
|
$this->configMock = \Mockery::mock(Config\Cache\Cache::class);
|
||||||
$this->dice->shouldReceive('create')
|
$this->dice->shouldReceive('create')
|
||||||
->with(Config\Cache::class)
|
->with(Config\Cache\Cache::class)
|
||||||
->andReturn($this->configMock);
|
->andReturn($this->configMock);
|
||||||
$this->mode = \Mockery::mock(App\Mode::class);
|
$this->mode = \Mockery::mock(App\Mode::class);
|
||||||
$this->dice->shouldReceive('create')
|
$this->dice->shouldReceive('create')
|
||||||
->with(App\Mode::class)
|
->with(App\Mode::class)
|
||||||
->andReturn($this->mode);
|
->andReturn($this->mode);
|
||||||
$configModel= \Mockery::mock(\Friendica\Model\Config\Config::class);
|
$configModel= \Mockery::mock(Config\Model\Config::class);
|
||||||
// Disable the adapter
|
// Disable the adapter
|
||||||
$configModel->shouldReceive('isConnected')->andReturn(false);
|
$configModel->shouldReceive('isConnected')->andReturn(false);
|
||||||
|
|
||||||
$config = new Config\JitConfig($this->configMock, $configModel);
|
$config = new Config\Type\JitConfig($this->configMock, $configModel);
|
||||||
$this->dice->shouldReceive('create')
|
$this->dice->shouldReceive('create')
|
||||||
->with(Config\IConfig::class)
|
->with(Config\IConfig::class)
|
||||||
->andReturn($config);
|
->andReturn($config);
|
||||||
|
|
|
@ -25,13 +25,13 @@ use Dice\Dice;
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Core\Cache\ICache;
|
use Friendica\Core\Cache\ICache;
|
||||||
use Friendica\Core\Cache\IMemoryCache;
|
use Friendica\Core\Cache\IMemoryCache;
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
use Friendica\Core\Config\IConfig;
|
use Friendica\Core\Config\IConfig;
|
||||||
use Friendica\Core\Lock\ILock;
|
use Friendica\Core\Lock\ILock;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
use Friendica\Test\Util\VFSTrait;
|
use Friendica\Test\Util\VFSTrait;
|
||||||
use Friendica\Util\BasePath;
|
use Friendica\Util\BasePath;
|
||||||
use Friendica\Util\ConfigFileLoader;
|
use Friendica\Core\Config\Cache\ConfigFileLoader;
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace Friendica\Test\src\App;
|
||||||
use Detection\MobileDetect;
|
use Detection\MobileDetect;
|
||||||
use Friendica\App\Mode;
|
use Friendica\App\Mode;
|
||||||
use Friendica\App\Module;
|
use Friendica\App\Module;
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
use Friendica\Test\MockedTest;
|
use Friendica\Test\MockedTest;
|
||||||
use Friendica\Test\Util\VFSTrait;
|
use Friendica\Test\Util\VFSTrait;
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace Friendica\Test\src\Console;
|
||||||
use Dice\Dice;
|
use Dice\Dice;
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Console\AutomaticInstallation;
|
use Friendica\Console\AutomaticInstallation;
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
use Friendica\Core\Installer;
|
use Friendica\Core\Installer;
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Core\Logger;
|
use Friendica\Core\Logger;
|
||||||
|
@ -53,7 +53,7 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
|
||||||
private $assertFileDb;
|
private $assertFileDb;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Cache The configuration cache to check after each test
|
* @var \Friendica\Core\Config\Cache\Cache The configuration cache to check after each test
|
||||||
*/
|
*/
|
||||||
private $configCache;
|
private $configCache;
|
||||||
|
|
||||||
|
|
|
@ -22,11 +22,10 @@
|
||||||
namespace Friendica\Test\src\Core\Cache;
|
namespace Friendica\Test\src\Core\Cache;
|
||||||
|
|
||||||
use Friendica\Core\Cache;
|
use Friendica\Core\Cache;
|
||||||
use Friendica\Factory\ConfigFactory;
|
use Friendica\Core\Config\Factory\ConfigFactory;
|
||||||
use Friendica\Test\DatabaseTestTrait;
|
use Friendica\Test\DatabaseTestTrait;
|
||||||
use Friendica\Test\Util\Database\StaticDatabase;
|
use Friendica\Test\Util\Database\StaticDatabase;
|
||||||
use Friendica\Test\Util\VFSTrait;
|
use Friendica\Test\Util\VFSTrait;
|
||||||
use Friendica\Util\ConfigFileLoader;
|
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
use Psr\Log\NullLogger;
|
use Psr\Log\NullLogger;
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Test\src\Core\Config;
|
namespace Friendica\Test\src\Core\Config\Cache;
|
||||||
|
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache;
|
||||||
use Friendica\Test\MockedTest;
|
use Friendica\Test\MockedTest;
|
||||||
|
@ -49,7 +49,7 @@ class CacheTest extends MockedTest
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function assertConfigValues($data, Cache $configCache)
|
private function assertConfigValues($data, Cache\Cache $configCache)
|
||||||
{
|
{
|
||||||
foreach ($data as $cat => $values) {
|
foreach ($data as $cat => $values) {
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
|
@ -64,7 +64,7 @@ class CacheTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testLoadConfigArray($data)
|
public function testLoadConfigArray($data)
|
||||||
{
|
{
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
$configCache->load($data);
|
$configCache->load($data);
|
||||||
|
|
||||||
self::assertConfigValues($data, $configCache);
|
self::assertConfigValues($data, $configCache);
|
||||||
|
@ -83,27 +83,27 @@ class CacheTest extends MockedTest
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
$configCache->load($data, Cache::SOURCE_DB);
|
$configCache->load($data, Cache\Cache::SOURCE_DB);
|
||||||
// doesn't override - Low Priority due Config file
|
// doesn't override - Low Priority due Config file
|
||||||
$configCache->load($override, Cache::SOURCE_FILE);
|
$configCache->load($override, Cache\Cache::SOURCE_FILE);
|
||||||
|
|
||||||
self::assertConfigValues($data, $configCache);
|
self::assertConfigValues($data, $configCache);
|
||||||
|
|
||||||
// override the value - High Prio due Server Env
|
// override the value - High Prio due Server Env
|
||||||
$configCache->load($override, Cache::SOURCE_ENV);
|
$configCache->load($override, Cache\Cache::SOURCE_ENV);
|
||||||
|
|
||||||
self::assertEquals($override['system']['test'], $configCache->get('system', 'test'));
|
self::assertEquals($override['system']['test'], $configCache->get('system', 'test'));
|
||||||
self::assertEquals($override['system']['boolTrue'], $configCache->get('system', 'boolTrue'));
|
self::assertEquals($override['system']['boolTrue'], $configCache->get('system', 'boolTrue'));
|
||||||
|
|
||||||
// Don't overwrite server ENV variables - even in load mode
|
// Don't overwrite server ENV variables - even in load mode
|
||||||
$configCache->load($data, Cache::SOURCE_DB);
|
$configCache->load($data, Cache\Cache::SOURCE_DB);
|
||||||
|
|
||||||
self::assertEquals($override['system']['test'], $configCache->get('system', 'test'));
|
self::assertEquals($override['system']['test'], $configCache->get('system', 'test'));
|
||||||
self::assertEquals($override['system']['boolTrue'], $configCache->get('system', 'boolTrue'));
|
self::assertEquals($override['system']['boolTrue'], $configCache->get('system', 'boolTrue'));
|
||||||
|
|
||||||
// Overwrite ENV variables with ENV variables
|
// Overwrite ENV variables with ENV variables
|
||||||
$configCache->load($data, Cache::SOURCE_ENV);
|
$configCache->load($data, Cache\Cache::SOURCE_ENV);
|
||||||
|
|
||||||
self::assertConfigValues($data, $configCache);
|
self::assertConfigValues($data, $configCache);
|
||||||
self::assertNotEquals($override['system']['test'], $configCache->get('system', 'test'));
|
self::assertNotEquals($override['system']['test'], $configCache->get('system', 'test'));
|
||||||
|
@ -115,7 +115,7 @@ class CacheTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testLoadConfigArrayWrong()
|
public function testLoadConfigArrayWrong()
|
||||||
{
|
{
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
|
|
||||||
// empty dataset
|
// empty dataset
|
||||||
$configCache->load([]);
|
$configCache->load([]);
|
||||||
|
@ -136,7 +136,7 @@ class CacheTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testGetAll($data)
|
public function testGetAll($data)
|
||||||
{
|
{
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
$configCache->load($data);
|
$configCache->load($data);
|
||||||
|
|
||||||
$all = $configCache->getAll();
|
$all = $configCache->getAll();
|
||||||
|
@ -151,7 +151,7 @@ class CacheTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testSetGet($data)
|
public function testSetGet($data)
|
||||||
{
|
{
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
|
|
||||||
foreach ($data as $cat => $values) {
|
foreach ($data as $cat => $values) {
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
|
@ -167,7 +167,7 @@ class CacheTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testGetEmpty()
|
public function testGetEmpty()
|
||||||
{
|
{
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
|
|
||||||
self::assertNull($configCache->get('something', 'value'));
|
self::assertNull($configCache->get('something', 'value'));
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ class CacheTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testGetCat()
|
public function testGetCat()
|
||||||
{
|
{
|
||||||
$configCache = new Cache([
|
$configCache = new Cache\Cache([
|
||||||
'system' => [
|
'system' => [
|
||||||
'key1' => 'value1',
|
'key1' => 'value1',
|
||||||
'key2' => 'value2',
|
'key2' => 'value2',
|
||||||
|
@ -205,7 +205,7 @@ class CacheTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testDelete($data)
|
public function testDelete($data)
|
||||||
{
|
{
|
||||||
$configCache = new Cache($data);
|
$configCache = new Cache\Cache($data);
|
||||||
|
|
||||||
foreach ($data as $cat => $values) {
|
foreach ($data as $cat => $values) {
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
|
@ -222,7 +222,7 @@ class CacheTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testKeyDiffWithResult($data)
|
public function testKeyDiffWithResult($data)
|
||||||
{
|
{
|
||||||
$configCache = new Cache($data);
|
$configCache = new Cache\Cache($data);
|
||||||
|
|
||||||
$diffConfig = [
|
$diffConfig = [
|
||||||
'fakeCat' => [
|
'fakeCat' => [
|
||||||
|
@ -239,7 +239,7 @@ class CacheTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testKeyDiffWithoutResult($data)
|
public function testKeyDiffWithoutResult($data)
|
||||||
{
|
{
|
||||||
$configCache = new Cache($data);
|
$configCache = new Cache\Cache($data);
|
||||||
|
|
||||||
$diffConfig = $configCache->getAll();
|
$diffConfig = $configCache->getAll();
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@ class CacheTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testPasswordHide()
|
public function testPasswordHide()
|
||||||
{
|
{
|
||||||
$configCache = new Cache([
|
$configCache = new Cache\Cache([
|
||||||
'database' => [
|
'database' => [
|
||||||
'password' => 'supersecure',
|
'password' => 'supersecure',
|
||||||
'username' => 'notsecured',
|
'username' => 'notsecured',
|
||||||
|
@ -268,7 +268,7 @@ class CacheTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testPasswordShow()
|
public function testPasswordShow()
|
||||||
{
|
{
|
||||||
$configCache = new Cache([
|
$configCache = new Cache\Cache([
|
||||||
'database' => [
|
'database' => [
|
||||||
'password' => 'supersecure',
|
'password' => 'supersecure',
|
||||||
'username' => 'notsecured',
|
'username' => 'notsecured',
|
||||||
|
@ -285,7 +285,7 @@ class CacheTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testEmptyPassword()
|
public function testEmptyPassword()
|
||||||
{
|
{
|
||||||
$configCache = new Cache([
|
$configCache = new Cache\Cache([
|
||||||
'database' => [
|
'database' => [
|
||||||
'password' => '',
|
'password' => '',
|
||||||
'username' => '',
|
'username' => '',
|
||||||
|
@ -299,7 +299,7 @@ class CacheTest extends MockedTest
|
||||||
|
|
||||||
public function testWrongTypePassword()
|
public function testWrongTypePassword()
|
||||||
{
|
{
|
||||||
$configCache = new Cache([
|
$configCache = new Cache\Cache([
|
||||||
'database' => [
|
'database' => [
|
||||||
'password' => new stdClass(),
|
'password' => new stdClass(),
|
||||||
'username' => '',
|
'username' => '',
|
||||||
|
@ -309,7 +309,7 @@ class CacheTest extends MockedTest
|
||||||
self::assertNotEmpty($configCache->get('database', 'password'));
|
self::assertNotEmpty($configCache->get('database', 'password'));
|
||||||
self::assertEmpty($configCache->get('database', 'username'));
|
self::assertEmpty($configCache->get('database', 'username'));
|
||||||
|
|
||||||
$configCache = new Cache([
|
$configCache = new Cache\Cache([
|
||||||
'database' => [
|
'database' => [
|
||||||
'password' => 23,
|
'password' => 23,
|
||||||
'username' => '',
|
'username' => '',
|
||||||
|
@ -327,19 +327,19 @@ class CacheTest extends MockedTest
|
||||||
public function testSetOverrides($data)
|
public function testSetOverrides($data)
|
||||||
{
|
{
|
||||||
|
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
$configCache->load($data, Cache::SOURCE_DB);
|
$configCache->load($data, Cache\Cache::SOURCE_DB);
|
||||||
|
|
||||||
// test with wrong override
|
// test with wrong override
|
||||||
self::assertFalse($configCache->set('system', 'test', '1234567', Cache::SOURCE_FILE));
|
self::assertFalse($configCache->set('system', 'test', '1234567', Cache\Cache::SOURCE_FILE));
|
||||||
self::assertEquals($data['system']['test'], $configCache->get('system', 'test'));
|
self::assertEquals($data['system']['test'], $configCache->get('system', 'test'));
|
||||||
|
|
||||||
// test with override (equal)
|
// test with override (equal)
|
||||||
self::assertTrue($configCache->set('system', 'test', '8910', Cache::SOURCE_DB));
|
self::assertTrue($configCache->set('system', 'test', '8910', Cache\Cache::SOURCE_DB));
|
||||||
self::assertEquals('8910', $configCache->get('system', 'test'));
|
self::assertEquals('8910', $configCache->get('system', 'test'));
|
||||||
|
|
||||||
// test with override (over)
|
// test with override (over)
|
||||||
self::assertTrue($configCache->set('system', 'test', '111213', Cache::SOURCE_ENV));
|
self::assertTrue($configCache->set('system', 'test', '111213', Cache\Cache::SOURCE_ENV));
|
||||||
self::assertEquals('111213', $configCache->get('system', 'test'));
|
self::assertEquals('111213', $configCache->get('system', 'test'));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,13 +19,13 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Test\src\Util\Config;
|
namespace Friendica\Test\src\Core\Config\Cache;
|
||||||
|
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache;
|
||||||
use Friendica\Factory\ConfigFactory;
|
use Friendica\Core\Config\Factory\ConfigFactory;
|
||||||
use Friendica\Test\MockedTest;
|
use Friendica\Test\MockedTest;
|
||||||
use Friendica\Test\Util\VFSTrait;
|
use Friendica\Test\Util\VFSTrait;
|
||||||
use Friendica\Util\ConfigFileLoader;
|
use Friendica\Core\Config\Cache\ConfigFileLoader;
|
||||||
use org\bovigo\vfs\vfsStream;
|
use org\bovigo\vfs\vfsStream;
|
||||||
|
|
||||||
class ConfigFileLoaderTest extends MockedTest
|
class ConfigFileLoaderTest extends MockedTest
|
||||||
|
@ -51,7 +51,7 @@ class ConfigFileLoaderTest extends MockedTest
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
|
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
|
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
|
||||||
);
|
);
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
|
|
||||||
$configFileLoader->setupCache($configCache);
|
$configFileLoader->setupCache($configCache);
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ class ConfigFileLoaderTest extends MockedTest
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
|
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
|
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
|
||||||
);
|
);
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
|
|
||||||
$configFileLoader->setupCache($configCache);
|
$configFileLoader->setupCache($configCache);
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,7 @@ class ConfigFileLoaderTest extends MockedTest
|
||||||
$this->delConfigFile('local.config.php');
|
$this->delConfigFile('local.config.php');
|
||||||
|
|
||||||
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||||
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'datasets' . DIRECTORY_SEPARATOR .
|
'datasets' . DIRECTORY_SEPARATOR .
|
||||||
|
@ -105,7 +106,7 @@ class ConfigFileLoaderTest extends MockedTest
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
|
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
|
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
|
||||||
);
|
);
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
|
|
||||||
$configFileLoader->setupCache($configCache);
|
$configFileLoader->setupCache($configCache);
|
||||||
|
|
||||||
|
@ -126,6 +127,7 @@ class ConfigFileLoaderTest extends MockedTest
|
||||||
$this->delConfigFile('local.config.php');
|
$this->delConfigFile('local.config.php');
|
||||||
|
|
||||||
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||||
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'datasets' . DIRECTORY_SEPARATOR .
|
'datasets' . DIRECTORY_SEPARATOR .
|
||||||
|
@ -141,7 +143,7 @@ class ConfigFileLoaderTest extends MockedTest
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
|
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
|
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
|
||||||
);
|
);
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
|
|
||||||
$configFileLoader->setupCache($configCache);
|
$configFileLoader->setupCache($configCache);
|
||||||
|
|
||||||
|
@ -161,6 +163,7 @@ class ConfigFileLoaderTest extends MockedTest
|
||||||
$this->delConfigFile('local.config.php');
|
$this->delConfigFile('local.config.php');
|
||||||
|
|
||||||
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||||
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'datasets' . DIRECTORY_SEPARATOR .
|
'datasets' . DIRECTORY_SEPARATOR .
|
||||||
|
@ -176,7 +179,7 @@ class ConfigFileLoaderTest extends MockedTest
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
|
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
|
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
|
||||||
);
|
);
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
|
|
||||||
$configFileLoader->setupCache($configCache);
|
$configFileLoader->setupCache($configCache);
|
||||||
|
|
||||||
|
@ -214,6 +217,7 @@ class ConfigFileLoaderTest extends MockedTest
|
||||||
vfsStream::create($structure, $this->root);
|
vfsStream::create($structure, $this->root);
|
||||||
|
|
||||||
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||||
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'datasets' . DIRECTORY_SEPARATOR .
|
'datasets' . DIRECTORY_SEPARATOR .
|
||||||
|
@ -250,6 +254,7 @@ class ConfigFileLoaderTest extends MockedTest
|
||||||
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'datasets' . DIRECTORY_SEPARATOR .
|
'datasets' . DIRECTORY_SEPARATOR .
|
||||||
'config' . DIRECTORY_SEPARATOR;
|
'config' . DIRECTORY_SEPARATOR;
|
||||||
|
|
||||||
|
@ -265,7 +270,7 @@ class ConfigFileLoaderTest extends MockedTest
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
|
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
|
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
|
||||||
);
|
);
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
|
|
||||||
$configFileLoader->setupCache($configCache);
|
$configFileLoader->setupCache($configCache);
|
||||||
|
|
||||||
|
@ -281,6 +286,7 @@ class ConfigFileLoaderTest extends MockedTest
|
||||||
$this->delConfigFile('local.config.php');
|
$this->delConfigFile('local.config.php');
|
||||||
|
|
||||||
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||||
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'datasets' . DIRECTORY_SEPARATOR .
|
'datasets' . DIRECTORY_SEPARATOR .
|
||||||
|
@ -298,7 +304,7 @@ class ConfigFileLoaderTest extends MockedTest
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
|
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
|
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
|
||||||
);
|
);
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
|
|
||||||
$configFileLoader->setupCache($configCache);
|
$configFileLoader->setupCache($configCache);
|
||||||
|
|
||||||
|
@ -316,6 +322,7 @@ class ConfigFileLoaderTest extends MockedTest
|
||||||
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'datasets' . DIRECTORY_SEPARATOR .
|
'datasets' . DIRECTORY_SEPARATOR .
|
||||||
'config' . DIRECTORY_SEPARATOR;
|
'config' . DIRECTORY_SEPARATOR;
|
||||||
|
|
||||||
|
@ -331,7 +338,7 @@ class ConfigFileLoaderTest extends MockedTest
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
|
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
|
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
|
||||||
);
|
);
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
|
|
||||||
$configFileLoader->setupCache($configCache);
|
$configFileLoader->setupCache($configCache);
|
||||||
|
|
||||||
|
@ -347,7 +354,7 @@ class ConfigFileLoaderTest extends MockedTest
|
||||||
$this->delConfigFile('local.config.php');
|
$this->delConfigFile('local.config.php');
|
||||||
|
|
||||||
$configFileLoader = (new ConfigFactory())->createConfigFileLoader($this->root->url(), ['FRIENDICA_CONFIG_DIR' => '/a/wrong/dir/']);
|
$configFileLoader = (new ConfigFactory())->createConfigFileLoader($this->root->url(), ['FRIENDICA_CONFIG_DIR' => '/a/wrong/dir/']);
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
|
|
||||||
$configFileLoader->setupCache($configCache);
|
$configFileLoader->setupCache($configCache);
|
||||||
|
|
||||||
|
@ -362,6 +369,7 @@ class ConfigFileLoaderTest extends MockedTest
|
||||||
$this->delConfigFile('local.config.php');
|
$this->delConfigFile('local.config.php');
|
||||||
|
|
||||||
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||||
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'datasets' . DIRECTORY_SEPARATOR .
|
'datasets' . DIRECTORY_SEPARATOR .
|
||||||
|
@ -372,7 +380,7 @@ class ConfigFileLoaderTest extends MockedTest
|
||||||
->setContent(file_get_contents($fileDir . 'B.config.php'));
|
->setContent(file_get_contents($fileDir . 'B.config.php'));
|
||||||
|
|
||||||
$configFileLoader = (new ConfigFactory())->createConfigFileLoader($this->root->url(), ['FRIENDICA_CONFIG_DIR' => $this->root->getChild('config2')->url()]);
|
$configFileLoader = (new ConfigFactory())->createConfigFileLoader($this->root->url(), ['FRIENDICA_CONFIG_DIR' => $this->root->getChild('config2')->url()]);
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
|
|
||||||
$configFileLoader->setupCache($configCache);
|
$configFileLoader->setupCache($configCache);
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace Friendica\Test\src\Core\Config;
|
||||||
|
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache;
|
||||||
use Friendica\Core\Config\IConfig;
|
use Friendica\Core\Config\IConfig;
|
||||||
use Friendica\Model\Config\Config as ConfigModel;
|
use Friendica\Core\Config\Model\Config as ConfigModel;
|
||||||
use Friendica\Test\MockedTest;
|
use Friendica\Test\MockedTest;
|
||||||
use Mockery\MockInterface;
|
use Mockery\MockInterface;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
|
@ -33,7 +33,7 @@ abstract class ConfigTest extends MockedTest
|
||||||
/** @var ConfigModel|MockInterface */
|
/** @var ConfigModel|MockInterface */
|
||||||
protected $configModel;
|
protected $configModel;
|
||||||
|
|
||||||
/** @var Cache */
|
/** @var Cache\Cache */
|
||||||
protected $configCache;
|
protected $configCache;
|
||||||
|
|
||||||
/** @var IConfig */
|
/** @var IConfig */
|
||||||
|
@ -61,7 +61,7 @@ abstract class ConfigTest extends MockedTest
|
||||||
|
|
||||||
// Create the config model
|
// Create the config model
|
||||||
$this->configModel = Mockery::mock(ConfigModel::class);
|
$this->configModel = Mockery::mock(ConfigModel::class);
|
||||||
$this->configCache = new Cache();
|
$this->configCache = new Cache\Cache();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -161,7 +161,7 @@ abstract class ConfigTest extends MockedTest
|
||||||
->once();
|
->once();
|
||||||
|
|
||||||
$this->testedConfig = $this->getInstance();
|
$this->testedConfig = $this->getInstance();
|
||||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
|
||||||
|
|
||||||
// assert config is loaded everytime
|
// assert config is loaded everytime
|
||||||
self::assertConfig('config', $data['config']);
|
self::assertConfig('config', $data['config']);
|
||||||
|
@ -176,7 +176,7 @@ abstract class ConfigTest extends MockedTest
|
||||||
public function testLoad(array $data, array $load)
|
public function testLoad(array $data, array $load)
|
||||||
{
|
{
|
||||||
$this->testedConfig = $this->getInstance();
|
$this->testedConfig = $this->getInstance();
|
||||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
|
||||||
|
|
||||||
foreach ($load as $loadedCats) {
|
foreach ($load as $loadedCats) {
|
||||||
$this->testedConfig->load($loadedCats);
|
$this->testedConfig->load($loadedCats);
|
||||||
|
@ -257,7 +257,7 @@ abstract class ConfigTest extends MockedTest
|
||||||
public function testCacheLoadDouble(array $data1, array $data2, array $expect = [])
|
public function testCacheLoadDouble(array $data1, array $data2, array $expect = [])
|
||||||
{
|
{
|
||||||
$this->testedConfig = $this->getInstance();
|
$this->testedConfig = $this->getInstance();
|
||||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
|
||||||
|
|
||||||
foreach ($data1 as $cat => $data) {
|
foreach ($data1 as $cat => $data) {
|
||||||
$this->testedConfig->load($cat);
|
$this->testedConfig->load($cat);
|
||||||
|
@ -282,7 +282,7 @@ abstract class ConfigTest extends MockedTest
|
||||||
$this->configModel->shouldReceive('load')->withAnyArgs()->andReturn([])->once();
|
$this->configModel->shouldReceive('load')->withAnyArgs()->andReturn([])->once();
|
||||||
|
|
||||||
$this->testedConfig = $this->getInstance();
|
$this->testedConfig = $this->getInstance();
|
||||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
|
||||||
|
|
||||||
self::assertEmpty($this->testedConfig->getCache()->getAll());
|
self::assertEmpty($this->testedConfig->getCache()->getAll());
|
||||||
}
|
}
|
||||||
|
@ -299,7 +299,7 @@ abstract class ConfigTest extends MockedTest
|
||||||
->times(3);
|
->times(3);
|
||||||
|
|
||||||
$this->testedConfig = $this->getInstance();
|
$this->testedConfig = $this->getInstance();
|
||||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
|
||||||
|
|
||||||
self::assertTrue($this->testedConfig->set('test', 'it', $data));
|
self::assertTrue($this->testedConfig->set('test', 'it', $data));
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@ abstract class ConfigTest extends MockedTest
|
||||||
$this->configModel->shouldReceive('set')->with('test', 'it', $data)->andReturn(true)->once();
|
$this->configModel->shouldReceive('set')->with('test', 'it', $data)->andReturn(true)->once();
|
||||||
|
|
||||||
$this->testedConfig = $this->getInstance();
|
$this->testedConfig = $this->getInstance();
|
||||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
|
||||||
|
|
||||||
self::assertTrue($this->testedConfig->set('test', 'it', $data));
|
self::assertTrue($this->testedConfig->set('test', 'it', $data));
|
||||||
|
|
||||||
|
@ -331,7 +331,7 @@ abstract class ConfigTest extends MockedTest
|
||||||
public function testGetWrongWithoutDB()
|
public function testGetWrongWithoutDB()
|
||||||
{
|
{
|
||||||
$this->testedConfig = $this->getInstance();
|
$this->testedConfig = $this->getInstance();
|
||||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
|
||||||
|
|
||||||
// without refresh
|
// without refresh
|
||||||
self::assertNull($this->testedConfig->get('test', 'it'));
|
self::assertNull($this->testedConfig->get('test', 'it'));
|
||||||
|
@ -353,10 +353,10 @@ abstract class ConfigTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testGetWithRefresh($data)
|
public function testGetWithRefresh($data)
|
||||||
{
|
{
|
||||||
$this->configCache->load(['test' => ['it' => 'now']], Cache::SOURCE_FILE);
|
$this->configCache->load(['test' => ['it' => 'now']], Cache\Cache::SOURCE_FILE);
|
||||||
|
|
||||||
$this->testedConfig = $this->getInstance();
|
$this->testedConfig = $this->getInstance();
|
||||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
|
||||||
|
|
||||||
// without refresh
|
// without refresh
|
||||||
self::assertEquals('now', $this->testedConfig->get('test', 'it'));
|
self::assertEquals('now', $this->testedConfig->get('test', 'it'));
|
||||||
|
@ -378,10 +378,10 @@ abstract class ConfigTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testDeleteWithoutDB($data)
|
public function testDeleteWithoutDB($data)
|
||||||
{
|
{
|
||||||
$this->configCache->load(['test' => ['it' => $data]], Cache::SOURCE_FILE);
|
$this->configCache->load(['test' => ['it' => $data]], Cache\Cache::SOURCE_FILE);
|
||||||
|
|
||||||
$this->testedConfig = $this->getInstance();
|
$this->testedConfig = $this->getInstance();
|
||||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
|
||||||
|
|
||||||
self::assertEquals($data, $this->testedConfig->get('test', 'it'));
|
self::assertEquals($data, $this->testedConfig->get('test', 'it'));
|
||||||
self::assertEquals($data, $this->testedConfig->getCache()->get('test', 'it'));
|
self::assertEquals($data, $this->testedConfig->getCache()->get('test', 'it'));
|
||||||
|
@ -398,7 +398,7 @@ abstract class ConfigTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testDeleteWithDB()
|
public function testDeleteWithDB()
|
||||||
{
|
{
|
||||||
$this->configCache->load(['test' => ['it' => 'now', 'quarter' => 'true']], Cache::SOURCE_FILE);
|
$this->configCache->load(['test' => ['it' => 'now', 'quarter' => 'true']], Cache\Cache::SOURCE_FILE);
|
||||||
|
|
||||||
$this->configModel->shouldReceive('delete')
|
$this->configModel->shouldReceive('delete')
|
||||||
->with('test', 'it')
|
->with('test', 'it')
|
||||||
|
@ -418,7 +418,7 @@ abstract class ConfigTest extends MockedTest
|
||||||
->once();
|
->once();
|
||||||
|
|
||||||
$this->testedConfig = $this->getInstance();
|
$this->testedConfig = $this->getInstance();
|
||||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
|
||||||
|
|
||||||
// directly set the value to the cache
|
// directly set the value to the cache
|
||||||
$this->testedConfig->getCache()->set('test', 'it', 'now');
|
$this->testedConfig->getCache()->set('test', 'it', 'now');
|
||||||
|
@ -444,9 +444,9 @@ abstract class ConfigTest extends MockedTest
|
||||||
public function testSetGetHighPrio()
|
public function testSetGetHighPrio()
|
||||||
{
|
{
|
||||||
$this->testedConfig = $this->getInstance();
|
$this->testedConfig = $this->getInstance();
|
||||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
|
||||||
|
|
||||||
$this->testedConfig->getCache()->set('config', 'test', 'prio', Cache::SOURCE_FILE);
|
$this->testedConfig->getCache()->set('config', 'test', 'prio', Cache\Cache::SOURCE_FILE);
|
||||||
self::assertEquals('prio', $this->testedConfig->get('config', 'test'));
|
self::assertEquals('prio', $this->testedConfig->get('config', 'test'));
|
||||||
|
|
||||||
// now you have to get the new variable entry because of the new set the get refresh succeed as well
|
// now you have to get the new variable entry because of the new set the get refresh succeed as well
|
||||||
|
@ -460,10 +460,10 @@ abstract class ConfigTest extends MockedTest
|
||||||
public function testSetGetLowPrio()
|
public function testSetGetLowPrio()
|
||||||
{
|
{
|
||||||
$this->testedConfig = $this->getInstance();
|
$this->testedConfig = $this->getInstance();
|
||||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
|
||||||
self::assertEquals('it', $this->testedConfig->get('config', 'test'));
|
self::assertEquals('it', $this->testedConfig->get('config', 'test'));
|
||||||
|
|
||||||
$this->testedConfig->getCache()->set('config', 'test', 'prio', Cache::SOURCE_ENV);
|
$this->testedConfig->getCache()->set('config', 'test', 'prio', Cache\Cache::SOURCE_ENV);
|
||||||
// now you have to get the env variable entry as output, even with a new set (which failed) and a get refresh
|
// now you have to get the env variable entry as output, even with a new set (which failed) and a get refresh
|
||||||
self::assertFalse($this->testedConfig->set('config', 'test', '123'));
|
self::assertFalse($this->testedConfig->set('config', 'test', '123'));
|
||||||
self::assertEquals('prio', $this->testedConfig->get('config', 'test', '', true));
|
self::assertEquals('prio', $this->testedConfig->get('config', 'test', '', true));
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
namespace Friendica\Test\src\Core\Config;
|
namespace Friendica\Test\src\Core\Config;
|
||||||
|
|
||||||
use Friendica\Core\Config\JitConfig;
|
use Friendica\Core\Config\Type\JitConfig;
|
||||||
|
|
||||||
class JitConfigTest extends ConfigTest
|
class JitConfigTest extends ConfigTest
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
namespace Friendica\Test\src\Core\Config;
|
namespace Friendica\Test\src\Core\Config;
|
||||||
|
|
||||||
use Friendica\Core\Config\PreloadConfig;
|
use Friendica\Core\Config\Type\PreloadConfig;
|
||||||
|
|
||||||
class PreloadConfigTest extends ConfigTest
|
class PreloadConfigTest extends ConfigTest
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
namespace Friendica\Core;
|
namespace Friendica\Core;
|
||||||
|
|
||||||
use Dice\Dice;
|
use Dice\Dice;
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Network\IHTTPResult;
|
use Friendica\Network\IHTTPResult;
|
||||||
use Friendica\Network\IHTTPClient;
|
use Friendica\Network\IHTTPClient;
|
||||||
|
|
|
@ -22,11 +22,10 @@
|
||||||
namespace Friendica\Test\src\Core\Lock;
|
namespace Friendica\Test\src\Core\Lock;
|
||||||
|
|
||||||
use Friendica\Core\Lock\DatabaseLock;
|
use Friendica\Core\Lock\DatabaseLock;
|
||||||
use Friendica\Factory\ConfigFactory;
|
use Friendica\Core\Config\Factory\ConfigFactory;
|
||||||
use Friendica\Test\DatabaseTestTrait;
|
use Friendica\Test\DatabaseTestTrait;
|
||||||
use Friendica\Test\Util\Database\StaticDatabase;
|
use Friendica\Test\Util\Database\StaticDatabase;
|
||||||
use Friendica\Test\Util\VFSTrait;
|
use Friendica\Test\Util\VFSTrait;
|
||||||
use Friendica\Util\ConfigFileLoader;
|
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
use Psr\Log\NullLogger;
|
use Psr\Log\NullLogger;
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace Friendica\Test\src\Core\Lock;
|
||||||
use Dice\Dice;
|
use Dice\Dice;
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Core\Config\IConfig;
|
use Friendica\Core\Config\IConfig;
|
||||||
use Friendica\Core\Config\JitConfig;
|
use Friendica\Core\Config\Type\JitConfig;
|
||||||
use Friendica\Core\Lock\SemaphoreLock;
|
use Friendica\Core\Lock\SemaphoreLock;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Test\src\Core\PConfig;
|
namespace Friendica\Test\src\Core\PConfig\Cache;
|
||||||
|
|
||||||
use Friendica\Core\PConfig\Cache;
|
use Friendica\Core\PConfig\Cache;
|
||||||
use Friendica\Test\MockedTest;
|
use Friendica\Test\MockedTest;
|
||||||
|
@ -47,7 +47,7 @@ class CacheTest extends MockedTest
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function assertConfigValues($data, Cache $configCache, $uid)
|
private function assertConfigValues($data, Cache\Cache $configCache, $uid)
|
||||||
{
|
{
|
||||||
foreach ($data as $cat => $values) {
|
foreach ($data as $cat => $values) {
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
|
@ -63,7 +63,7 @@ class CacheTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testSetGet($data)
|
public function testSetGet($data)
|
||||||
{
|
{
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
$uid = 345;
|
$uid = 345;
|
||||||
|
|
||||||
foreach ($data as $cat => $values) {
|
foreach ($data as $cat => $values) {
|
||||||
|
@ -81,7 +81,7 @@ class CacheTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testGetCat()
|
public function testGetCat()
|
||||||
{
|
{
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
$uid = 345;
|
$uid = 345;
|
||||||
|
|
||||||
$configCache->load($uid, [
|
$configCache->load($uid, [
|
||||||
|
@ -113,7 +113,7 @@ class CacheTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testDelete($data)
|
public function testDelete($data)
|
||||||
{
|
{
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
$uid = 345;
|
$uid = 345;
|
||||||
|
|
||||||
foreach ($data as $cat => $values) {
|
foreach ($data as $cat => $values) {
|
||||||
|
@ -136,7 +136,7 @@ class CacheTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testKeyDiffWithResult()
|
public function testKeyDiffWithResult()
|
||||||
{
|
{
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
|
|
||||||
$diffConfig = [
|
$diffConfig = [
|
||||||
'fakeCat' => [
|
'fakeCat' => [
|
||||||
|
@ -154,7 +154,7 @@ class CacheTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testKeyDiffWithoutResult($data)
|
public function testKeyDiffWithoutResult($data)
|
||||||
{
|
{
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
|
|
||||||
$configCache->load(1, $data);
|
$configCache->load(1, $data);
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ class CacheTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testPasswordHide()
|
public function testPasswordHide()
|
||||||
{
|
{
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
|
|
||||||
$configCache->load(1, [
|
$configCache->load(1, [
|
||||||
'database' => [
|
'database' => [
|
||||||
|
@ -187,7 +187,7 @@ class CacheTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testPasswordShow()
|
public function testPasswordShow()
|
||||||
{
|
{
|
||||||
$configCache = new Cache(false);
|
$configCache = new Cache\Cache(false);
|
||||||
|
|
||||||
$configCache->load(1, [
|
$configCache->load(1, [
|
||||||
'database' => [
|
'database' => [
|
||||||
|
@ -206,7 +206,7 @@ class CacheTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testEmptyPassword()
|
public function testEmptyPassword()
|
||||||
{
|
{
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
|
|
||||||
$configCache->load(1, [
|
$configCache->load(1, [
|
||||||
'database' => [
|
'database' => [
|
||||||
|
@ -221,7 +221,7 @@ class CacheTest extends MockedTest
|
||||||
|
|
||||||
public function testWrongTypePassword()
|
public function testWrongTypePassword()
|
||||||
{
|
{
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
|
|
||||||
$configCache->load(1, [
|
$configCache->load(1, [
|
||||||
'database' => [
|
'database' => [
|
||||||
|
@ -233,7 +233,7 @@ class CacheTest extends MockedTest
|
||||||
self::assertNotEmpty($configCache->get(1, 'database', 'password'));
|
self::assertNotEmpty($configCache->get(1, 'database', 'password'));
|
||||||
self::assertEmpty($configCache->get(1, 'database', 'username'));
|
self::assertEmpty($configCache->get(1, 'database', 'username'));
|
||||||
|
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
|
|
||||||
$configCache->load(1, [
|
$configCache->load(1, [
|
||||||
'database' => [
|
'database' => [
|
||||||
|
@ -251,7 +251,7 @@ class CacheTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function testTwoUid()
|
public function testTwoUid()
|
||||||
{
|
{
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
|
|
||||||
$configCache->load(1, [
|
$configCache->load(1, [
|
||||||
'cat1' => [
|
'cat1' => [
|
||||||
|
@ -282,7 +282,7 @@ class CacheTest extends MockedTest
|
||||||
// bad UID!
|
// bad UID!
|
||||||
$uid = null;
|
$uid = null;
|
||||||
|
|
||||||
$configCache = new Cache();
|
$configCache = new Cache\Cache();
|
||||||
|
|
||||||
self::assertNull($configCache->get($uid, 'cat1', 'cat2'));
|
self::assertNull($configCache->get($uid, 'cat1', 'cat2'));
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
namespace Friendica\Test\src\Core\PConfig;
|
namespace Friendica\Test\src\Core\PConfig;
|
||||||
|
|
||||||
use Friendica\Core\PConfig\JitPConfig;
|
use Friendica\Core\PConfig\Type\JitPConfig;
|
||||||
|
|
||||||
class JitPConfigTest extends PConfigTest
|
class JitPConfigTest extends PConfigTest
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,8 +22,8 @@
|
||||||
namespace Friendica\Test\src\Core\PConfig;
|
namespace Friendica\Test\src\Core\PConfig;
|
||||||
|
|
||||||
use Friendica\Core\PConfig\Cache;
|
use Friendica\Core\PConfig\Cache;
|
||||||
use Friendica\Core\BasePConfig;
|
use Friendica\Core\PConfig\Type\BasePConfig;
|
||||||
use Friendica\Model\Config\PConfig as PConfigModel;
|
use Friendica\Core\PConfig\Model\PConfig as PConfigModel;
|
||||||
use Friendica\Test\MockedTest;
|
use Friendica\Test\MockedTest;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
use Mockery\MockInterface;
|
use Mockery\MockInterface;
|
||||||
|
@ -33,7 +33,7 @@ abstract class PConfigTest extends MockedTest
|
||||||
/** @var PConfigModel|MockInterface */
|
/** @var PConfigModel|MockInterface */
|
||||||
protected $configModel;
|
protected $configModel;
|
||||||
|
|
||||||
/** @var Cache */
|
/** @var Cache\Cache */
|
||||||
protected $configCache;
|
protected $configCache;
|
||||||
|
|
||||||
/** @var BasePConfig */
|
/** @var BasePConfig */
|
||||||
|
@ -63,11 +63,11 @@ abstract class PConfigTest extends MockedTest
|
||||||
|
|
||||||
// Create the config model
|
// Create the config model
|
||||||
$this->configModel = Mockery::mock(PConfigModel::class);
|
$this->configModel = Mockery::mock(PConfigModel::class);
|
||||||
$this->configCache = new Cache();
|
$this->configCache = new Cache\Cache();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return BasePConfig
|
* @return \Friendica\Core\PConfig\Type\BasePConfig
|
||||||
*/
|
*/
|
||||||
abstract public function getInstance();
|
abstract public function getInstance();
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ abstract class PConfigTest extends MockedTest
|
||||||
public function testSetUp()
|
public function testSetUp()
|
||||||
{
|
{
|
||||||
$this->testedConfig = $this->getInstance();
|
$this->testedConfig = $this->getInstance();
|
||||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
|
||||||
|
|
||||||
self::assertEmpty($this->testedConfig->getCache()->getAll());
|
self::assertEmpty($this->testedConfig->getCache()->getAll());
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ abstract class PConfigTest extends MockedTest
|
||||||
public function testLoad(int $uid, array $data, array $possibleCats, array $load)
|
public function testLoad(int $uid, array $data, array $possibleCats, array $load)
|
||||||
{
|
{
|
||||||
$this->testedConfig = $this->getInstance();
|
$this->testedConfig = $this->getInstance();
|
||||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
|
||||||
|
|
||||||
foreach ($load as $loadedCats) {
|
foreach ($load as $loadedCats) {
|
||||||
$this->testedConfig->load($uid, $loadedCats);
|
$this->testedConfig->load($uid, $loadedCats);
|
||||||
|
@ -257,7 +257,7 @@ abstract class PConfigTest extends MockedTest
|
||||||
public function testCacheLoadDouble(int $uid, array $data1, array $data2, array $expect)
|
public function testCacheLoadDouble(int $uid, array $data1, array $data2, array $expect)
|
||||||
{
|
{
|
||||||
$this->testedConfig = $this->getInstance();
|
$this->testedConfig = $this->getInstance();
|
||||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
|
||||||
|
|
||||||
foreach ($data1 as $cat => $data) {
|
foreach ($data1 as $cat => $data) {
|
||||||
$this->testedConfig->load($uid, $cat);
|
$this->testedConfig->load($uid, $cat);
|
||||||
|
@ -281,7 +281,7 @@ abstract class PConfigTest extends MockedTest
|
||||||
public function testSetGetWithoutDB(int $uid, $data)
|
public function testSetGetWithoutDB(int $uid, $data)
|
||||||
{
|
{
|
||||||
$this->testedConfig = $this->getInstance();
|
$this->testedConfig = $this->getInstance();
|
||||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
|
||||||
|
|
||||||
self::assertTrue($this->testedConfig->set($uid, 'test', 'it', $data));
|
self::assertTrue($this->testedConfig->set($uid, 'test', 'it', $data));
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ abstract class PConfigTest extends MockedTest
|
||||||
->once();
|
->once();
|
||||||
|
|
||||||
$this->testedConfig = $this->getInstance();
|
$this->testedConfig = $this->getInstance();
|
||||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
|
||||||
|
|
||||||
self::assertTrue($this->testedConfig->set($uid, 'test', 'it', $data));
|
self::assertTrue($this->testedConfig->set($uid, 'test', 'it', $data));
|
||||||
|
|
||||||
|
@ -316,7 +316,7 @@ abstract class PConfigTest extends MockedTest
|
||||||
public function testGetWrongWithoutDB()
|
public function testGetWrongWithoutDB()
|
||||||
{
|
{
|
||||||
$this->testedConfig = $this->getInstance();
|
$this->testedConfig = $this->getInstance();
|
||||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
|
||||||
|
|
||||||
// without refresh
|
// without refresh
|
||||||
self::assertNull($this->testedConfig->get(0, 'test', 'it'));
|
self::assertNull($this->testedConfig->get(0, 'test', 'it'));
|
||||||
|
@ -341,7 +341,7 @@ abstract class PConfigTest extends MockedTest
|
||||||
$this->configCache->load($uid, ['test' => ['it' => 'now']]);
|
$this->configCache->load($uid, ['test' => ['it' => 'now']]);
|
||||||
|
|
||||||
$this->testedConfig = $this->getInstance();
|
$this->testedConfig = $this->getInstance();
|
||||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
|
||||||
|
|
||||||
// without refresh
|
// without refresh
|
||||||
self::assertEquals('now', $this->testedConfig->get($uid, 'test', 'it'));
|
self::assertEquals('now', $this->testedConfig->get($uid, 'test', 'it'));
|
||||||
|
@ -366,7 +366,7 @@ abstract class PConfigTest extends MockedTest
|
||||||
$this->configCache->load($uid, ['test' => ['it' => $data]]);
|
$this->configCache->load($uid, ['test' => ['it' => $data]]);
|
||||||
|
|
||||||
$this->testedConfig = $this->getInstance();
|
$this->testedConfig = $this->getInstance();
|
||||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
|
||||||
|
|
||||||
self::assertEquals($data, $this->testedConfig->get($uid, 'test', 'it'));
|
self::assertEquals($data, $this->testedConfig->get($uid, 'test', 'it'));
|
||||||
self::assertEquals($data, $this->testedConfig->getCache()->get($uid, 'test', 'it'));
|
self::assertEquals($data, $this->testedConfig->getCache()->get($uid, 'test', 'it'));
|
||||||
|
@ -405,7 +405,7 @@ abstract class PConfigTest extends MockedTest
|
||||||
->once();
|
->once();
|
||||||
|
|
||||||
$this->testedConfig = $this->getInstance();
|
$this->testedConfig = $this->getInstance();
|
||||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
|
||||||
|
|
||||||
// directly set the value to the cache
|
// directly set the value to the cache
|
||||||
$this->testedConfig->getCache()->set($uid, 'test', 'it', 'now');
|
$this->testedConfig->getCache()->set($uid, 'test', 'it', 'now');
|
||||||
|
@ -465,7 +465,7 @@ abstract class PConfigTest extends MockedTest
|
||||||
$this->configCache->load($data2['uid'], $data2['data']);
|
$this->configCache->load($data2['uid'], $data2['data']);
|
||||||
|
|
||||||
$this->testedConfig = $this->getInstance();
|
$this->testedConfig = $this->getInstance();
|
||||||
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
|
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
|
||||||
|
|
||||||
self::assertConfig($data1['uid'], 'cat1', $data1['data']['cat1']);
|
self::assertConfig($data1['uid'], 'cat1', $data1['data']['cat1']);
|
||||||
self::assertConfig($data1['uid'], 'cat2', $data1['data']['cat2']);
|
self::assertConfig($data1['uid'], 'cat2', $data1['data']['cat2']);
|
||||||
|
|
|
@ -21,13 +21,13 @@
|
||||||
|
|
||||||
namespace Friendica\Test\src\Core\PConfig;
|
namespace Friendica\Test\src\Core\PConfig;
|
||||||
|
|
||||||
use Friendica\Core\PConfig\PreloadPConfig;
|
use Friendica\Core\PConfig\Type\PreloadPConfig;
|
||||||
|
|
||||||
class PreloadPConfigTest extends PConfigTest
|
class PreloadPConfigTest extends PConfigTest
|
||||||
{
|
{
|
||||||
public function getInstance()
|
public function getInstance()
|
||||||
{
|
{
|
||||||
return new PreloadPConfig($this->configCache, $this->configModel);
|
return new \Friendica\Core\PConfig\Type\PreloadPConfig($this->configCache, $this->configModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -23,22 +23,22 @@ namespace Friendica\Test\src\Core;
|
||||||
|
|
||||||
use Dice\Dice;
|
use Dice\Dice;
|
||||||
use Friendica\Core\Config\IConfig;
|
use Friendica\Core\Config\IConfig;
|
||||||
use Friendica\Core\Config\PreloadConfig;
|
use Friendica\Core\Config\Type\PreloadConfig;
|
||||||
use Friendica\Core\Hook;
|
use Friendica\Core\Hook;
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Core\Session\ISession;
|
use Friendica\Core\Session\ISession;
|
||||||
use Friendica\Core\StorageManager;
|
use Friendica\Core\StorageManager;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Factory\ConfigFactory;
|
use Friendica\Core\Config\Factory\ConfigFactory;
|
||||||
use Friendica\Model\Config\Config;
|
use Friendica\Core\Config\Model\Config;
|
||||||
use Friendica\Model\Storage;
|
use Friendica\Model\Storage;
|
||||||
use Friendica\Core\Session;
|
use Friendica\Core\Session;
|
||||||
use Friendica\Network\HTTPClient;
|
use Friendica\Network\HTTPClient;
|
||||||
use Friendica\Test\DatabaseTest;
|
use Friendica\Test\DatabaseTest;
|
||||||
use Friendica\Test\Util\Database\StaticDatabase;
|
use Friendica\Test\Util\Database\StaticDatabase;
|
||||||
use Friendica\Test\Util\VFSTrait;
|
use Friendica\Test\Util\VFSTrait;
|
||||||
use Friendica\Util\ConfigFileLoader;
|
use Friendica\Core\Config\Cache\ConfigFileLoader;
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
use org\bovigo\vfs\vfsStream;
|
use org\bovigo\vfs\vfsStream;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
|
@ -2,12 +2,11 @@
|
||||||
|
|
||||||
namespace Friendica\Test\src\Model;
|
namespace Friendica\Test\src\Model;
|
||||||
|
|
||||||
use Friendica\Factory\ConfigFactory;
|
use Friendica\Core\Config\Factory\ConfigFactory;
|
||||||
use Friendica\Model\Process;
|
use Friendica\Model\Process;
|
||||||
use Friendica\Test\DatabaseTest;
|
use Friendica\Test\DatabaseTest;
|
||||||
use Friendica\Test\Util\Database\StaticDatabase;
|
use Friendica\Test\Util\Database\StaticDatabase;
|
||||||
use Friendica\Test\Util\VFSTrait;
|
use Friendica\Test\Util\VFSTrait;
|
||||||
use Friendica\Util\ConfigFileLoader;
|
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
use Psr\Log\NullLogger;
|
use Psr\Log\NullLogger;
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
namespace Friendica\Test\src\Model\Storage;
|
namespace Friendica\Test\src\Model\Storage;
|
||||||
|
|
||||||
use Friendica\Factory\ConfigFactory;
|
use Friendica\Core\Config\Factory\ConfigFactory;
|
||||||
use Friendica\Model\Storage\Database;
|
use Friendica\Model\Storage\Database;
|
||||||
use Friendica\Test\DatabaseTestTrait;
|
use Friendica\Test\DatabaseTestTrait;
|
||||||
use Friendica\Test\Util\Database\StaticDatabase;
|
use Friendica\Test\Util\Database\StaticDatabase;
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
namespace Friendica\Test\src\Util;
|
namespace Friendica\Test\src\Util;
|
||||||
|
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache\Cache;
|
||||||
use Friendica\Core\Config\IConfig;
|
use Friendica\Core\Config\IConfig;
|
||||||
use Friendica\Test\MockedTest;
|
use Friendica\Test\MockedTest;
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user