Move PConfig to strategies

This commit is contained in:
Philipp 2023-07-23 03:19:38 +02:00
parent 58f56c7d7d
commit 8ed94037d5
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
2 changed files with 10 additions and 17 deletions

View file

@ -22,28 +22,16 @@
namespace Friendica\Core\PConfig\Factory; namespace Friendica\Core\PConfig\Factory;
use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Hooks\Capabilities\ICanCreateInstances;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\PConfig\Repository;
use Friendica\Core\PConfig\Type;
use Friendica\Core\PConfig\ValueObject;
class PConfig class PConfig
{ {
/** public function create(ICanCreateInstances $instanceCreator, IManageConfigValues $config): IManagePersonalConfigValues
* @param IManageConfigValues $config The config
* @param ValueObject\Cache $pConfigCache The personal config cache
* @param Repository\PConfig $configRepo The configuration model
*
* @return IManagePersonalConfigValues
*/
public function create(IManageConfigValues $config, ValueObject\Cache $pConfigCache, Repository\PConfig $configRepo): IManagePersonalConfigValues
{ {
if ($config->get('system', 'config_adapter') === 'preload') { $strategy = $config->get('system', 'config_adapter');
$configuration = new Type\PreloadPConfig($pConfigCache, $configRepo);
} else {
$configuration = new Type\JitPConfig($pConfigCache, $configRepo);
}
return $configuration; /** @var IManagePersonalConfigValues */
return $instanceCreator->create(IManagePersonalConfigValues::class, $strategy);
} }
} }

View file

@ -22,6 +22,7 @@
use Friendica\Core\Cache; use Friendica\Core\Cache;
use Friendica\Core\Logger\Type; use Friendica\Core\Logger\Type;
use Friendica\Core\KeyValueStorage; use Friendica\Core\KeyValueStorage;
use Friendica\Core\PConfig;
use Psr\Log; use Psr\Log;
return [ return [
@ -40,4 +41,8 @@ return [
KeyValueStorage\Capabilities\IManageKeyValuePairs::class => [ KeyValueStorage\Capabilities\IManageKeyValuePairs::class => [
KeyValueStorage\Type\DBKeyValueStorage::class => ['database', ''], KeyValueStorage\Type\DBKeyValueStorage::class => ['database', ''],
], ],
PConfig\Capability\IManagePersonalConfigValues::class => [
PConfig\Type\JitPConfig::class => ['jit'],
PConfig\Type\PreloadPConfig::class => ['preload', ''],
],
]; ];