From f2c02a79b9c34a25c39cb8a0868a45a6a39e1bfe Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 22 Jul 2023 23:57:38 +0200 Subject: [PATCH 01/12] Move Cache to strategies --- src/Core/Cache/Factory/Cache.php | 69 +++++----------------- src/Core/Cache/Type/APCuCache.php | 13 +--- src/Core/Cache/Type/AbstractCache.php | 8 +++ src/Core/Cache/Type/ArrayCache.php | 10 +--- src/Core/Cache/Type/DatabaseCache.php | 10 +--- src/Core/Cache/Type/MemcacheCache.php | 11 +--- src/Core/Cache/Type/MemcachedCache.php | 11 +--- src/Core/Cache/Type/RedisCache.php | 37 ++++++------ static/dependencies.config.php | 14 +++++ static/strategies.config.php | 9 ++- tests/phpunit-addons.xml | 24 ++++++++ tests/src/Core/Cache/DatabaseCacheTest.php | 1 + 12 files changed, 98 insertions(+), 119 deletions(-) create mode 100644 tests/phpunit-addons.xml diff --git a/src/Core/Cache/Factory/Cache.php b/src/Core/Cache/Factory/Cache.php index 107c6ab21..b6124c156 100644 --- a/src/Core/Cache/Factory/Cache.php +++ b/src/Core/Cache/Factory/Cache.php @@ -21,16 +21,14 @@ namespace Friendica\Core\Cache\Factory; -use Friendica\App\BaseURL; use Friendica\Core\Cache\Enum; use Friendica\Core\Cache\Capability\ICanCache; use Friendica\Core\Cache\Exception\CachePersistenceException; use Friendica\Core\Cache\Exception\InvalidCacheDriverException; use Friendica\Core\Cache\Type; use Friendica\Core\Config\Capability\IManageConfigValues; -use Friendica\Database\Database; +use Friendica\Core\Hooks\Capabilities\ICanCreateInstances; use Friendica\Util\Profiler; -use Psr\Log\LoggerInterface; /** * Class CacheFactory @@ -45,39 +43,18 @@ class Cache * @var string The default cache if nothing set */ const DEFAULT_TYPE = Enum\Type::DATABASE; + /** @var ICanCreateInstances */ + protected $instanceCreator; + /** @var IManageConfigValues */ + protected $config; + /** @var Profiler */ + protected $profiler; - /** - * @var IManageConfigValues The IConfiguration to read parameters out of the config - */ - private $config; - - /** - * @var Database The database connection in case that the cache is used the dba connection - */ - private $dba; - - /** - * @var string The hostname, used as Prefix for Caching - */ - private $hostname; - - /** - * @var Profiler The optional profiler if the cached should be profiled - */ - private $profiler; - - /** - * @var LoggerInterface The Friendica Logger - */ - private $logger; - - public function __construct(BaseURL $baseURL, IManageConfigValues $config, Database $dba, Profiler $profiler, LoggerInterface $logger) + public function __construct(ICanCreateInstances $instanceCreator, IManageConfigValues $config, Profiler $profiler) { - $this->hostname = $baseURL->getHost(); - $this->config = $config; - $this->dba = $dba; - $this->profiler = $profiler; - $this->logger = $logger; + $this->config = $config; + $this->instanceCreator = $instanceCreator; + $this->profiler = $profiler; } /** @@ -92,7 +69,7 @@ class Cache */ public function createDistributed(string $type = null): ICanCache { - if ($type === Enum\Type::APCU) { + if ($type === Type\APCuCache::$NAME) { throw new InvalidCacheDriverException('apcu doesn\'t support distributed caching.'); } @@ -117,31 +94,17 @@ class Cache /** * Creates a new Cache instance * - * @param string $type The type of cache + * @param string $strategy The strategy, which cache instance should be used * * @return ICanCache * * @throws InvalidCacheDriverException In case the underlying cache driver isn't valid or not configured properly * @throws CachePersistenceException In case the underlying cache has errors during persistence */ - protected function create(string $type): ICanCache + protected function create(string $strategy): ICanCache { - switch ($type) { - case Enum\Type::MEMCACHE: - $cache = new Type\MemcacheCache($this->hostname, $this->config); - break; - case Enum\Type::MEMCACHED: - $cache = new Type\MemcachedCache($this->hostname, $this->config, $this->logger); - break; - case Enum\Type::REDIS: - $cache = new Type\RedisCache($this->hostname, $this->config); - break; - case Enum\Type::APCU: - $cache = new Type\APCuCache($this->hostname); - break; - default: - $cache = new Type\DatabaseCache($this->hostname, $this->dba); - } + /** @var ICanCache $cache */ + $cache = $this->instanceCreator->create(ICanCache::class, $strategy); $profiling = $this->config->get('system', 'profiling', false); diff --git a/src/Core/Cache/Type/APCuCache.php b/src/Core/Cache/Type/APCuCache.php index 05eb2fa07..02b2d0fbd 100644 --- a/src/Core/Cache/Type/APCuCache.php +++ b/src/Core/Cache/Type/APCuCache.php @@ -23,7 +23,6 @@ namespace Friendica\Core\Cache\Type; use Friendica\Core\Cache\Enum\Duration; use Friendica\Core\Cache\Capability\ICanCacheInMemory; -use Friendica\Core\Cache\Enum\Type; use Friendica\Core\Cache\Exception\InvalidCacheDriverException; /** @@ -31,12 +30,12 @@ use Friendica\Core\Cache\Exception\InvalidCacheDriverException; */ class APCuCache extends AbstractCache implements ICanCacheInMemory { + public static $NAME = 'apcu'; + use CompareSetTrait; use CompareDeleteTrait; /** - * @param string $hostname - * * @throws InvalidCacheDriverException */ public function __construct(string $hostname) @@ -173,12 +172,4 @@ class APCuCache extends AbstractCache implements ICanCacheInMemory return true; } - - /** - * {@inheritDoc} - */ - public function getName(): string - { - return Type::APCU; - } } diff --git a/src/Core/Cache/Type/AbstractCache.php b/src/Core/Cache/Type/AbstractCache.php index 5c00542a7..36e301ad2 100644 --- a/src/Core/Cache/Type/AbstractCache.php +++ b/src/Core/Cache/Type/AbstractCache.php @@ -28,6 +28,8 @@ use Friendica\Core\Cache\Capability\ICanCache; */ abstract class AbstractCache implements ICanCache { + public static $NAME = ''; + /** * @var string The hostname */ @@ -105,4 +107,10 @@ abstract class AbstractCache implements ICanCache return $result; } } + + /** {@inheritDoc} */ + public function getName(): string + { + return static::$NAME; + } } diff --git a/src/Core/Cache/Type/ArrayCache.php b/src/Core/Cache/Type/ArrayCache.php index 8886a886a..ad87eaf23 100644 --- a/src/Core/Cache/Type/ArrayCache.php +++ b/src/Core/Cache/Type/ArrayCache.php @@ -29,6 +29,8 @@ use Friendica\Core\Cache\Enum; */ class ArrayCache extends AbstractCache implements ICanCacheInMemory { + public static $NAME = 'array'; + use CompareDeleteTrait; /** @var array Array with the cached data */ @@ -108,12 +110,4 @@ class ArrayCache extends AbstractCache implements ICanCacheInMemory return false; } } - - /** - * {@inheritDoc} - */ - public function getName(): string - { - return Enum\Type::ARRAY; - } } diff --git a/src/Core/Cache/Type/DatabaseCache.php b/src/Core/Cache/Type/DatabaseCache.php index fa7968b65..18541e0d2 100644 --- a/src/Core/Cache/Type/DatabaseCache.php +++ b/src/Core/Cache/Type/DatabaseCache.php @@ -32,6 +32,8 @@ use Friendica\Util\DateTimeFormat; */ class DatabaseCache extends AbstractCache implements ICanCache { + public static $NAME = 'database'; + /** * @var Database */ @@ -154,12 +156,4 @@ class DatabaseCache extends AbstractCache implements ICanCache throw new CachePersistenceException('Cannot clear cache', $exception); } } - - /** - * {@inheritDoc} - */ - public function getName(): string - { - return Enum\Type::DATABASE; - } } diff --git a/src/Core/Cache/Type/MemcacheCache.php b/src/Core/Cache/Type/MemcacheCache.php index d19e7deb1..09394a1dd 100644 --- a/src/Core/Cache/Type/MemcacheCache.php +++ b/src/Core/Cache/Type/MemcacheCache.php @@ -23,7 +23,6 @@ namespace Friendica\Core\Cache\Type; use Friendica\Core\Cache\Enum\Duration; use Friendica\Core\Cache\Capability\ICanCacheInMemory; -use Friendica\Core\Cache\Enum\Type; use Friendica\Core\Cache\Exception\CachePersistenceException; use Friendica\Core\Cache\Exception\InvalidCacheDriverException; use Friendica\Core\Config\Capability\IManageConfigValues; @@ -34,6 +33,8 @@ use Memcache; */ class MemcacheCache extends AbstractCache implements ICanCacheInMemory { + static $NAME = 'memcached'; + use CompareSetTrait; use CompareDeleteTrait; use MemcacheCommandTrait; @@ -169,12 +170,4 @@ class MemcacheCache extends AbstractCache implements ICanCacheInMemory $cacheKey = $this->getCacheKey($key); return $this->memcache->add($cacheKey, serialize($value), MEMCACHE_COMPRESSED, $ttl); } - - /** - * {@inheritDoc} - */ - public function getName(): string - { - return Type::MEMCACHE; - } } diff --git a/src/Core/Cache/Type/MemcachedCache.php b/src/Core/Cache/Type/MemcachedCache.php index 6d994ddf5..45a7a0f1c 100644 --- a/src/Core/Cache/Type/MemcachedCache.php +++ b/src/Core/Cache/Type/MemcachedCache.php @@ -23,7 +23,6 @@ namespace Friendica\Core\Cache\Type; use Friendica\Core\Cache\Enum\Duration; use Friendica\Core\Cache\Capability\ICanCacheInMemory; -use Friendica\Core\Cache\Enum\Type; use Friendica\Core\Cache\Exception\CachePersistenceException; use Friendica\Core\Cache\Exception\InvalidCacheDriverException; use Friendica\Core\Config\Capability\IManageConfigValues; @@ -35,6 +34,8 @@ use Psr\Log\LoggerInterface; */ class MemcachedCache extends AbstractCache implements ICanCacheInMemory { + static $NAME = 'memcached'; + use CompareSetTrait; use CompareDeleteTrait; use MemcacheCommandTrait; @@ -185,12 +186,4 @@ class MemcachedCache extends AbstractCache implements ICanCacheInMemory $cacheKey = $this->getCacheKey($key); return $this->memcached->add($cacheKey, $value, $ttl); } - - /** - * {@inheritDoc} - */ - public function getName(): string - { - return Type::MEMCACHED; - } } diff --git a/src/Core/Cache/Type/RedisCache.php b/src/Core/Cache/Type/RedisCache.php index b1fb9ba9c..36c60a12c 100644 --- a/src/Core/Cache/Type/RedisCache.php +++ b/src/Core/Cache/Type/RedisCache.php @@ -21,10 +21,8 @@ namespace Friendica\Core\Cache\Type; -use Exception; use Friendica\Core\Cache\Enum\Duration; use Friendica\Core\Cache\Capability\ICanCacheInMemory; -use Friendica\Core\Cache\Enum\Type; use Friendica\Core\Cache\Exception\CachePersistenceException; use Friendica\Core\Cache\Exception\InvalidCacheDriverException; use Friendica\Core\Config\Capability\IManageConfigValues; @@ -35,6 +33,8 @@ use Redis; */ class RedisCache extends AbstractCache implements ICanCacheInMemory { + public static $NAME = 'redis'; + /** * @var Redis */ @@ -59,18 +59,23 @@ class RedisCache extends AbstractCache implements ICanCacheInMemory $redis_pw = $config->get('system', 'redis_password'); $redis_db = $config->get('system', 'redis_db', 0); - if (!empty($redis_port) && !@$this->redis->connect($redis_host, $redis_port)) { - throw new CachePersistenceException('Expected Redis server at ' . $redis_host . ':' . $redis_port . ' isn\'t available'); - } elseif (!@$this->redis->connect($redis_host)) { - throw new CachePersistenceException('Expected Redis server at ' . $redis_host . ' isn\'t available'); - } + try { - if (!empty($redis_pw) && !$this->redis->auth($redis_pw)) { - throw new CachePersistenceException('Cannot authenticate redis server at ' . $redis_host . ':' . $redis_port); - } + if (!empty($redis_port) && !@$this->redis->connect($redis_host, $redis_port)) { + throw new CachePersistenceException('Expected Redis server at ' . $redis_host . ':' . $redis_port . ' isn\'t available'); + } else if (!@$this->redis->connect($redis_host)) { + throw new CachePersistenceException('Expected Redis server at ' . $redis_host . ' isn\'t available'); + } - if ($redis_db !== 0 && !$this->redis->select($redis_db)) { - throw new CachePersistenceException('Cannot switch to redis db ' . $redis_db . ' at ' . $redis_host . ':' . $redis_port); + if (!empty($redis_pw) && !$this->redis->auth($redis_pw)) { + throw new CachePersistenceException('Cannot authenticate redis server at ' . $redis_host . ':' . $redis_port); + } + + if ($redis_db !== 0 && !$this->redis->select($redis_db)) { + throw new CachePersistenceException('Cannot switch to redis db ' . $redis_db . ' at ' . $redis_host . ':' . $redis_port); + } + } catch (\RedisException $exception) { + throw new CachePersistenceException('Redis connection fails unexpectedly', $exception); } } @@ -211,12 +216,4 @@ class RedisCache extends AbstractCache implements ICanCacheInMemory $this->redis->unwatch(); return false; } - - /** - * {@inheritDoc} - */ - public function getName(): string - { - return Type::REDIS; - } } diff --git a/static/dependencies.config.php b/static/dependencies.config.php index 98a9f3077..c3f30ad8d 100644 --- a/static/dependencies.config.php +++ b/static/dependencies.config.php @@ -178,6 +178,20 @@ return [ $_SERVER, ], ], + '$hostname' => [ + 'instanceOf' => App\BaseURL::class, + 'constructParams' => [ + $_SERVER, + ], + 'call' => [ + ['getHost', [], Dice::CHAIN_CALL], + ], + ], + Cache\Type\AbstractCache::class => [ + 'constructParams' => [ + [Dice::INSTANCE => '$hostname'], + ], + ], App\Page::class => [ 'constructParams' => [ [Dice::INSTANCE => '$basepath'], diff --git a/static/strategies.config.php b/static/strategies.config.php index bb3598c36..5d84a7e47 100644 --- a/static/strategies.config.php +++ b/static/strategies.config.php @@ -19,7 +19,7 @@ * */ -use Friendica\Core\Hooks\Capabilities\BehavioralHookType as H; +use Friendica\Core\Cache; use Friendica\Core\Logger\Type; use Psr\Log; @@ -29,4 +29,11 @@ return [ Type\SyslogLogger::class => ['syslog'], Type\StreamLogger::class => ['stream'], ], + 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'], + ] ]; diff --git a/tests/phpunit-addons.xml b/tests/phpunit-addons.xml new file mode 100644 index 000000000..3793249ab --- /dev/null +++ b/tests/phpunit-addons.xml @@ -0,0 +1,24 @@ + + + + ../addon/*/tests/ + + + + + ../addon/ + + + ../addon/*/tests/ + ../addon/*/view/ + ../addon/*/vendor/ + + + diff --git a/tests/src/Core/Cache/DatabaseCacheTest.php b/tests/src/Core/Cache/DatabaseCacheTest.php index 98afa9e24..63cc7e445 100644 --- a/tests/src/Core/Cache/DatabaseCacheTest.php +++ b/tests/src/Core/Cache/DatabaseCacheTest.php @@ -21,6 +21,7 @@ namespace Friendica\Test\src\Core\Cache; +use Friendica\App\BaseURL; use Friendica\Core\Cache; use Friendica\Test\DatabaseTestTrait; use Friendica\Test\Util\CreateDatabaseTrait; From 58f56c7d7d902349cdfdde76a22301c8cd689b19 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 23 Jul 2023 03:15:59 +0200 Subject: [PATCH 02/12] Move KeyValuePairStorage to strategies --- .../Factory/KeyValueStorage.php | 34 +++++++++++++++++++ src/Core/Lock/Type/AbstractLock.php | 2 +- static/dependencies.config.php | 5 ++- static/strategies.config.php | 6 +++- 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 src/Core/KeyValueStorage/Factory/KeyValueStorage.php diff --git a/src/Core/KeyValueStorage/Factory/KeyValueStorage.php b/src/Core/KeyValueStorage/Factory/KeyValueStorage.php new file mode 100644 index 000000000..1bce84f4e --- /dev/null +++ b/src/Core/KeyValueStorage/Factory/KeyValueStorage.php @@ -0,0 +1,34 @@ +. + * + */ + +namespace Friendica\Core\KeyValueStorage\Factory; + +use Friendica\Core\Hooks\Capabilities\ICanCreateInstances; +use Friendica\Core\KeyValueStorage\Capabilities\IManageKeyValuePairs; + +class KeyValueStorage +{ + public function create(ICanCreateInstances $instanceCreator): IManageKeyValuePairs + { + /** @var IManageKeyValuePairs */ + return $instanceCreator->create(IManageKeyValuePairs::class, ''); + } +} diff --git a/src/Core/Lock/Type/AbstractLock.php b/src/Core/Lock/Type/AbstractLock.php index 3c47c0171..25eb47fe9 100644 --- a/src/Core/Lock/Type/AbstractLock.php +++ b/src/Core/Lock/Type/AbstractLock.php @@ -36,7 +36,7 @@ abstract class AbstractLock implements ICanLock /** * Check if we've locally acquired a lock * - * @param string key The Name of the lock + * @param string $key The Name of the lock * * @return bool Returns true if the lock is set */ diff --git a/static/dependencies.config.php b/static/dependencies.config.php index c3f30ad8d..9c1ead905 100644 --- a/static/dependencies.config.php +++ b/static/dependencies.config.php @@ -291,7 +291,10 @@ return [ ], ], \Friendica\Core\KeyValueStorage\Capabilities\IManageKeyValuePairs::class => [ - 'instanceOf' => \Friendica\Core\KeyValueStorage\Type\DBKeyValueStorage::class, + 'instanceOf' => \Friendica\Core\KeyValueStorage\Factory\KeyValueStorage::class, + 'call' => [ + ['create', [], Dice::CHAIN_CALL], + ], ], Network\HTTPClient\Capability\ICanSendHttpRequests::class => [ 'instanceOf' => Network\HTTPClient\Factory\HttpClient::class, diff --git a/static/strategies.config.php b/static/strategies.config.php index 5d84a7e47..35afe2e51 100644 --- a/static/strategies.config.php +++ b/static/strategies.config.php @@ -21,6 +21,7 @@ use Friendica\Core\Cache; use Friendica\Core\Logger\Type; +use Friendica\Core\KeyValueStorage; use Psr\Log; return [ @@ -35,5 +36,8 @@ return [ Cache\Type\MemcacheCache::class => ['memcache'], Cache\Type\MemcachedCache::class => ['memcached'], Cache\Type\RedisCache::class => ['redis'], - ] + ], + KeyValueStorage\Capabilities\IManageKeyValuePairs::class => [ + KeyValueStorage\Type\DBKeyValueStorage::class => ['database', ''], + ], ]; From 8ed94037d5022d75a9104ceebf06409d6c51c505 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 23 Jul 2023 03:19:38 +0200 Subject: [PATCH 03/12] Move PConfig to strategies --- src/Core/PConfig/Factory/PConfig.php | 22 +++++----------------- static/strategies.config.php | 5 +++++ 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/Core/PConfig/Factory/PConfig.php b/src/Core/PConfig/Factory/PConfig.php index cde97759e..4195619bc 100644 --- a/src/Core/PConfig/Factory/PConfig.php +++ b/src/Core/PConfig/Factory/PConfig.php @@ -22,28 +22,16 @@ namespace Friendica\Core\PConfig\Factory; use Friendica\Core\Config\Capability\IManageConfigValues; +use Friendica\Core\Hooks\Capabilities\ICanCreateInstances; use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; -use Friendica\Core\PConfig\Repository; -use Friendica\Core\PConfig\Type; -use Friendica\Core\PConfig\ValueObject; class PConfig { - /** - * @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 + public function create(ICanCreateInstances $instanceCreator, IManageConfigValues $config): IManagePersonalConfigValues { - if ($config->get('system', 'config_adapter') === 'preload') { - $configuration = new Type\PreloadPConfig($pConfigCache, $configRepo); - } else { - $configuration = new Type\JitPConfig($pConfigCache, $configRepo); - } + $strategy = $config->get('system', 'config_adapter'); - return $configuration; + /** @var IManagePersonalConfigValues */ + return $instanceCreator->create(IManagePersonalConfigValues::class, $strategy); } } diff --git a/static/strategies.config.php b/static/strategies.config.php index 35afe2e51..339a59a87 100644 --- a/static/strategies.config.php +++ b/static/strategies.config.php @@ -22,6 +22,7 @@ use Friendica\Core\Cache; use Friendica\Core\Logger\Type; use Friendica\Core\KeyValueStorage; +use Friendica\Core\PConfig; use Psr\Log; return [ @@ -40,4 +41,8 @@ return [ KeyValueStorage\Capabilities\IManageKeyValuePairs::class => [ KeyValueStorage\Type\DBKeyValueStorage::class => ['database', ''], ], + PConfig\Capability\IManagePersonalConfigValues::class => [ + PConfig\Type\JitPConfig::class => ['jit'], + PConfig\Type\PreloadPConfig::class => ['preload', ''], + ], ]; From 9f18222a061342e3587ee6f38c4543d00948c0b8 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 23 Jul 2023 03:21:41 +0200 Subject: [PATCH 04/12] Unify "Capability" --- bin/auth_ejabberd.php | 6 +++--- bin/console.php | 6 +++--- bin/daemon.php | 6 +++--- bin/worker.php | 6 +++--- doc/StrategyHooks.md | 12 ++++++------ index.php | 4 ++-- src/Console/PostUpdate.php | 2 +- src/Content/Item.php | 2 +- .../{Capabilities => Capability}/ICanLoadAddons.php | 2 +- src/Core/Addon/Model/AddonLoader.php | 2 +- src/Core/Cache/Factory/Cache.php | 2 +- .../BehavioralHookType.php | 2 +- .../ICanCreateInstances.php | 2 +- .../ICanRegisterStrategies.php | 2 +- src/Core/Hooks/Model/DiceInstanceManager.php | 4 ++-- src/Core/Hooks/Util/StrategiesFileManager.php | 4 ++-- .../IManageKeyValuePairs.php | 2 +- src/Core/KeyValueStorage/Factory/KeyValueStorage.php | 4 ++-- .../KeyValueStorage/Type/AbstractKeyValueStorage.php | 2 +- .../ICheckLoggerSettings.php | 2 +- .../IHaveCallIntrospections.php | 2 +- .../{Capabilities => Capability}/LogChannel.php | 2 +- .../Logger/Factory/AbstractLoggerTypeFactory.php | 2 +- src/Core/Logger/Factory/Logger.php | 4 ++-- src/Core/Logger/Factory/StreamLogger.php | 2 +- src/Core/Logger/Type/AbstractLogger.php | 2 +- src/Core/Logger/Type/StreamLogger.php | 2 +- src/Core/Logger/Type/SyslogLogger.php | 2 +- src/Core/Logger/Util/Introspection.php | 2 +- src/Core/Logger/Util/LoggerSettingsCheck.php | 2 +- src/Core/PConfig/Factory/PConfig.php | 2 +- src/DI.php | 6 +++--- src/Module/Friendica.php | 2 +- src/Module/Statistics.php | 4 ++-- static/dependencies.config.php | 12 ++++++------ static/strategies.config.php | 4 ++-- tests/src/Core/Addon/Model/AddonLoaderTest.php | 8 ++++---- .../Core/Hooks/Util/StrategiesFileManagerTest.php | 4 ++-- .../Core/KeyValueStorage/DBKeyValueStorageTest.php | 2 +- .../src/Core/KeyValueStorage/KeyValueStorageTest.php | 2 +- tests/src/Core/Logger/SyslogLoggerWrapper.php | 2 +- 41 files changed, 72 insertions(+), 72 deletions(-) rename src/Core/Addon/{Capabilities => Capability}/ICanLoadAddons.php (96%) rename src/Core/Hooks/{Capabilities => Capability}/BehavioralHookType.php (96%) rename src/Core/Hooks/{Capabilities => Capability}/ICanCreateInstances.php (97%) rename src/Core/Hooks/{Capabilities => Capability}/ICanRegisterStrategies.php (97%) rename src/Core/KeyValueStorage/{Capabilities => Capability}/IManageKeyValuePairs.php (97%) rename src/Core/Logger/{Capabilities => Capability}/ICheckLoggerSettings.php (96%) rename src/Core/Logger/{Capabilities => Capability}/IHaveCallIntrospections.php (96%) rename src/Core/Logger/{Capabilities => Capability}/LogChannel.php (97%) diff --git a/bin/auth_ejabberd.php b/bin/auth_ejabberd.php index b923009e6..3a9553246 100755 --- a/bin/auth_ejabberd.php +++ b/bin/auth_ejabberd.php @@ -58,7 +58,7 @@ if (php_sapi_name() !== 'cli') { use Dice\Dice; use Friendica\App\Mode; -use Friendica\Core\Logger\Capabilities\LogChannel; +use Friendica\Core\Logger\Capability\LogChannel; use Friendica\Security\ExAuth; use Psr\Log\LoggerInterface; @@ -79,8 +79,8 @@ chdir($directory); require dirname(__DIR__) . '/vendor/autoload.php'; $dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php'); -/** @var \Friendica\Core\Addon\Capabilities\ICanLoadAddons $addonLoader */ -$addonLoader = $dice->create(\Friendica\Core\Addon\Capabilities\ICanLoadAddons::class); +/** @var \Friendica\Core\Addon\Capability\ICanLoadAddons $addonLoader */ +$addonLoader = $dice->create(\Friendica\Core\Addon\Capability\ICanLoadAddons::class); $dice = $dice->addRules($addonLoader->getActiveAddonConfig('dependencies')); $dice = $dice->addRule(LoggerInterface::class,['constructParams' => [LogChannel::AUTH_JABBERED]]); diff --git a/bin/console.php b/bin/console.php index b2cde1082..b797e6ba9 100755 --- a/bin/console.php +++ b/bin/console.php @@ -26,15 +26,15 @@ if (php_sapi_name() !== 'cli') { } use Dice\Dice; -use Friendica\Core\Logger\Capabilities\LogChannel; +use Friendica\Core\Logger\Capability\LogChannel; use Friendica\DI; use Psr\Log\LoggerInterface; require dirname(__DIR__) . '/vendor/autoload.php'; $dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php'); -/** @var \Friendica\Core\Addon\Capabilities\ICanLoadAddons $addonLoader */ -$addonLoader = $dice->create(\Friendica\Core\Addon\Capabilities\ICanLoadAddons::class); +/** @var \Friendica\Core\Addon\Capability\ICanLoadAddons $addonLoader */ +$addonLoader = $dice->create(\Friendica\Core\Addon\Capability\ICanLoadAddons::class); $dice = $dice->addRules($addonLoader->getActiveAddonConfig('dependencies')); $dice = $dice->addRule(LoggerInterface::class, ['constructParams' => [LogChannel::CONSOLE]]); diff --git a/bin/daemon.php b/bin/daemon.php index 11bad2b11..cd774fe25 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -60,10 +60,10 @@ if (!file_exists('index.php') && (sizeof($_SERVER['argv']) != 0)) { require dirname(__DIR__) . '/vendor/autoload.php'; $dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php'); -/** @var \Friendica\Core\Addon\Capabilities\ICanLoadAddons $addonLoader */ -$addonLoader = $dice->create(\Friendica\Core\Addon\Capabilities\ICanLoadAddons::class); +/** @var \Friendica\Core\Addon\Capability\ICanLoadAddons $addonLoader */ +$addonLoader = $dice->create(\Friendica\Core\Addon\Capability\ICanLoadAddons::class); $dice = $dice->addRules($addonLoader->getActiveAddonConfig('dependencies')); -$dice = $dice->addRule(LoggerInterface::class, ['constructParams' => [Logger\Capabilities\LogChannel::DAEMON]]); +$dice = $dice->addRule(LoggerInterface::class, ['constructParams' => [Logger\Capability\LogChannel::DAEMON]]); DI::init($dice); \Friendica\Core\Logger\Handler\ErrorHandler::register($dice->create(\Psr\Log\LoggerInterface::class)); diff --git a/bin/worker.php b/bin/worker.php index 42a8f533d..c855f9bc5 100755 --- a/bin/worker.php +++ b/bin/worker.php @@ -29,7 +29,7 @@ if (php_sapi_name() !== 'cli') { use Dice\Dice; use Friendica\App; use Friendica\App\Mode; -use Friendica\Core\Logger\Capabilities\LogChannel; +use Friendica\Core\Logger\Capability\LogChannel; use Friendica\Core\Update; use Friendica\Core\Worker; use Friendica\DI; @@ -55,8 +55,8 @@ if (!file_exists("index.php") && (sizeof($_SERVER["argv"]) != 0)) { require dirname(__DIR__) . '/vendor/autoload.php'; $dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php'); -/** @var \Friendica\Core\Addon\Capabilities\ICanLoadAddons $addonLoader */ -$addonLoader = $dice->create(\Friendica\Core\Addon\Capabilities\ICanLoadAddons::class); +/** @var \Friendica\Core\Addon\Capability\ICanLoadAddons $addonLoader */ +$addonLoader = $dice->create(\Friendica\Core\Addon\Capability\ICanLoadAddons::class); $dice = $dice->addRules($addonLoader->getActiveAddonConfig('dependencies')); $dice = $dice->addRule(LoggerInterface::class, ['constructParams' => [LogChannel::WORKER]]); diff --git a/doc/StrategyHooks.md b/doc/StrategyHooks.md index 39fc1bd8d..2960ceeaa 100644 --- a/doc/StrategyHooks.md +++ b/doc/StrategyHooks.md @@ -10,9 +10,9 @@ This type of hook is based on the [Strategy Design Pattern](https://refactoring. A strategy class defines a possible implementation of a given interface based on a unique name. Every name is possible as long as it's unique and not `null`. Using an empty name (`''`) is possible as well and should be used as the "default" implementation. -To register a strategy, use the [`ICanRegisterInstance`](../src/Core/Hooks/Capabilities/ICanRegisterInstances.php) interface. +To register a strategy, use the [`ICanRegisterInstance`](../src/Core/Hooks/Capability/ICanRegisterInstances.php) interface. -After registration, a caller can automatically create this instance with the [`ICanCreateInstances`](../src/Core/Hooks/Capabilities/ICanCreateInstances.php) interface and the chosen name. +After registration, a caller can automatically create this instance with the [`ICanCreateInstances`](../src/Core/Hooks/Capability/ICanCreateInstances.php) interface and the chosen name. This is useful in case there are different, possible implementations for the same purpose, like for logging, locking, caching, ... @@ -43,11 +43,11 @@ public class ConcreteClassB implements ExampleInterface } } -/** @var \Friendica\Core\Hooks\Capabilities\ICanRegisterStrategies $instanceRegister */ +/** @var \Friendica\Core\Hooks\Capability\ICanRegisterStrategies $instanceRegister */ $instanceRegister->registerStrategy(ExampleInterface::class, ConcreteClassA::class, 'A'); $instanceRegister->registerStrategy(ExampleInterface::class, ConcreteClassB::class, 'B'); -/** @var \Friendica\Core\Hooks\Capabilities\ICanCreateInstances $instanceManager */ +/** @var \Friendica\Core\Hooks\Capability\ICanCreateInstances $instanceManager */ /** @var ConcreteClassA $concreteClass */ $concreteClass = $instanceManager->create(ExampleInterface::class, 'A'); @@ -62,14 +62,14 @@ To avoid registering all strategies manually inside the code, Friendica introduc There, you can register all kind of strategies in one file. -### [`HookType::STRATEGY`](../src/Core/Hooks/Capabilities/HookType.php) +### [`HookType::STRATEGY`](../src/Core/Hooks/Capability/HookType.php) For each given interface, a list of key-value pairs can be set, where the key is the concrete implementation class and the value is an array of unique names. ### Example ```php -use Friendica\Core\Hooks\Capabilities\BehavioralHookType as H; +use Friendica\Core\Hooks\Capability\BehavioralHookType as H; return [ H::STRATEGY => [ diff --git a/index.php b/index.php index ce82470b6..87778308a 100644 --- a/index.php +++ b/index.php @@ -30,8 +30,8 @@ if (!file_exists(__DIR__ . '/vendor/autoload.php')) { require __DIR__ . '/vendor/autoload.php'; $dice = (new Dice())->addRules(include __DIR__ . '/static/dependencies.config.php'); -/** @var \Friendica\Core\Addon\Capabilities\ICanLoadAddons $addonLoader */ -$addonLoader = $dice->create(\Friendica\Core\Addon\Capabilities\ICanLoadAddons::class); +/** @var \Friendica\Core\Addon\Capability\ICanLoadAddons $addonLoader */ +$addonLoader = $dice->create(\Friendica\Core\Addon\Capability\ICanLoadAddons::class); $dice = $dice->addRules($addonLoader->getActiveAddonConfig('dependencies')); $dice = $dice->addRule(Friendica\App\Mode::class, ['call' => [['determineRunMode', [false, $_SERVER], Dice::CHAIN_CALL]]]); diff --git a/src/Console/PostUpdate.php b/src/Console/PostUpdate.php index 742197e73..42cc63e10 100644 --- a/src/Console/PostUpdate.php +++ b/src/Console/PostUpdate.php @@ -22,7 +22,7 @@ namespace Friendica\Console; use Friendica\App; -use Friendica\Core\KeyValueStorage\Capabilities\IManageKeyValuePairs; +use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs; use Friendica\Core\L10n; use Friendica\Core\Update; diff --git a/src/Content/Item.php b/src/Content/Item.php index f7dda6c65..c25e5296f 100644 --- a/src/Content/Item.php +++ b/src/Content/Item.php @@ -544,7 +544,7 @@ class Item unset($item['owner-name']); unset($item['owner-avatar']); } - + $item['postopts'] = ''; } diff --git a/src/Core/Addon/Capabilities/ICanLoadAddons.php b/src/Core/Addon/Capability/ICanLoadAddons.php similarity index 96% rename from src/Core/Addon/Capabilities/ICanLoadAddons.php rename to src/Core/Addon/Capability/ICanLoadAddons.php index 9c9d1e841..42af1a7b3 100644 --- a/src/Core/Addon/Capabilities/ICanLoadAddons.php +++ b/src/Core/Addon/Capability/ICanLoadAddons.php @@ -19,7 +19,7 @@ * */ -namespace Friendica\Core\Addon\Capabilities; +namespace Friendica\Core\Addon\Capability; /** * Interface for loading Addons specific content diff --git a/src/Core/Addon/Model/AddonLoader.php b/src/Core/Addon/Model/AddonLoader.php index 952246af0..e808f2177 100644 --- a/src/Core/Addon/Model/AddonLoader.php +++ b/src/Core/Addon/Model/AddonLoader.php @@ -21,7 +21,7 @@ namespace Friendica\Core\Addon\Model; -use Friendica\Core\Addon\Capabilities\ICanLoadAddons; +use Friendica\Core\Addon\Capability\ICanLoadAddons; use Friendica\Core\Addon\Exception\AddonInvalidConfigFileException; use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Util\Strings; diff --git a/src/Core/Cache/Factory/Cache.php b/src/Core/Cache/Factory/Cache.php index b6124c156..02cdb1a79 100644 --- a/src/Core/Cache/Factory/Cache.php +++ b/src/Core/Cache/Factory/Cache.php @@ -27,7 +27,7 @@ use Friendica\Core\Cache\Exception\CachePersistenceException; use Friendica\Core\Cache\Exception\InvalidCacheDriverException; use Friendica\Core\Cache\Type; use Friendica\Core\Config\Capability\IManageConfigValues; -use Friendica\Core\Hooks\Capabilities\ICanCreateInstances; +use Friendica\Core\Hooks\Capability\ICanCreateInstances; use Friendica\Util\Profiler; /** diff --git a/src/Core/Hooks/Capabilities/BehavioralHookType.php b/src/Core/Hooks/Capability/BehavioralHookType.php similarity index 96% rename from src/Core/Hooks/Capabilities/BehavioralHookType.php rename to src/Core/Hooks/Capability/BehavioralHookType.php index 6336406e6..6de875e55 100644 --- a/src/Core/Hooks/Capabilities/BehavioralHookType.php +++ b/src/Core/Hooks/Capability/BehavioralHookType.php @@ -19,7 +19,7 @@ * */ -namespace Friendica\Core\Hooks\Capabilities; +namespace Friendica\Core\Hooks\Capability; /** * An enum of hook types, based on behavioral design patterns diff --git a/src/Core/Hooks/Capabilities/ICanCreateInstances.php b/src/Core/Hooks/Capability/ICanCreateInstances.php similarity index 97% rename from src/Core/Hooks/Capabilities/ICanCreateInstances.php rename to src/Core/Hooks/Capability/ICanCreateInstances.php index 77d4c4b36..55740d276 100644 --- a/src/Core/Hooks/Capabilities/ICanCreateInstances.php +++ b/src/Core/Hooks/Capability/ICanCreateInstances.php @@ -19,7 +19,7 @@ * */ -namespace Friendica\Core\Hooks\Capabilities; +namespace Friendica\Core\Hooks\Capability; /** * creates special instances for given classes diff --git a/src/Core/Hooks/Capabilities/ICanRegisterStrategies.php b/src/Core/Hooks/Capability/ICanRegisterStrategies.php similarity index 97% rename from src/Core/Hooks/Capabilities/ICanRegisterStrategies.php rename to src/Core/Hooks/Capability/ICanRegisterStrategies.php index 911eb3499..875665764 100644 --- a/src/Core/Hooks/Capabilities/ICanRegisterStrategies.php +++ b/src/Core/Hooks/Capability/ICanRegisterStrategies.php @@ -19,7 +19,7 @@ * */ -namespace Friendica\Core\Hooks\Capabilities; +namespace Friendica\Core\Hooks\Capability; use Friendica\Core\Hooks\Exceptions\HookRegisterArgumentException; diff --git a/src/Core/Hooks/Model/DiceInstanceManager.php b/src/Core/Hooks/Model/DiceInstanceManager.php index a8b0b540c..194fc6e5c 100644 --- a/src/Core/Hooks/Model/DiceInstanceManager.php +++ b/src/Core/Hooks/Model/DiceInstanceManager.php @@ -22,8 +22,8 @@ namespace Friendica\Core\Hooks\Model; use Dice\Dice; -use Friendica\Core\Hooks\Capabilities\ICanCreateInstances; -use Friendica\Core\Hooks\Capabilities\ICanRegisterStrategies; +use Friendica\Core\Hooks\Capability\ICanCreateInstances; +use Friendica\Core\Hooks\Capability\ICanRegisterStrategies; use Friendica\Core\Hooks\Exceptions\HookInstanceException; use Friendica\Core\Hooks\Exceptions\HookRegisterArgumentException; use Friendica\Core\Hooks\Util\StrategiesFileManager; diff --git a/src/Core/Hooks/Util/StrategiesFileManager.php b/src/Core/Hooks/Util/StrategiesFileManager.php index 700c401f2..d6651ac98 100644 --- a/src/Core/Hooks/Util/StrategiesFileManager.php +++ b/src/Core/Hooks/Util/StrategiesFileManager.php @@ -21,8 +21,8 @@ namespace Friendica\Core\Hooks\Util; -use Friendica\Core\Addon\Capabilities\ICanLoadAddons; -use Friendica\Core\Hooks\Capabilities\ICanRegisterStrategies; +use Friendica\Core\Addon\Capability\ICanLoadAddons; +use Friendica\Core\Hooks\Capability\ICanRegisterStrategies; use Friendica\Core\Hooks\Exceptions\HookConfigException; /** diff --git a/src/Core/KeyValueStorage/Capabilities/IManageKeyValuePairs.php b/src/Core/KeyValueStorage/Capability/IManageKeyValuePairs.php similarity index 97% rename from src/Core/KeyValueStorage/Capabilities/IManageKeyValuePairs.php rename to src/Core/KeyValueStorage/Capability/IManageKeyValuePairs.php index c9d215c49..5d9c8455e 100644 --- a/src/Core/KeyValueStorage/Capabilities/IManageKeyValuePairs.php +++ b/src/Core/KeyValueStorage/Capability/IManageKeyValuePairs.php @@ -19,7 +19,7 @@ * */ -namespace Friendica\Core\KeyValueStorage\Capabilities; +namespace Friendica\Core\KeyValueStorage\Capability; use Friendica\Core\KeyValueStorage\Exceptions\KeyValueStoragePersistenceException; diff --git a/src/Core/KeyValueStorage/Factory/KeyValueStorage.php b/src/Core/KeyValueStorage/Factory/KeyValueStorage.php index 1bce84f4e..ee6cb1731 100644 --- a/src/Core/KeyValueStorage/Factory/KeyValueStorage.php +++ b/src/Core/KeyValueStorage/Factory/KeyValueStorage.php @@ -21,8 +21,8 @@ namespace Friendica\Core\KeyValueStorage\Factory; -use Friendica\Core\Hooks\Capabilities\ICanCreateInstances; -use Friendica\Core\KeyValueStorage\Capabilities\IManageKeyValuePairs; +use Friendica\Core\Hooks\Capability\ICanCreateInstances; +use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs; class KeyValueStorage { diff --git a/src/Core/KeyValueStorage/Type/AbstractKeyValueStorage.php b/src/Core/KeyValueStorage/Type/AbstractKeyValueStorage.php index a6924b61f..6b1666527 100644 --- a/src/Core/KeyValueStorage/Type/AbstractKeyValueStorage.php +++ b/src/Core/KeyValueStorage/Type/AbstractKeyValueStorage.php @@ -21,7 +21,7 @@ namespace Friendica\Core\KeyValueStorage\Type; -use Friendica\Core\KeyValueStorage\Capabilities\IManageKeyValuePairs; +use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs; /** * An abstract helper class for Key-Value storage classes diff --git a/src/Core/Logger/Capabilities/ICheckLoggerSettings.php b/src/Core/Logger/Capability/ICheckLoggerSettings.php similarity index 96% rename from src/Core/Logger/Capabilities/ICheckLoggerSettings.php rename to src/Core/Logger/Capability/ICheckLoggerSettings.php index fb93d18e8..abdbc3b50 100644 --- a/src/Core/Logger/Capabilities/ICheckLoggerSettings.php +++ b/src/Core/Logger/Capability/ICheckLoggerSettings.php @@ -19,7 +19,7 @@ * */ -namespace Friendica\Core\Logger\Capabilities; +namespace Friendica\Core\Logger\Capability; /** * Whenever a logging specific check is necessary, use this interface to encapsulate and centralize this logic diff --git a/src/Core/Logger/Capabilities/IHaveCallIntrospections.php b/src/Core/Logger/Capability/IHaveCallIntrospections.php similarity index 96% rename from src/Core/Logger/Capabilities/IHaveCallIntrospections.php rename to src/Core/Logger/Capability/IHaveCallIntrospections.php index 83d75f976..918232af3 100644 --- a/src/Core/Logger/Capabilities/IHaveCallIntrospections.php +++ b/src/Core/Logger/Capability/IHaveCallIntrospections.php @@ -19,7 +19,7 @@ * */ -namespace Friendica\Core\Logger\Capabilities; +namespace Friendica\Core\Logger\Capability; interface IHaveCallIntrospections { diff --git a/src/Core/Logger/Capabilities/LogChannel.php b/src/Core/Logger/Capability/LogChannel.php similarity index 97% rename from src/Core/Logger/Capabilities/LogChannel.php rename to src/Core/Logger/Capability/LogChannel.php index 31915168b..c3b631644 100644 --- a/src/Core/Logger/Capabilities/LogChannel.php +++ b/src/Core/Logger/Capability/LogChannel.php @@ -19,7 +19,7 @@ * */ -namespace Friendica\Core\Logger\Capabilities; +namespace Friendica\Core\Logger\Capability; /** * An enum class for the Log channels diff --git a/src/Core/Logger/Factory/AbstractLoggerTypeFactory.php b/src/Core/Logger/Factory/AbstractLoggerTypeFactory.php index 402176d8e..86dfeae63 100644 --- a/src/Core/Logger/Factory/AbstractLoggerTypeFactory.php +++ b/src/Core/Logger/Factory/AbstractLoggerTypeFactory.php @@ -21,7 +21,7 @@ namespace Friendica\Core\Logger\Factory; -use Friendica\Core\Logger\Capabilities\IHaveCallIntrospections; +use Friendica\Core\Logger\Capability\IHaveCallIntrospections; use Psr\Log\LogLevel; /** diff --git a/src/Core/Logger/Factory/Logger.php b/src/Core/Logger/Factory/Logger.php index c370cc4dd..f1086f585 100644 --- a/src/Core/Logger/Factory/Logger.php +++ b/src/Core/Logger/Factory/Logger.php @@ -22,8 +22,8 @@ namespace Friendica\Core\Logger\Factory; use Friendica\Core\Config\Capability\IManageConfigValues; -use Friendica\Core\Hooks\Capabilities\ICanCreateInstances; -use Friendica\Core\Logger\Capabilities\LogChannel; +use Friendica\Core\Hooks\Capability\ICanCreateInstances; +use Friendica\Core\Logger\Capability\LogChannel; use Friendica\Core\Logger\Type\ProfilerLogger as ProfilerLoggerClass; use Friendica\Util\Profiler; use Psr\Log\LoggerInterface; diff --git a/src/Core/Logger/Factory/StreamLogger.php b/src/Core/Logger/Factory/StreamLogger.php index caad78e3b..7f32d66b1 100644 --- a/src/Core/Logger/Factory/StreamLogger.php +++ b/src/Core/Logger/Factory/StreamLogger.php @@ -22,7 +22,7 @@ namespace Friendica\Core\Logger\Factory; use Friendica\Core\Config\Capability\IManageConfigValues; -use Friendica\Core\Logger\Capabilities\LogChannel; +use Friendica\Core\Logger\Capability\LogChannel; use Friendica\Core\Logger\Exception\LoggerArgumentException; use Friendica\Core\Logger\Exception\LoggerException; use Friendica\Core\Logger\Exception\LogLevelException; diff --git a/src/Core/Logger/Type/AbstractLogger.php b/src/Core/Logger/Type/AbstractLogger.php index 77a61e920..e592ee86d 100644 --- a/src/Core/Logger/Type/AbstractLogger.php +++ b/src/Core/Logger/Type/AbstractLogger.php @@ -21,7 +21,7 @@ namespace Friendica\Core\Logger\Type; -use Friendica\Core\Logger\Capabilities\IHaveCallIntrospections; +use Friendica\Core\Logger\Capability\IHaveCallIntrospections; use Friendica\Core\Logger\Exception\LoggerException; use Friendica\Util\Strings; use Psr\Log\LoggerInterface; diff --git a/src/Core/Logger/Type/StreamLogger.php b/src/Core/Logger/Type/StreamLogger.php index 87f1a3937..e09a32047 100644 --- a/src/Core/Logger/Type/StreamLogger.php +++ b/src/Core/Logger/Type/StreamLogger.php @@ -21,7 +21,7 @@ namespace Friendica\Core\Logger\Type; -use Friendica\Core\Logger\Capabilities\IHaveCallIntrospections; +use Friendica\Core\Logger\Capability\IHaveCallIntrospections; use Friendica\Core\Logger\Exception\LoggerException; use Friendica\Core\Logger\Exception\LogLevelException; use Friendica\Util\DateTimeFormat; diff --git a/src/Core/Logger/Type/SyslogLogger.php b/src/Core/Logger/Type/SyslogLogger.php index 88dc1964d..fb8cb97ae 100644 --- a/src/Core/Logger/Type/SyslogLogger.php +++ b/src/Core/Logger/Type/SyslogLogger.php @@ -21,7 +21,7 @@ namespace Friendica\Core\Logger\Type; -use Friendica\Core\Logger\Capabilities\IHaveCallIntrospections; +use Friendica\Core\Logger\Capability\IHaveCallIntrospections; use Friendica\Core\Logger\Exception\LoggerException; use Friendica\Core\Logger\Exception\LogLevelException; use Psr\Log\LogLevel; diff --git a/src/Core/Logger/Util/Introspection.php b/src/Core/Logger/Util/Introspection.php index e0f7e8554..0b703da82 100644 --- a/src/Core/Logger/Util/Introspection.php +++ b/src/Core/Logger/Util/Introspection.php @@ -22,7 +22,7 @@ namespace Friendica\Core\Logger\Util; use Friendica\App\Request; -use Friendica\Core\Logger\Capabilities\IHaveCallIntrospections; +use Friendica\Core\Logger\Capability\IHaveCallIntrospections; /** * Get Introspection information about the current call diff --git a/src/Core/Logger/Util/LoggerSettingsCheck.php b/src/Core/Logger/Util/LoggerSettingsCheck.php index 7782216da..cb598d5f2 100644 --- a/src/Core/Logger/Util/LoggerSettingsCheck.php +++ b/src/Core/Logger/Util/LoggerSettingsCheck.php @@ -23,7 +23,7 @@ namespace Friendica\Core\Logger\Util; use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\L10n; -use Friendica\Core\Logger\Capabilities\ICheckLoggerSettings; +use Friendica\Core\Logger\Capability\ICheckLoggerSettings; use Friendica\Core\Logger\Exception\LoggerUnusableException; /** {@inheritDoc} */ diff --git a/src/Core/PConfig/Factory/PConfig.php b/src/Core/PConfig/Factory/PConfig.php index 4195619bc..059675289 100644 --- a/src/Core/PConfig/Factory/PConfig.php +++ b/src/Core/PConfig/Factory/PConfig.php @@ -22,7 +22,7 @@ namespace Friendica\Core\PConfig\Factory; use Friendica\Core\Config\Capability\IManageConfigValues; -use Friendica\Core\Hooks\Capabilities\ICanCreateInstances; +use Friendica\Core\Hooks\Capability\ICanCreateInstances; use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; class PConfig diff --git a/src/DI.php b/src/DI.php index 1917f710d..34cf1c68d 100644 --- a/src/DI.php +++ b/src/DI.php @@ -22,7 +22,7 @@ namespace Friendica; use Dice\Dice; -use Friendica\Core\Logger\Capabilities\ICheckLoggerSettings; +use Friendica\Core\Logger\Capability\ICheckLoggerSettings; use Friendica\Core\Logger\Util\LoggerSettingsCheck; use Friendica\Core\Session\Capability\IHandleSessions; use Friendica\Core\Session\Capability\IHandleUserSessions; @@ -210,9 +210,9 @@ abstract class DI return self::$dice->create(Core\Config\Util\ConfigFileManager::class); } - public static function keyValue(): Core\KeyValueStorage\Capabilities\IManageKeyValuePairs + public static function keyValue(): Core\KeyValueStorage\Capability\IManageKeyValuePairs { - return self::$dice->create(Core\KeyValueStorage\Capabilities\IManageKeyValuePairs::class); + return self::$dice->create(Core\KeyValueStorage\Capability\IManageKeyValuePairs::class); } /** diff --git a/src/Module/Friendica.php b/src/Module/Friendica.php index c6e2768bd..1bd6bd411 100644 --- a/src/Module/Friendica.php +++ b/src/Module/Friendica.php @@ -26,7 +26,7 @@ use Friendica\BaseModule; use Friendica\Core\Addon; use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\Hook; -use Friendica\Core\KeyValueStorage\Capabilities\IManageKeyValuePairs; +use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs; use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Core\Session\Capability\IHandleUserSessions; diff --git a/src/Module/Statistics.php b/src/Module/Statistics.php index 514f10bb7..e69f75421 100644 --- a/src/Module/Statistics.php +++ b/src/Module/Statistics.php @@ -25,7 +25,7 @@ use Friendica\App; use Friendica\BaseModule; use Friendica\Core\Addon; use Friendica\Core\Config\Capability\IManageConfigValues; -use Friendica\Core\KeyValueStorage\Capabilities\IManageKeyValuePairs; +use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs; use Friendica\Core\L10n; use Friendica\Core\System; use Friendica\Network\HTTPException\NotFoundException; @@ -38,7 +38,7 @@ class Statistics extends BaseModule protected $config; /** @var IManageKeyValuePairs */ protected $keyValue; - + public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, IManageConfigValues $config, IManageKeyValuePairs $keyValue, Response $response, array $server, array $parameters = []) { parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); diff --git a/static/dependencies.config.php b/static/dependencies.config.php index 9c1ead905..3dfde6b5f 100644 --- a/static/dependencies.config.php +++ b/static/dependencies.config.php @@ -37,8 +37,8 @@ use Dice\Dice; use Friendica\App; use Friendica\Core\Cache; use Friendica\Core\Config; -use Friendica\Core\Hooks\Capabilities\ICanCreateInstances; -use Friendica\Core\Hooks\Capabilities\ICanRegisterStrategies; +use Friendica\Core\Hooks\Capability\ICanCreateInstances; +use Friendica\Core\Hooks\Capability\ICanRegisterStrategies; use Friendica\Core\Hooks\Model\DiceInstanceManager; use Friendica\Core\PConfig; use Friendica\Core\L10n; @@ -63,7 +63,7 @@ return [ // one instance for the whole execution 'shared' => true, ], - \Friendica\Core\Addon\Capabilities\ICanLoadAddons::class => [ + \Friendica\Core\Addon\Capability\ICanLoadAddons::class => [ 'instanceOf' => \Friendica\Core\Addon\Model\AddonLoader::class, 'constructParams' => [ [Dice::INSTANCE => '$basepath'], @@ -215,10 +215,10 @@ return [ ['create', [], Dice::CHAIN_CALL], ], ], - \Friendica\Core\Logger\Capabilities\IHaveCallIntrospections::class => [ + \Friendica\Core\Logger\Capability\IHaveCallIntrospections::class => [ 'instanceOf' => \Friendica\Core\Logger\Util\Introspection::class, 'constructParams' => [ - \Friendica\Core\Logger\Capabilities\IHaveCallIntrospections::IGNORE_CLASS_LIST, + \Friendica\Core\Logger\Capability\IHaveCallIntrospections::IGNORE_CLASS_LIST, ], ], '$devLogger' => [ @@ -290,7 +290,7 @@ return [ ['getBackend', [], Dice::CHAIN_CALL], ], ], - \Friendica\Core\KeyValueStorage\Capabilities\IManageKeyValuePairs::class => [ + \Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs::class => [ 'instanceOf' => \Friendica\Core\KeyValueStorage\Factory\KeyValueStorage::class, 'call' => [ ['create', [], Dice::CHAIN_CALL], diff --git a/static/strategies.config.php b/static/strategies.config.php index 339a59a87..8df0c0478 100644 --- a/static/strategies.config.php +++ b/static/strategies.config.php @@ -38,11 +38,11 @@ return [ Cache\Type\MemcachedCache::class => ['memcached'], Cache\Type\RedisCache::class => ['redis'], ], - KeyValueStorage\Capabilities\IManageKeyValuePairs::class => [ + KeyValueStorage\Capability\IManageKeyValuePairs::class => [ KeyValueStorage\Type\DBKeyValueStorage::class => ['database', ''], ], PConfig\Capability\IManagePersonalConfigValues::class => [ - PConfig\Type\JitPConfig::class => ['jit'], + PConfig\Type\JitPConfig::class => ['jit'], PConfig\Type\PreloadPConfig::class => ['preload', ''], ], ]; diff --git a/tests/src/Core/Addon/Model/AddonLoaderTest.php b/tests/src/Core/Addon/Model/AddonLoaderTest.php index 189110fde..f49333b32 100644 --- a/tests/src/Core/Addon/Model/AddonLoaderTest.php +++ b/tests/src/Core/Addon/Model/AddonLoaderTest.php @@ -54,7 +54,7 @@ class AddonLoaderTest extends MockedTest [ + \Friendica\Core\Hooks\Capability\BehavioralHookType::STRATEGY => [ \Psr\Log\LoggerInterface::class => [ \Psr\Log\NullLogger::class => [''], ], @@ -79,7 +79,7 @@ EOF; 'addon/testaddon1/static/hooks.config.php' => $this->content, ], 'assertion' => [ - \Friendica\Core\Hooks\Capabilities\BehavioralHookType::STRATEGY => [ + \Friendica\Core\Hooks\Capability\BehavioralHookType::STRATEGY => [ \Psr\Log\LoggerInterface::class => [ \Psr\Log\NullLogger::class => [''], ], @@ -94,7 +94,7 @@ EOF; 'addon/testaddon2/static/hooks.config.php' => $this->content, ], 'assertion' => [ - \Friendica\Core\Hooks\Capabilities\BehavioralHookType::STRATEGY => [ + \Friendica\Core\Hooks\Capability\BehavioralHookType::STRATEGY => [ \Psr\Log\LoggerInterface::class => [ \Psr\Log\NullLogger::class => ['', ''], ], @@ -118,7 +118,7 @@ EOF; 'addon/testaddon2/static/hooks.config.php' => $this->content, ], 'assertion' => [ - \Friendica\Core\Hooks\Capabilities\BehavioralHookType::STRATEGY => [ + \Friendica\Core\Hooks\Capability\BehavioralHookType::STRATEGY => [ \Psr\Log\LoggerInterface::class => [ \Psr\Log\NullLogger::class => [''], ], diff --git a/tests/src/Core/Hooks/Util/StrategiesFileManagerTest.php b/tests/src/Core/Hooks/Util/StrategiesFileManagerTest.php index 592f6f1e0..ebb213fa7 100644 --- a/tests/src/Core/Hooks/Util/StrategiesFileManagerTest.php +++ b/tests/src/Core/Hooks/Util/StrategiesFileManagerTest.php @@ -21,8 +21,8 @@ namespace Friendica\Test\src\Core\Hooks\Util; -use Friendica\Core\Addon\Capabilities\ICanLoadAddons; -use Friendica\Core\Hooks\Capabilities\ICanRegisterStrategies; +use Friendica\Core\Addon\Capability\ICanLoadAddons; +use Friendica\Core\Hooks\Capability\ICanRegisterStrategies; use Friendica\Core\Hooks\Exceptions\HookConfigException; use Friendica\Core\Hooks\Util\StrategiesFileManager; use Friendica\Test\MockedTest; diff --git a/tests/src/Core/KeyValueStorage/DBKeyValueStorageTest.php b/tests/src/Core/KeyValueStorage/DBKeyValueStorageTest.php index 80a0f16de..3a3b25536 100644 --- a/tests/src/Core/KeyValueStorage/DBKeyValueStorageTest.php +++ b/tests/src/Core/KeyValueStorage/DBKeyValueStorageTest.php @@ -21,7 +21,7 @@ namespace Friendica\Test\src\Core\KeyValueStorage; -use Friendica\Core\KeyValueStorage\Capabilities\IManageKeyValuePairs; +use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs; use Friendica\Core\KeyValueStorage\Type\DBKeyValueStorage; use Friendica\Database\Database; use Friendica\Test\Util\CreateDatabaseTrait; diff --git a/tests/src/Core/KeyValueStorage/KeyValueStorageTest.php b/tests/src/Core/KeyValueStorage/KeyValueStorageTest.php index 6ccc0f5f4..ddb0acc4d 100644 --- a/tests/src/Core/KeyValueStorage/KeyValueStorageTest.php +++ b/tests/src/Core/KeyValueStorage/KeyValueStorageTest.php @@ -21,7 +21,7 @@ namespace Friendica\Test\src\Core\KeyValueStorage; -use Friendica\Core\KeyValueStorage\Capabilities\IManageKeyValuePairs; +use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs; use Friendica\Test\MockedTest; abstract class KeyValueStorageTest extends MockedTest diff --git a/tests/src/Core/Logger/SyslogLoggerWrapper.php b/tests/src/Core/Logger/SyslogLoggerWrapper.php index 1e0c4535f..dce28b164 100644 --- a/tests/src/Core/Logger/SyslogLoggerWrapper.php +++ b/tests/src/Core/Logger/SyslogLoggerWrapper.php @@ -21,7 +21,7 @@ namespace Friendica\Test\src\Core\Logger; -use Friendica\Core\Logger\Capabilities\IHaveCallIntrospections; +use Friendica\Core\Logger\Capability\IHaveCallIntrospections; use Friendica\Core\Logger\Type\SyslogLogger; /** From bbfec06a3d0a922aba054feb0f17aef1c90edd15 Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 26 Jul 2023 21:43:03 +0200 Subject: [PATCH 05/12] Add "getName()" test --- tests/src/Core/Cache/CacheTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/src/Core/Cache/CacheTest.php b/tests/src/Core/Cache/CacheTest.php index 615a1095d..dbcc56e22 100644 --- a/tests/src/Core/Cache/CacheTest.php +++ b/tests/src/Core/Cache/CacheTest.php @@ -23,6 +23,7 @@ namespace Friendica\Test\src\Core\Cache; use Friendica\Core\Cache\Capability\ICanCache; use Friendica\Core\Cache\Capability\ICanCacheInMemory; +use Friendica\Core\Cache\Type\AbstractCache; use Friendica\Test\MockedTest; use Friendica\Util\PidFile; @@ -246,4 +247,13 @@ abstract class CacheTest extends MockedTest self::assertTrue($this->instance->set('key space', 'value')); self::assertEquals('value', $this->instance->get('key space')); } + + public function testGetName() + { + if (property_exists($this->instance, '$NAME')) { + self::assertEquals($this->instance::$NAME, $this->instance->getName()); + } else { + self::expectNotToPerformAssertions(); + } + } } From 9ff89a970a87582520e2051230da04c7e7a93de6 Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 26 Jul 2023 22:42:40 +0200 Subject: [PATCH 06/12] Rename NAME to constant --- src/Core/Cache/Factory/Cache.php | 2 +- src/Core/Cache/Type/APCuCache.php | 2 +- src/Core/Cache/Type/AbstractCache.php | 4 ++-- src/Core/Cache/Type/ArrayCache.php | 2 +- src/Core/Cache/Type/DatabaseCache.php | 2 +- src/Core/Cache/Type/MemcacheCache.php | 2 +- src/Core/Cache/Type/MemcachedCache.php | 2 +- src/Core/Cache/Type/RedisCache.php | 2 +- tests/src/Core/Cache/CacheTest.php | 4 ++-- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Core/Cache/Factory/Cache.php b/src/Core/Cache/Factory/Cache.php index 02cdb1a79..000233df7 100644 --- a/src/Core/Cache/Factory/Cache.php +++ b/src/Core/Cache/Factory/Cache.php @@ -69,7 +69,7 @@ class Cache */ public function createDistributed(string $type = null): ICanCache { - if ($type === Type\APCuCache::$NAME) { + if ($type === Type\APCuCache::NAME) { throw new InvalidCacheDriverException('apcu doesn\'t support distributed caching.'); } diff --git a/src/Core/Cache/Type/APCuCache.php b/src/Core/Cache/Type/APCuCache.php index 02b2d0fbd..f35815c15 100644 --- a/src/Core/Cache/Type/APCuCache.php +++ b/src/Core/Cache/Type/APCuCache.php @@ -30,7 +30,7 @@ use Friendica\Core\Cache\Exception\InvalidCacheDriverException; */ class APCuCache extends AbstractCache implements ICanCacheInMemory { - public static $NAME = 'apcu'; + const NAME = 'apcu'; use CompareSetTrait; use CompareDeleteTrait; diff --git a/src/Core/Cache/Type/AbstractCache.php b/src/Core/Cache/Type/AbstractCache.php index 36e301ad2..211f28b9a 100644 --- a/src/Core/Cache/Type/AbstractCache.php +++ b/src/Core/Cache/Type/AbstractCache.php @@ -28,7 +28,7 @@ use Friendica\Core\Cache\Capability\ICanCache; */ abstract class AbstractCache implements ICanCache { - public static $NAME = ''; + const NAME = ''; /** * @var string The hostname @@ -111,6 +111,6 @@ abstract class AbstractCache implements ICanCache /** {@inheritDoc} */ public function getName(): string { - return static::$NAME; + return static::NAME; } } diff --git a/src/Core/Cache/Type/ArrayCache.php b/src/Core/Cache/Type/ArrayCache.php index ad87eaf23..34246afff 100644 --- a/src/Core/Cache/Type/ArrayCache.php +++ b/src/Core/Cache/Type/ArrayCache.php @@ -29,7 +29,7 @@ use Friendica\Core\Cache\Enum; */ class ArrayCache extends AbstractCache implements ICanCacheInMemory { - public static $NAME = 'array'; + const NAME = 'array'; use CompareDeleteTrait; diff --git a/src/Core/Cache/Type/DatabaseCache.php b/src/Core/Cache/Type/DatabaseCache.php index 18541e0d2..4959d6a75 100644 --- a/src/Core/Cache/Type/DatabaseCache.php +++ b/src/Core/Cache/Type/DatabaseCache.php @@ -32,7 +32,7 @@ use Friendica\Util\DateTimeFormat; */ class DatabaseCache extends AbstractCache implements ICanCache { - public static $NAME = 'database'; + const NAME = 'database'; /** * @var Database diff --git a/src/Core/Cache/Type/MemcacheCache.php b/src/Core/Cache/Type/MemcacheCache.php index 09394a1dd..fccaff6c0 100644 --- a/src/Core/Cache/Type/MemcacheCache.php +++ b/src/Core/Cache/Type/MemcacheCache.php @@ -33,7 +33,7 @@ use Memcache; */ class MemcacheCache extends AbstractCache implements ICanCacheInMemory { - static $NAME = 'memcached'; + const NAME = 'memcached'; use CompareSetTrait; use CompareDeleteTrait; diff --git a/src/Core/Cache/Type/MemcachedCache.php b/src/Core/Cache/Type/MemcachedCache.php index 45a7a0f1c..160c5a16f 100644 --- a/src/Core/Cache/Type/MemcachedCache.php +++ b/src/Core/Cache/Type/MemcachedCache.php @@ -34,7 +34,7 @@ use Psr\Log\LoggerInterface; */ class MemcachedCache extends AbstractCache implements ICanCacheInMemory { - static $NAME = 'memcached'; + const NAME = 'memcached'; use CompareSetTrait; use CompareDeleteTrait; diff --git a/src/Core/Cache/Type/RedisCache.php b/src/Core/Cache/Type/RedisCache.php index 36c60a12c..be2a7ff08 100644 --- a/src/Core/Cache/Type/RedisCache.php +++ b/src/Core/Cache/Type/RedisCache.php @@ -33,7 +33,7 @@ use Redis; */ class RedisCache extends AbstractCache implements ICanCacheInMemory { - public static $NAME = 'redis'; + const NAME = 'redis'; /** * @var Redis diff --git a/tests/src/Core/Cache/CacheTest.php b/tests/src/Core/Cache/CacheTest.php index dbcc56e22..775a29374 100644 --- a/tests/src/Core/Cache/CacheTest.php +++ b/tests/src/Core/Cache/CacheTest.php @@ -250,8 +250,8 @@ abstract class CacheTest extends MockedTest public function testGetName() { - if (property_exists($this->instance, '$NAME')) { - self::assertEquals($this->instance::$NAME, $this->instance->getName()); + if (defined(get_class($this->instance) . '::NAME')) { + self::assertEquals($this->instance::NAME, $this->instance->getName()); } else { self::expectNotToPerformAssertions(); } From acf52a9783c1c56ca740ef903388ab254043340d Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 26 Jul 2023 23:02:09 +0200 Subject: [PATCH 07/12] Added a lot of constants :-) --- src/Core/Cache/Enum/Type.php | 35 ------------------- src/Core/Cache/Factory/Cache.php | 2 +- src/Core/Cache/Type/MemcacheCache.php | 2 +- src/Core/Hooks/Util/StrategiesFileManager.php | 5 +++ .../Type/AbstractKeyValueStorage.php | 2 ++ .../Type/DBKeyValueStorage.php | 1 + src/Core/Lock/Enum/Type.php | 4 +-- src/Core/Lock/Factory/Lock.php | 26 +++++++------- src/Core/Logger/Type/AbstractLogger.php | 2 ++ src/Core/Logger/Type/StreamLogger.php | 2 ++ src/Core/Logger/Type/SyslogLogger.php | 2 ++ .../PConfig/Type/AbstractPConfigValues.php | 2 ++ src/Core/PConfig/Type/JitPConfig.php | 2 ++ src/Core/PConfig/Type/PreloadPConfig.php | 2 ++ src/Core/Session/Factory/Session.php | 4 +-- static/strategies.config.php | 23 ++++++------ 16 files changed, 51 insertions(+), 65 deletions(-) delete mode 100644 src/Core/Cache/Enum/Type.php diff --git a/src/Core/Cache/Enum/Type.php b/src/Core/Cache/Enum/Type.php deleted file mode 100644 index 98ed9e41f..000000000 --- a/src/Core/Cache/Enum/Type.php +++ /dev/null @@ -1,35 +0,0 @@ -. - * - */ - -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'; -} diff --git a/src/Core/Cache/Factory/Cache.php b/src/Core/Cache/Factory/Cache.php index 000233df7..189c574aa 100644 --- a/src/Core/Cache/Factory/Cache.php +++ b/src/Core/Cache/Factory/Cache.php @@ -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 */ diff --git a/src/Core/Cache/Type/MemcacheCache.php b/src/Core/Cache/Type/MemcacheCache.php index fccaff6c0..e8d3b07c8 100644 --- a/src/Core/Cache/Type/MemcacheCache.php +++ b/src/Core/Cache/Type/MemcacheCache.php @@ -33,7 +33,7 @@ use Memcache; */ class MemcacheCache extends AbstractCache implements ICanCacheInMemory { - const NAME = 'memcached'; + const NAME = 'memcache'; use CompareSetTrait; use CompareDeleteTrait; diff --git a/src/Core/Hooks/Util/StrategiesFileManager.php b/src/Core/Hooks/Util/StrategiesFileManager.php index d6651ac98..860166fb6 100644 --- a/src/Core/Hooks/Util/StrategiesFileManager.php +++ b/src/Core/Hooks/Util/StrategiesFileManager.php @@ -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'; diff --git a/src/Core/KeyValueStorage/Type/AbstractKeyValueStorage.php b/src/Core/KeyValueStorage/Type/AbstractKeyValueStorage.php index 6b1666527..5d1b1f9d4 100644 --- a/src/Core/KeyValueStorage/Type/AbstractKeyValueStorage.php +++ b/src/Core/KeyValueStorage/Type/AbstractKeyValueStorage.php @@ -28,6 +28,8 @@ use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs; */ abstract class AbstractKeyValueStorage implements IManageKeyValuePairs { + const NAME = ''; + /** {@inheritDoc} */ public function get(string $key) { diff --git a/src/Core/KeyValueStorage/Type/DBKeyValueStorage.php b/src/Core/KeyValueStorage/Type/DBKeyValueStorage.php index d31f3c1ce..cc152f0c9 100644 --- a/src/Core/KeyValueStorage/Type/DBKeyValueStorage.php +++ b/src/Core/KeyValueStorage/Type/DBKeyValueStorage.php @@ -30,6 +30,7 @@ use Friendica\Database\Database; */ class DBKeyValueStorage extends AbstractKeyValueStorage { + const NAME = 'database'; const DB_KEY_VALUE_TABLE = 'key-value'; /** @var Database */ diff --git a/src/Core/Lock/Enum/Type.php b/src/Core/Lock/Enum/Type.php index 9e6e9194d..3a623b637 100644 --- a/src/Core/Lock/Enum/Type.php +++ b/src/Core/Lock/Enum/Type.php @@ -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'; } diff --git a/src/Core/Lock/Factory/Lock.php b/src/Core/Lock/Factory/Lock.php index bc4650c97..a60bc5a96 100644 --- a/src/Core/Lock/Factory/Lock.php +++ b/src/Core/Lock/Factory/Lock.php @@ -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); } } diff --git a/src/Core/Logger/Type/AbstractLogger.php b/src/Core/Logger/Type/AbstractLogger.php index e592ee86d..7de0e4160 100644 --- a/src/Core/Logger/Type/AbstractLogger.php +++ b/src/Core/Logger/Type/AbstractLogger.php @@ -38,6 +38,8 @@ use Psr\Log\LogLevel; */ abstract class AbstractLogger implements LoggerInterface { + const NAME = ''; + /** * The output channel of this logger * @var string diff --git a/src/Core/Logger/Type/StreamLogger.php b/src/Core/Logger/Type/StreamLogger.php index e09a32047..8cadd8cc7 100644 --- a/src/Core/Logger/Type/StreamLogger.php +++ b/src/Core/Logger/Type/StreamLogger.php @@ -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 diff --git a/src/Core/Logger/Type/SyslogLogger.php b/src/Core/Logger/Type/SyslogLogger.php index fb8cb97ae..556351a7e 100644 --- a/src/Core/Logger/Type/SyslogLogger.php +++ b/src/Core/Logger/Type/SyslogLogger.php @@ -32,6 +32,8 @@ use Psr\Log\LogLevel; */ class SyslogLogger extends AbstractLogger { + const NAME = 'syslog'; + const IDENT = 'Friendica'; /** @var int The default syslog flags */ diff --git a/src/Core/PConfig/Type/AbstractPConfigValues.php b/src/Core/PConfig/Type/AbstractPConfigValues.php index 39be8f4e7..e567cbaed 100644 --- a/src/Core/PConfig/Type/AbstractPConfigValues.php +++ b/src/Core/PConfig/Type/AbstractPConfigValues.php @@ -34,6 +34,8 @@ use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; */ abstract class AbstractPConfigValues implements IManagePersonalConfigValues { + const NAME = ''; + /** * @var Cache */ diff --git a/src/Core/PConfig/Type/JitPConfig.php b/src/Core/PConfig/Type/JitPConfig.php index c5c20577e..b851015e7 100644 --- a/src/Core/PConfig/Type/JitPConfig.php +++ b/src/Core/PConfig/Type/JitPConfig.php @@ -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) */ diff --git a/src/Core/PConfig/Type/PreloadPConfig.php b/src/Core/PConfig/Type/PreloadPConfig.php index b3b709286..6ae028c5e 100644 --- a/src/Core/PConfig/Type/PreloadPConfig.php +++ b/src/Core/PConfig/Type/PreloadPConfig.php @@ -32,6 +32,8 @@ use Friendica\Core\PConfig\ValueObject; */ class PreloadPConfig extends AbstractPConfigValues { + const NAME = 'preload'; + /** @var array */ private $config_loaded; diff --git a/src/Core/Session/Factory/Session.php b/src/Core/Session/Factory/Session.php index 239b050e7..e12dbd9af 100644 --- a/src/Core/Session/Factory/Session.php +++ b/src/Core/Session/Factory/Session.php @@ -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); diff --git a/static/strategies.config.php b/static/strategies.config.php index 8df0c0478..18872dc1d 100644 --- a/static/strategies.config.php +++ b/static/strategies.config.php @@ -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], ], ]; From 0c6efe50c320b8f6e7610e400688d751afd257b8 Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 28 Jul 2023 17:16:30 +0200 Subject: [PATCH 08/12] Remove unused parameter --- src/Core/Cache/Factory/Cache.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/Core/Cache/Factory/Cache.php b/src/Core/Cache/Factory/Cache.php index 189c574aa..0c54bfe63 100644 --- a/src/Core/Cache/Factory/Cache.php +++ b/src/Core/Cache/Factory/Cache.php @@ -21,7 +21,6 @@ namespace Friendica\Core\Cache\Factory; -use Friendica\Core\Cache\Enum; use Friendica\Core\Cache\Capability\ICanCache; use Friendica\Core\Cache\Exception\CachePersistenceException; use Friendica\Core\Cache\Exception\InvalidCacheDriverException; @@ -58,22 +57,16 @@ class Cache } /** - * This method creates a CacheDriver for distributed caching with the given cache driver name - * - * @param string|null $type The cache type to create (default is per config) + * This method creates a CacheDriver for distributed caching * * @return ICanCache The instance of the CacheDriver * * @throws InvalidCacheDriverException In case the underlying cache driver isn't valid or not configured properly * @throws CachePersistenceException In case the underlying cache has errors during persistence */ - public function createDistributed(string $type = null): ICanCache + public function createDistributed(): ICanCache { - if ($type === Type\APCuCache::NAME) { - throw new InvalidCacheDriverException('apcu doesn\'t support distributed caching.'); - } - - return $this->create($type ?? $this->config->get('system', 'distributed_cache_driver', self::DEFAULT_TYPE)); + return $this->create($this->config->get('system', 'distributed_cache_driver', self::DEFAULT_TYPE)); } /** From 5291401de01f73a8aa1f4cad578672afa271f88e Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 28 Jul 2023 17:45:31 +0200 Subject: [PATCH 09/12] rename woodpecker "pipeline" to "steps" --- .woodpecker/.code_standards_check.yml | 2 +- .woodpecker/.continuous-deployment.yml | 2 +- .woodpecker/.database_checks.yml | 2 +- .woodpecker/.license_check.yml | 2 +- .woodpecker/.messages.po_check.yml | 4 ++-- .woodpecker/.phpunit.yml | 2 +- .woodpecker/.releaser.yml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.woodpecker/.code_standards_check.yml b/.woodpecker/.code_standards_check.yml index f81ab960f..0c951d701 100644 --- a/.woodpecker/.code_standards_check.yml +++ b/.woodpecker/.code_standards_check.yml @@ -1,4 +1,4 @@ -pipeline: +steps: restore_cache: image: meltwater/drone-cache:dev settings: diff --git a/.woodpecker/.continuous-deployment.yml b/.woodpecker/.continuous-deployment.yml index 767fffde3..3d49ed37e 100644 --- a/.woodpecker/.continuous-deployment.yml +++ b/.woodpecker/.continuous-deployment.yml @@ -11,7 +11,7 @@ labels: skip_clone: true -pipeline: +steps: clone: image: alpine/git commands: diff --git a/.woodpecker/.database_checks.yml b/.woodpecker/.database_checks.yml index 04bdeed62..daeff7ac3 100644 --- a/.woodpecker/.database_checks.yml +++ b/.woodpecker/.database_checks.yml @@ -6,7 +6,7 @@ matrix: branches: exclude: [ stable ] -pipeline: +steps: db_version_match: image: friendicaci/transifex commands: diff --git a/.woodpecker/.license_check.yml b/.woodpecker/.license_check.yml index 777986544..e7545f5f4 100644 --- a/.woodpecker/.license_check.yml +++ b/.woodpecker/.license_check.yml @@ -1,4 +1,4 @@ -pipeline: +steps: check: image: friendicaci/php-cs commands: diff --git a/.woodpecker/.messages.po_check.yml b/.woodpecker/.messages.po_check.yml index c5b283e1d..9c2509594 100644 --- a/.woodpecker/.messages.po_check.yml +++ b/.woodpecker/.messages.po_check.yml @@ -1,4 +1,4 @@ -pipeline: +steps: build_xgettext: image: friendicaci/transifex commands: @@ -9,4 +9,4 @@ pipeline: - /check-messages.sh branches: - exclude: [ stable ] \ No newline at end of file + exclude: [ stable ] diff --git a/.woodpecker/.phpunit.yml b/.woodpecker/.phpunit.yml index 8f89e4b5b..290da6b70 100644 --- a/.woodpecker/.phpunit.yml +++ b/.woodpecker/.phpunit.yml @@ -15,7 +15,7 @@ matrix: labels: location: opensocial -pipeline: +steps: php-lint: image: php:${PHP_MAJOR_VERSION} group: lint diff --git a/.woodpecker/.releaser.yml b/.woodpecker/.releaser.yml index 482ea5429..2562e7872 100644 --- a/.woodpecker/.releaser.yml +++ b/.woodpecker/.releaser.yml @@ -9,7 +9,7 @@ labels: skip_clone: true -pipeline: +steps: clone: image: alpine/git commands: From bed13f71bda93c64c2eadf6179faec570f4e3bf9 Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 28 Jul 2023 18:55:06 +0200 Subject: [PATCH 10/12] use default_key --- src/Core/KeyValueStorage/Factory/KeyValueStorage.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Core/KeyValueStorage/Factory/KeyValueStorage.php b/src/Core/KeyValueStorage/Factory/KeyValueStorage.php index ee6cb1731..467006614 100644 --- a/src/Core/KeyValueStorage/Factory/KeyValueStorage.php +++ b/src/Core/KeyValueStorage/Factory/KeyValueStorage.php @@ -22,6 +22,7 @@ namespace Friendica\Core\KeyValueStorage\Factory; use Friendica\Core\Hooks\Capability\ICanCreateInstances; +use Friendica\Core\Hooks\Util\StrategiesFileManager; use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs; class KeyValueStorage @@ -29,6 +30,6 @@ class KeyValueStorage public function create(ICanCreateInstances $instanceCreator): IManageKeyValuePairs { /** @var IManageKeyValuePairs */ - return $instanceCreator->create(IManageKeyValuePairs::class, ''); + return $instanceCreator->create(IManageKeyValuePairs::class, StrategiesFileManager::STRATEGY_DEFAULT_KEY); } } From 8ee58aaf181c0512b957ac9fa6718e3932b38134 Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 28 Jul 2023 19:02:08 +0200 Subject: [PATCH 11/12] try making php-lint faster.. --- .woodpecker/.phpunit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.woodpecker/.phpunit.yml b/.woodpecker/.phpunit.yml index 290da6b70..302bd911d 100644 --- a/.woodpecker/.phpunit.yml +++ b/.woodpecker/.phpunit.yml @@ -20,7 +20,7 @@ steps: image: php:${PHP_MAJOR_VERSION} group: lint commands: - - ./bin/composer.phar run lint + - find . -name \*.php -not -path './vendor/*' -not -path './view/asset/*' -print0 | xargs -0 -n1 php -l restore_cache: image: meltwater/drone-cache:dev settings: From e231907b3c00223909bfbef19998a42d3e198a4a Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 28 Jul 2023 19:07:29 +0200 Subject: [PATCH 12/12] add opensocial as location for db-based execution --- .woodpecker/.database_checks.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.woodpecker/.database_checks.yml b/.woodpecker/.database_checks.yml index daeff7ac3..7d2553674 100644 --- a/.woodpecker/.database_checks.yml +++ b/.woodpecker/.database_checks.yml @@ -6,6 +6,10 @@ matrix: branches: exclude: [ stable ] +# This forces CI executions at the "opensocial" labeled location (because of much more power...) +labels: + location: opensocial + steps: db_version_match: image: friendicaci/transifex