+++ /dev/null
-<?php
-/**
- * @copyright Copyright (C) 2010-2023, 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\Cache\Enum;
-
-/**
- * Enumeration for cache types
- */
-abstract class Type
-{
- const APCU = 'apcu';
- const REDIS = 'redis';
- const ARRAY = 'array';
- const MEMCACHE = 'memcache';
- const DATABASE = 'database';
- const MEMCACHED = 'memcached';
-}
/**
* @var string The default cache if nothing set
*/
- const DEFAULT_TYPE = Enum\Type::DATABASE;
+ const DEFAULT_TYPE = Type\DatabaseCache::NAME;
/** @var ICanCreateInstances */
protected $instanceCreator;
/** @var IManageConfigValues */
*/
class MemcacheCache extends AbstractCache implements ICanCacheInMemory
{
- const NAME = 'memcached';
+ const NAME = 'memcache';
use CompareSetTrait;
use CompareDeleteTrait;
*/
class StrategiesFileManager
{
+ /**
+ * The default hook-file-key of strategies
+ * -> it's an empty string to cover empty/missing config values
+ */
+ const STRATEGY_DEFAULT_KEY = '';
const STATIC_DIR = 'static';
const CONFIG_NAME = 'strategies';
*/
abstract class AbstractKeyValueStorage implements IManageKeyValuePairs
{
+ const NAME = '';
+
/** {@inheritDoc} */
public function get(string $key)
{
*/
class DBKeyValueStorage extends AbstractKeyValueStorage
{
+ const NAME = 'database';
const DB_KEY_VALUE_TABLE = 'key-value';
/** @var Database */
namespace Friendica\Core\Lock\Enum;
-use Friendica\Core\Cache\Enum\Type as CacheType;
+use Friendica\Core\Cache\Type\DatabaseCache;
/**
* Enumeration for lock types
*/
abstract class Type
{
- const DATABASE = CacheType::DATABASE;
+ const DATABASE = DatabaseCache::NAME;
const SEMAPHORE = 'semaphore';
}
use Friendica\Core\Cache\Factory\Cache;
use Friendica\Core\Cache\Capability\ICanCacheInMemory;
-use Friendica\Core\Cache\Enum;
+use Friendica\Core\Cache\Type as CacheType;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Lock\Capability\ICanLock;
-use Friendica\Core\Lock\Type;
+use Friendica\Core\Lock\Type as LockType;
use Friendica\Database\Database;
use Psr\Log\LoggerInterface;
try {
switch ($lock_type) {
- case Enum\Type::MEMCACHE:
- case Enum\Type::MEMCACHED:
- case Enum\Type::REDIS:
- case Enum\Type::APCU:
+ case CacheType\MemcacheCache::NAME:
+ case CacheType\MemcachedCache::NAME:
+ case CacheType\RedisCache::NAME:
+ case CacheType\APCuCache::NAME:
$cache = $this->cacheFactory->createLocal($lock_type);
if ($cache instanceof ICanCacheInMemory) {
- return new Type\CacheLock($cache);
+ return new LockType\CacheLock($cache);
} else {
throw new \Exception(sprintf('Incompatible cache driver \'%s\' for lock used', $lock_type));
}
case 'database':
- return new Type\DatabaseLock($this->dba);
+ return new LockType\DatabaseLock($this->dba);
case 'semaphore':
- return new Type\SemaphoreLock();
+ return new LockType\SemaphoreLock();
default:
return self::useAutoDriver();
}
// 1. Try to use Semaphores for - local - locking
if (function_exists('sem_get')) {
try {
- return new Type\SemaphoreLock();
+ return new LockType\SemaphoreLock();
} catch (\Exception $exception) {
$this->logger->warning('Using Semaphore driver for locking failed.', ['exception' => $exception]);
}
// 2. Try to use Cache Locking (don't use the DB-Cache Locking because it works different!)
$cache_type = $this->config->get('system', 'cache_driver', 'database');
- if ($cache_type != Enum\Type::DATABASE) {
+ if ($cache_type != CacheType\DatabaseCache::NAME) {
try {
$cache = $this->cacheFactory->createLocal($cache_type);
if ($cache instanceof ICanCacheInMemory) {
- return new Type\CacheLock($cache);
+ return new LockType\CacheLock($cache);
}
} catch (\Exception $exception) {
$this->logger->warning('Using Cache driver for locking failed.', ['exception' => $exception]);
}
// 3. Use Database Locking as a Fallback
- return new Type\DatabaseLock($this->dba);
+ return new LockType\DatabaseLock($this->dba);
}
}
*/
abstract class AbstractLogger implements LoggerInterface
{
+ const NAME = '';
+
/**
* The output channel of this logger
* @var string
*/
class StreamLogger extends AbstractLogger
{
+ const NAME = 'stream';
+
/**
* The minimum loglevel at which this logger will be triggered
* @var string
*/
class SyslogLogger extends AbstractLogger
{
+ const NAME = 'syslog';
+
const IDENT = 'Friendica';
/** @var int The default syslog flags */
*/
abstract class AbstractPConfigValues implements IManagePersonalConfigValues
{
+ const NAME = '';
+
/**
* @var Cache
*/
*/
class JitPConfig extends AbstractPConfigValues
{
+ const NAME = 'jit';
+
/**
* @var array Array of already loaded db values (even if there was no value)
*/
*/
class PreloadPConfig extends AbstractPConfigValues
{
+ const NAME = 'preload';
+
/** @var array */
private $config_loaded;
namespace Friendica\Core\Session\Factory;
use Friendica\App;
-use Friendica\Core\Cache\Enum;
use Friendica\Core\Cache\Factory\Cache;
+use Friendica\Core\Cache\Type\DatabaseCache;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Session\Capability\IHandleSessions;
use Friendica\Core\Session\Type;
$cache = $cacheFactory->createDistributed();
// In case we're using the db as cache driver, use the native db session, not the cache
- if ($config->get('system', 'cache_driver') === Enum\Type::DATABASE) {
+ if ($config->get('system', 'cache_driver') === DatabaseCache::NAME) {
$handler = new Handler\Database($dba, $logger, $server);
} else {
$handler = new Handler\Cache($cache, $logger);
*/
use Friendica\Core\Cache;
+use Friendica\Core\Hooks\Util\StrategiesFileManager;
use Friendica\Core\Logger\Type;
use Friendica\Core\KeyValueStorage;
use Friendica\Core\PConfig;
return [
Log\LoggerInterface::class => [
- Log\NullLogger::class => [''],
- Type\SyslogLogger::class => ['syslog'],
- Type\StreamLogger::class => ['stream'],
+ Log\NullLogger::class => [StrategiesFileManager::STRATEGY_DEFAULT_KEY],
+ Type\SyslogLogger::class => [Type\SyslogLogger::NAME],
+ Type\StreamLogger::class => [Type\StreamLogger::NAME],
],
Cache\Capability\ICanCache::class => [
- Cache\Type\APCuCache::class => ['apcu'],
- Cache\Type\DatabaseCache::class => ['database', ''],
- Cache\Type\MemcacheCache::class => ['memcache'],
- Cache\Type\MemcachedCache::class => ['memcached'],
- Cache\Type\RedisCache::class => ['redis'],
+ Cache\Type\DatabaseCache::class => [Cache\Type\DatabaseCache::NAME, StrategiesFileManager::STRATEGY_DEFAULT_KEY],
+ Cache\Type\APCuCache::class => [Cache\Type\APCuCache::NAME],
+ Cache\Type\MemcacheCache::class => [Cache\Type\MemcacheCache::NAME],
+ Cache\Type\MemcachedCache::class => [Cache\Type\MemcachedCache::NAME],
+ Cache\Type\RedisCache::class => [Cache\Type\RedisCache::NAME],
],
KeyValueStorage\Capability\IManageKeyValuePairs::class => [
- KeyValueStorage\Type\DBKeyValueStorage::class => ['database', ''],
+ KeyValueStorage\Type\DBKeyValueStorage::class => [KeyValueStorage\Type\DBKeyValueStorage::NAME, StrategiesFileManager::STRATEGY_DEFAULT_KEY],
],
PConfig\Capability\IManagePersonalConfigValues::class => [
- PConfig\Type\JitPConfig::class => ['jit'],
- PConfig\Type\PreloadPConfig::class => ['preload', ''],
+ PConfig\Type\JitPConfig::class => [PConfig\Type\JitPConfig::NAME],
+ PConfig\Type\PreloadPConfig::class => [PConfig\Type\PreloadPConfig::NAME, StrategiesFileManager::STRATEGY_DEFAULT_KEY],
],
];