1
1
Fork 0

Added a lot of constants :-)

This commit is contained in:
Philipp Holzer 2023-07-26 23:02:09 +02:00
parent 9ff89a970a
commit acf52a9783
Signed by: nupplaPhil
GPG key ID: 24A7501396EB5432
16 changed files with 51 additions and 65 deletions

View file

@ -1,35 +0,0 @@
<?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';
}

View file

@ -42,7 +42,7 @@ class Cache
/** /**
* @var string The default cache if nothing set * @var string The default cache if nothing set
*/ */
const DEFAULT_TYPE = Enum\Type::DATABASE; const DEFAULT_TYPE = Type\DatabaseCache::NAME;
/** @var ICanCreateInstances */ /** @var ICanCreateInstances */
protected $instanceCreator; protected $instanceCreator;
/** @var IManageConfigValues */ /** @var IManageConfigValues */

View file

@ -33,7 +33,7 @@ use Memcache;
*/ */
class MemcacheCache extends AbstractCache implements ICanCacheInMemory class MemcacheCache extends AbstractCache implements ICanCacheInMemory
{ {
const NAME = 'memcached'; const NAME = 'memcache';
use CompareSetTrait; use CompareSetTrait;
use CompareDeleteTrait; use CompareDeleteTrait;

View file

@ -30,6 +30,11 @@ use Friendica\Core\Hooks\Exceptions\HookConfigException;
*/ */
class StrategiesFileManager 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 STATIC_DIR = 'static';
const CONFIG_NAME = 'strategies'; const CONFIG_NAME = 'strategies';

View file

@ -28,6 +28,8 @@ use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs;
*/ */
abstract class AbstractKeyValueStorage implements IManageKeyValuePairs abstract class AbstractKeyValueStorage implements IManageKeyValuePairs
{ {
const NAME = '';
/** {@inheritDoc} */ /** {@inheritDoc} */
public function get(string $key) public function get(string $key)
{ {

View file

@ -30,6 +30,7 @@ use Friendica\Database\Database;
*/ */
class DBKeyValueStorage extends AbstractKeyValueStorage class DBKeyValueStorage extends AbstractKeyValueStorage
{ {
const NAME = 'database';
const DB_KEY_VALUE_TABLE = 'key-value'; const DB_KEY_VALUE_TABLE = 'key-value';
/** @var Database */ /** @var Database */

View file

@ -21,7 +21,7 @@
namespace Friendica\Core\Lock\Enum; namespace Friendica\Core\Lock\Enum;
use Friendica\Core\Cache\Enum\Type as CacheType; use Friendica\Core\Cache\Type\DatabaseCache;
/** /**
* Enumeration for lock types * Enumeration for lock types
@ -30,6 +30,6 @@ use Friendica\Core\Cache\Enum\Type as CacheType;
*/ */
abstract class Type abstract class Type
{ {
const DATABASE = CacheType::DATABASE; const DATABASE = DatabaseCache::NAME;
const SEMAPHORE = 'semaphore'; const SEMAPHORE = 'semaphore';
} }

View file

@ -23,10 +23,10 @@ namespace Friendica\Core\Lock\Factory;
use Friendica\Core\Cache\Factory\Cache; use Friendica\Core\Cache\Factory\Cache;
use Friendica\Core\Cache\Capability\ICanCacheInMemory; 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\Config\Capability\IManageConfigValues;
use Friendica\Core\Lock\Capability\ICanLock; use Friendica\Core\Lock\Capability\ICanLock;
use Friendica\Core\Lock\Type; use Friendica\Core\Lock\Type as LockType;
use Friendica\Database\Database; use Friendica\Database\Database;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -78,20 +78,20 @@ class Lock
try { try {
switch ($lock_type) { switch ($lock_type) {
case Enum\Type::MEMCACHE: case CacheType\MemcacheCache::NAME:
case Enum\Type::MEMCACHED: case CacheType\MemcachedCache::NAME:
case Enum\Type::REDIS: case CacheType\RedisCache::NAME:
case Enum\Type::APCU: case CacheType\APCuCache::NAME:
$cache = $this->cacheFactory->createLocal($lock_type); $cache = $this->cacheFactory->createLocal($lock_type);
if ($cache instanceof ICanCacheInMemory) { if ($cache instanceof ICanCacheInMemory) {
return new Type\CacheLock($cache); return new LockType\CacheLock($cache);
} else { } else {
throw new \Exception(sprintf('Incompatible cache driver \'%s\' for lock used', $lock_type)); throw new \Exception(sprintf('Incompatible cache driver \'%s\' for lock used', $lock_type));
} }
case 'database': case 'database':
return new Type\DatabaseLock($this->dba); return new LockType\DatabaseLock($this->dba);
case 'semaphore': case 'semaphore':
return new Type\SemaphoreLock(); return new LockType\SemaphoreLock();
default: default:
return self::useAutoDriver(); return self::useAutoDriver();
} }
@ -116,7 +116,7 @@ class Lock
// 1. Try to use Semaphores for - local - locking // 1. Try to use Semaphores for - local - locking
if (function_exists('sem_get')) { if (function_exists('sem_get')) {
try { try {
return new Type\SemaphoreLock(); return new LockType\SemaphoreLock();
} catch (\Exception $exception) { } catch (\Exception $exception) {
$this->logger->warning('Using Semaphore driver for locking failed.', ['exception' => $exception]); $this->logger->warning('Using Semaphore driver for locking failed.', ['exception' => $exception]);
} }
@ -124,11 +124,11 @@ class Lock
// 2. Try to use Cache Locking (don't use the DB-Cache Locking because it works different!) // 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'); $cache_type = $this->config->get('system', 'cache_driver', 'database');
if ($cache_type != Enum\Type::DATABASE) { if ($cache_type != CacheType\DatabaseCache::NAME) {
try { try {
$cache = $this->cacheFactory->createLocal($cache_type); $cache = $this->cacheFactory->createLocal($cache_type);
if ($cache instanceof ICanCacheInMemory) { if ($cache instanceof ICanCacheInMemory) {
return new Type\CacheLock($cache); return new LockType\CacheLock($cache);
} }
} catch (\Exception $exception) { } catch (\Exception $exception) {
$this->logger->warning('Using Cache driver for locking failed.', ['exception' => $exception]); $this->logger->warning('Using Cache driver for locking failed.', ['exception' => $exception]);
@ -136,6 +136,6 @@ class Lock
} }
// 3. Use Database Locking as a Fallback // 3. Use Database Locking as a Fallback
return new Type\DatabaseLock($this->dba); return new LockType\DatabaseLock($this->dba);
} }
} }

View file

@ -38,6 +38,8 @@ use Psr\Log\LogLevel;
*/ */
abstract class AbstractLogger implements LoggerInterface abstract class AbstractLogger implements LoggerInterface
{ {
const NAME = '';
/** /**
* The output channel of this logger * The output channel of this logger
* @var string * @var string

View file

@ -32,6 +32,8 @@ use Psr\Log\LogLevel;
*/ */
class StreamLogger extends AbstractLogger class StreamLogger extends AbstractLogger
{ {
const NAME = 'stream';
/** /**
* The minimum loglevel at which this logger will be triggered * The minimum loglevel at which this logger will be triggered
* @var string * @var string

View file

@ -32,6 +32,8 @@ use Psr\Log\LogLevel;
*/ */
class SyslogLogger extends AbstractLogger class SyslogLogger extends AbstractLogger
{ {
const NAME = 'syslog';
const IDENT = 'Friendica'; const IDENT = 'Friendica';
/** @var int The default syslog flags */ /** @var int The default syslog flags */

View file

@ -34,6 +34,8 @@ use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
*/ */
abstract class AbstractPConfigValues implements IManagePersonalConfigValues abstract class AbstractPConfigValues implements IManagePersonalConfigValues
{ {
const NAME = '';
/** /**
* @var Cache * @var Cache
*/ */

View file

@ -33,6 +33,8 @@ use Friendica\Core\PConfig\ValueObject;
*/ */
class JitPConfig extends AbstractPConfigValues class JitPConfig extends AbstractPConfigValues
{ {
const NAME = 'jit';
/** /**
* @var array Array of already loaded db values (even if there was no value) * @var array Array of already loaded db values (even if there was no value)
*/ */

View file

@ -32,6 +32,8 @@ use Friendica\Core\PConfig\ValueObject;
*/ */
class PreloadPConfig extends AbstractPConfigValues class PreloadPConfig extends AbstractPConfigValues
{ {
const NAME = 'preload';
/** @var array */ /** @var array */
private $config_loaded; private $config_loaded;

View file

@ -22,8 +22,8 @@
namespace Friendica\Core\Session\Factory; namespace Friendica\Core\Session\Factory;
use Friendica\App; use Friendica\App;
use Friendica\Core\Cache\Enum;
use Friendica\Core\Cache\Factory\Cache; use Friendica\Core\Cache\Factory\Cache;
use Friendica\Core\Cache\Type\DatabaseCache;
use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Session\Capability\IHandleSessions; use Friendica\Core\Session\Capability\IHandleSessions;
use Friendica\Core\Session\Type; use Friendica\Core\Session\Type;
@ -74,7 +74,7 @@ class Session
$cache = $cacheFactory->createDistributed(); $cache = $cacheFactory->createDistributed();
// In case we're using the db as cache driver, use the native db session, not the cache // 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); $handler = new Handler\Database($dba, $logger, $server);
} else { } else {
$handler = new Handler\Cache($cache, $logger); $handler = new Handler\Cache($cache, $logger);

View file

@ -20,6 +20,7 @@
*/ */
use Friendica\Core\Cache; use Friendica\Core\Cache;
use Friendica\Core\Hooks\Util\StrategiesFileManager;
use Friendica\Core\Logger\Type; use Friendica\Core\Logger\Type;
use Friendica\Core\KeyValueStorage; use Friendica\Core\KeyValueStorage;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
@ -27,22 +28,22 @@ use Psr\Log;
return [ return [
Log\LoggerInterface::class => [ Log\LoggerInterface::class => [
Log\NullLogger::class => [''], Log\NullLogger::class => [StrategiesFileManager::STRATEGY_DEFAULT_KEY],
Type\SyslogLogger::class => ['syslog'], Type\SyslogLogger::class => [Type\SyslogLogger::NAME],
Type\StreamLogger::class => ['stream'], Type\StreamLogger::class => [Type\StreamLogger::NAME],
], ],
Cache\Capability\ICanCache::class => [ Cache\Capability\ICanCache::class => [
Cache\Type\APCuCache::class => ['apcu'], Cache\Type\DatabaseCache::class => [Cache\Type\DatabaseCache::NAME, StrategiesFileManager::STRATEGY_DEFAULT_KEY],
Cache\Type\DatabaseCache::class => ['database', ''], Cache\Type\APCuCache::class => [Cache\Type\APCuCache::NAME],
Cache\Type\MemcacheCache::class => ['memcache'], Cache\Type\MemcacheCache::class => [Cache\Type\MemcacheCache::NAME],
Cache\Type\MemcachedCache::class => ['memcached'], Cache\Type\MemcachedCache::class => [Cache\Type\MemcachedCache::NAME],
Cache\Type\RedisCache::class => ['redis'], Cache\Type\RedisCache::class => [Cache\Type\RedisCache::NAME],
], ],
KeyValueStorage\Capability\IManageKeyValuePairs::class => [ 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\Capability\IManagePersonalConfigValues::class => [
PConfig\Type\JitPConfig::class => ['jit'], PConfig\Type\JitPConfig::class => [PConfig\Type\JitPConfig::NAME],
PConfig\Type\PreloadPConfig::class => ['preload', ''], PConfig\Type\PreloadPConfig::class => [PConfig\Type\PreloadPConfig::NAME, StrategiesFileManager::STRATEGY_DEFAULT_KEY],
], ],
]; ];