]> git.mxchange.org Git - friendica.git/commitdiff
Added a lot of constants :-)
authorPhilipp <admin@philipp.info>
Wed, 26 Jul 2023 21:02:09 +0000 (23:02 +0200)
committerPhilipp <admin@philipp.info>
Fri, 28 Jul 2023 15:39:13 +0000 (17:39 +0200)
16 files changed:
src/Core/Cache/Enum/Type.php [deleted file]
src/Core/Cache/Factory/Cache.php
src/Core/Cache/Type/MemcacheCache.php
src/Core/Hooks/Util/StrategiesFileManager.php
src/Core/KeyValueStorage/Type/AbstractKeyValueStorage.php
src/Core/KeyValueStorage/Type/DBKeyValueStorage.php
src/Core/Lock/Enum/Type.php
src/Core/Lock/Factory/Lock.php
src/Core/Logger/Type/AbstractLogger.php
src/Core/Logger/Type/StreamLogger.php
src/Core/Logger/Type/SyslogLogger.php
src/Core/PConfig/Type/AbstractPConfigValues.php
src/Core/PConfig/Type/JitPConfig.php
src/Core/PConfig/Type/PreloadPConfig.php
src/Core/Session/Factory/Session.php
static/strategies.config.php

diff --git a/src/Core/Cache/Enum/Type.php b/src/Core/Cache/Enum/Type.php
deleted file mode 100644 (file)
index 98ed9e4..0000000
+++ /dev/null
@@ -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';
-}
index 000233df7fcb3ebbb52035fa465d0861956f60d3..189c574aac254eacf8d12b38ba3812189e5c1a80 100644 (file)
@@ -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 */
index fccaff6c004a94331d28d596a404ea1cb781f524..e8d3b07c8e0889e243d45862fae60effdfa226af 100644 (file)
@@ -33,7 +33,7 @@ use Memcache;
  */
 class MemcacheCache extends AbstractCache implements ICanCacheInMemory
 {
-       const NAME = 'memcached';
+       const NAME = 'memcache';
 
        use CompareSetTrait;
        use CompareDeleteTrait;
index d6651ac9813da4917abf07bec94a71a354eca110..860166fb645119c121aaafc9581f2e8fe930167f 100644 (file)
@@ -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';
 
index 6b1666527642fe957f282ccf4e5872a04223c86f..5d1b1f9d457a8044a28c8a4ab164a3dda363d1be 100644 (file)
@@ -28,6 +28,8 @@ use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs;
  */
 abstract class AbstractKeyValueStorage implements IManageKeyValuePairs
 {
+       const NAME = '';
+
        /** {@inheritDoc} */
        public function get(string $key)
        {
index d31f3c1ced27102c71a40651aac7cf169aa83094..cc152f0c9961c999c2712db7819e3702952eeb28 100644 (file)
@@ -30,6 +30,7 @@ use Friendica\Database\Database;
  */
 class DBKeyValueStorage extends AbstractKeyValueStorage
 {
+       const NAME = 'database';
        const DB_KEY_VALUE_TABLE = 'key-value';
 
        /** @var Database */
index 9e6e9194dff9fda2b10909072a6e10b190ba8788..3a623b6372a0e7b4de33f2f85496ed5f28d4af44 100644 (file)
@@ -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';
 }
index bc4650c97b516bc6c964d81fe80b32481764c927..a60bc5a96c32748974354c6dc7f37fa76b34c1fb 100644 (file)
@@ -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);
        }
 }
index e592ee86d6a0e6436fcbf18ca5d8acfe7c80e803..7de0e416057284894fd16587e0738a67e69b01aa 100644 (file)
@@ -38,6 +38,8 @@ use Psr\Log\LogLevel;
  */
 abstract class AbstractLogger implements LoggerInterface
 {
+       const NAME = '';
+
        /**
         * The output channel of this logger
         * @var string
index e09a320473ed2c334b000d3d3490848a820a1b41..8cadd8cc72a78d11277c389ef9f4ceefd3dc8bf1 100644 (file)
@@ -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
index fb8cb97ae72b2c80d57f1266e94c942613d5fa21..556351a7e4e6445c19ec98bd6eae23b667ae4913 100644 (file)
@@ -32,6 +32,8 @@ use Psr\Log\LogLevel;
  */
 class SyslogLogger extends AbstractLogger
 {
+       const NAME = 'syslog';
+
        const IDENT = 'Friendica';
 
        /** @var int The default syslog flags */
index 39be8f4e74666173e30a4df57954fc5cf2c00438..e567cbaed96eb6d4125e4bfec4466ba44b9d4ea5 100644 (file)
@@ -34,6 +34,8 @@ use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
  */
 abstract class AbstractPConfigValues implements IManagePersonalConfigValues
 {
+       const NAME = '';
+
        /**
         * @var Cache
         */
index c5c20577ef7f4259f6ff7e9769f1dab73b65ee21..b851015e7915a4e7d06707fc484fbb9cda289a11 100644 (file)
@@ -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)
         */
index b3b709286a4051d0ec9bca81735e24526ba449b6..6ae028c5ec21c891966a9097ddc93ec655bd74cc 100644 (file)
@@ -32,6 +32,8 @@ use Friendica\Core\PConfig\ValueObject;
  */
 class PreloadPConfig extends AbstractPConfigValues
 {
+       const NAME = 'preload';
+
        /** @var array */
        private $config_loaded;
 
index 239b050e77723b1abf3473d82b3d71dedde68c48..e12dbd9af6072b12851685017663e45e389fbd77 100644 (file)
@@ -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);
index 8df0c04788862ff3e04293b59e2fa4c578e5974a..18872dc1d44228ad0e1667557df95eec4acc21fa 100644 (file)
@@ -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],
        ],
 ];