mirror of
https://github.com/friendica/friendica
synced 2024-11-09 23:02:54 +00:00
Added a lot of constants :-)
This commit is contained in:
parent
9ff89a970a
commit
acf52a9783
16 changed files with 51 additions and 65 deletions
|
@ -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';
|
||||
}
|
|
@ -42,7 +42,7 @@ class Cache
|
|||
/**
|
||||
* @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 */
|
||||
|
|
|
@ -33,7 +33,7 @@ use Memcache;
|
|||
*/
|
||||
class MemcacheCache extends AbstractCache implements ICanCacheInMemory
|
||||
{
|
||||
const NAME = 'memcached';
|
||||
const NAME = 'memcache';
|
||||
|
||||
use CompareSetTrait;
|
||||
use CompareDeleteTrait;
|
||||
|
|
|
@ -30,6 +30,11 @@ use Friendica\Core\Hooks\Exceptions\HookConfigException;
|
|||
*/
|
||||
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';
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@ use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs;
|
|||
*/
|
||||
abstract class AbstractKeyValueStorage implements IManageKeyValuePairs
|
||||
{
|
||||
const NAME = '';
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function get(string $key)
|
||||
{
|
||||
|
|
|
@ -30,6 +30,7 @@ use Friendica\Database\Database;
|
|||
*/
|
||||
class DBKeyValueStorage extends AbstractKeyValueStorage
|
||||
{
|
||||
const NAME = 'database';
|
||||
const DB_KEY_VALUE_TABLE = 'key-value';
|
||||
|
||||
/** @var Database */
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
namespace Friendica\Core\Lock\Enum;
|
||||
|
||||
use Friendica\Core\Cache\Enum\Type as CacheType;
|
||||
use Friendica\Core\Cache\Type\DatabaseCache;
|
||||
|
||||
/**
|
||||
* Enumeration for lock types
|
||||
|
@ -30,6 +30,6 @@ use Friendica\Core\Cache\Enum\Type as CacheType;
|
|||
*/
|
||||
abstract class Type
|
||||
{
|
||||
const DATABASE = CacheType::DATABASE;
|
||||
const DATABASE = DatabaseCache::NAME;
|
||||
const SEMAPHORE = 'semaphore';
|
||||
}
|
||||
|
|
|
@ -23,10 +23,10 @@ namespace Friendica\Core\Lock\Factory;
|
|||
|
||||
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;
|
||||
|
||||
|
@ -78,20 +78,20 @@ class Lock
|
|||
|
||||
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();
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ class Lock
|
|||
// 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]);
|
||||
}
|
||||
|
@ -124,11 +124,11 @@ class Lock
|
|||
|
||||
// 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]);
|
||||
|
@ -136,6 +136,6 @@ class Lock
|
|||
}
|
||||
|
||||
// 3. Use Database Locking as a Fallback
|
||||
return new Type\DatabaseLock($this->dba);
|
||||
return new LockType\DatabaseLock($this->dba);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,8 @@ use Psr\Log\LogLevel;
|
|||
*/
|
||||
abstract class AbstractLogger implements LoggerInterface
|
||||
{
|
||||
const NAME = '';
|
||||
|
||||
/**
|
||||
* The output channel of this logger
|
||||
* @var string
|
||||
|
|
|
@ -32,6 +32,8 @@ use Psr\Log\LogLevel;
|
|||
*/
|
||||
class StreamLogger extends AbstractLogger
|
||||
{
|
||||
const NAME = 'stream';
|
||||
|
||||
/**
|
||||
* The minimum loglevel at which this logger will be triggered
|
||||
* @var string
|
||||
|
|
|
@ -32,6 +32,8 @@ use Psr\Log\LogLevel;
|
|||
*/
|
||||
class SyslogLogger extends AbstractLogger
|
||||
{
|
||||
const NAME = 'syslog';
|
||||
|
||||
const IDENT = 'Friendica';
|
||||
|
||||
/** @var int The default syslog flags */
|
||||
|
|
|
@ -34,6 +34,8 @@ use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
|
|||
*/
|
||||
abstract class AbstractPConfigValues implements IManagePersonalConfigValues
|
||||
{
|
||||
const NAME = '';
|
||||
|
||||
/**
|
||||
* @var Cache
|
||||
*/
|
||||
|
|
|
@ -33,6 +33,8 @@ use Friendica\Core\PConfig\ValueObject;
|
|||
*/
|
||||
class JitPConfig extends AbstractPConfigValues
|
||||
{
|
||||
const NAME = 'jit';
|
||||
|
||||
/**
|
||||
* @var array Array of already loaded db values (even if there was no value)
|
||||
*/
|
||||
|
|
|
@ -32,6 +32,8 @@ use Friendica\Core\PConfig\ValueObject;
|
|||
*/
|
||||
class PreloadPConfig extends AbstractPConfigValues
|
||||
{
|
||||
const NAME = 'preload';
|
||||
|
||||
/** @var array */
|
||||
private $config_loaded;
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
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;
|
||||
|
@ -74,7 +74,7 @@ class Session
|
|||
$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);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
*/
|
||||
|
||||
use Friendica\Core\Cache;
|
||||
use Friendica\Core\Hooks\Util\StrategiesFileManager;
|
||||
use Friendica\Core\Logger\Type;
|
||||
use Friendica\Core\KeyValueStorage;
|
||||
use Friendica\Core\PConfig;
|
||||
|
@ -27,22 +28,22 @@ use Psr\Log;
|
|||
|
||||
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],
|
||||
],
|
||||
];
|
||||
|
|
Loading…
Reference in a new issue