Browse Source

Merge pull request #10918 from nupplaphil/feat/core_new_paradigm

Paradigm Restructuring Part 1 - Core classes
pull/10716/merge
Hypolite Petovan 7 months ago committed by GitHub
parent
commit
24f8ee8e67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      doc/AddonStorageBackend.md
  2. 2
      index.php
  3. 2
      mod/ping.php
  4. 49
      src/App.php
  5. 10
      src/App/BaseURL.php
  6. 2
      src/App/Mode.php
  7. 9
      src/App/Module.php
  8. 32
      src/App/Page.php
  9. 14
      src/App/Router.php
  10. 14
      src/Console/AutomaticInstallation.php
  11. 8
      src/Console/Cache.php
  12. 6
      src/Console/Config.php
  13. 2
      src/Console/DatabaseStructure.php
  14. 6
      src/Console/Lock.php
  15. 6
      src/Console/Maintenance.php
  16. 6
      src/Console/PostUpdate.php
  17. 26
      src/Console/ServerBlock.php
  18. 6
      src/Console/Typo.php
  19. 6
      src/Console/User.php
  20. 12
      src/Content/Conversation.php
  21. 2
      src/Content/OEmbed.php
  22. 2
      src/Content/Widget.php
  23. 42
      src/Core/Cache/Capability/ICanCache.php
  24. 39
      src/Core/Cache/Capability/ICanCacheInMemory.php
  25. 138
      src/Core/Cache/DatabaseCache.php
  26. 2
      src/Core/Cache/Enum/Duration.php
  27. 2
      src/Core/Cache/Enum/Type.php
  28. 13
      src/Core/Cache/Exception/CachePersistenceException.php
  29. 13
      src/Core/Cache/Exception/InvalidCacheDriverException.php
  30. 49
      src/Core/Cache/Factory/Cache.php
  31. 63
      src/Core/Cache/Type/APCuCache.php
  32. 26
      src/Core/Cache/Type/AbstractCache.php
  33. 29
      src/Core/Cache/Type/ArrayCache.php
  34. 26
      src/Core/Cache/Type/CompareDeleteTrait.php
  35. 29
      src/Core/Cache/Type/CompareSetTrait.php
  36. 165
      src/Core/Cache/Type/DatabaseCache.php
  37. 76
      src/Core/Cache/Type/MemcacheCache.php
  38. 27
      src/Core/Cache/Type/MemcacheCommandTrait.php
  39. 78
      src/Core/Cache/Type/MemcachedCache.php
  40. 40
      src/Core/Cache/Type/ProfilerCacheDecorator.php
  41. 91
      src/Core/Cache/Type/RedisCache.php
  42. 40
      src/Core/Config/Capability/IManageConfigValues.php
  43. 13
      src/Core/Config/Exception/ConfigFileException.php
  44. 13
      src/Core/Config/Exception/ConfigPersistenceException.php
  45. 61
      src/Core/Config/Factory/Config.php
  46. 187
      src/Core/Config/Repository/Config.php
  47. 28
      src/Core/Config/Type/AbstractConfig.php
  48. 50
      src/Core/Config/Type/JitConfig.php
  49. 51
      src/Core/Config/Type/PreloadConfig.php
  50. 52
      src/Core/Config/Util/ConfigFileLoader.php
  51. 62
      src/Core/Config/Util/ValueConversion.php
  52. 27
      src/Core/Config/ValueObject/Cache.php
  53. 8
      src/Core/Installer.php
  54. 10
      src/Core/L10n.php
  55. 162
      src/Core/Lock/CacheLock.php
  56. 37
      src/Core/Lock/Capability/ICanLock.php
  57. 178
      src/Core/Lock/DatabaseLock.php
  58. 4
      src/Core/Lock/Enum/Type.php
  59. 13
      src/Core/Lock/Exception/InvalidLockDriverException.php
  60. 13
      src/Core/Lock/Exception/LockPersistenceException.php
  61. 50
      src/Core/Lock/Factory/Lock.php
  62. 14
      src/Core/Lock/Type/AbstractLock.php
  63. 180
      src/Core/Lock/Type/CacheLock.php
  64. 212
      src/Core/Lock/Type/DatabaseLock.php
  65. 26
      src/Core/Lock/Type/SemaphoreLock.php
  66. 36
      src/Core/PConfig/Capability/IManagePersonalConfigValues.php
  67. 13
      src/Core/PConfig/Exception/PConfigPersistenceException.php
  68. 49
      src/Core/PConfig/Factory/PConfig.php
  69. 105
      src/Core/PConfig/Repository/PConfig.php
  70. 26
      src/Core/PConfig/Type/AbstractPConfigValues.php
  71. 36
      src/Core/PConfig/Type/JitPConfig.php
  72. 26
      src/Core/PConfig/Type/PreloadPConfig.php
  73. 31
      src/Core/PConfig/ValueObject/Cache.php
  74. 8
      src/Core/Process.php
  75. 8
      src/Core/Session/Capability/IHandleSessions.php
  76. 48
      src/Core/Session/Factory/Session.php
  77. 67
      src/Core/Session/Handler/Cache.php
  78. 75
      src/Core/Session/Handler/Database.php
  79. 10
      src/Core/Session/Type/AbstractSession.php
  80. 6
      src/Core/Session/Type/Memory.php
  81. 7
      src/Core/Session/Type/Native.php
  82. 14
      src/Core/StorageManager.php
  83. 4
      src/Core/Update.php
  84. 20
      src/DI.php
  85. 4
      src/Database/Database.php
  86. 6
      src/Factory/HTTPClientFactory.php
  87. 20
      src/Factory/LoggerFactory.php
  88. 2
      src/Model/APContact.php
  89. 150
      src/Model/Config/Config.php
  90. 105
      src/Model/Config/DbaConfig.php
  91. 2
      src/Model/Photo.php
  92. 2
      src/Model/Profile.php
  93. 10
      src/Model/Storage/FilesystemConfig.php
  94. 2
      src/Model/Tag.php
  95. 12
      src/Model/User/Cookie.php
  96. 8
      src/Module/Admin/Summary.php
  97. 12
      src/Module/Install.php
  98. 2
      src/Module/Search/Index.php
  99. 10
      src/Navigation/Notifications/Factory/Introduction.php
  100. 6
      src/Navigation/Notifications/Repository/Notify.php
  101. Some files were not shown because too many files have changed in this diff Show More

8
doc/AddonStorageBackend.md

@ -188,7 +188,7 @@ namespace Friendica\Addon\samplestorage;
use Friendica\Model\Storage\IWritableStorage;
use Friendica\Core\Config\IConfig;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\L10n;
class SampleStorageBackend implements IWritableStorage
@ -249,12 +249,12 @@ namespace Friendica\Addon\samplestorage;
use Friendica\Model\Storage\IStorageConfiguration;
use Friendica\Core\Config\IConfig;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\L10n;
class SampleStorageBackendConfig implements IStorageConfiguration
{
/** @var IConfig */
/** @var \Friendica\Core\Config\Capability\IManageConfigValues */
private $config;
/** @var L10n */
private $l10n;
@ -265,7 +265,7 @@ class SampleStorageBackendConfig implements IStorageConfiguration
* You can add here every dynamic class as dependency you like and add them to a private field
* Friendica automatically creates these classes and passes them as argument to the constructor
*/
public function __construct(IConfig $config, L10n $l10n)
public function __construct(IManageConfigValues $config, L10n $l10n)
{
$this->config = $config;
$this->l10n = $l10n;

2
index.php

@ -43,7 +43,7 @@ $a = \Friendica\DI::app();
$a->runFrontend(
$dice->create(\Friendica\App\Module::class),
$dice->create(\Friendica\App\Router::class),
$dice->create(\Friendica\Core\PConfig\IPConfig::class),
$dice->create(\Friendica\Core\PConfig\Capability\IManagePersonalConfigValues::class),
$dice->create(\Friendica\Security\Authentication::class),
$dice->create(\Friendica\App\Page::class),
$start_time

2
mod/ping.php

@ -22,7 +22,7 @@
use Friendica\App;
use Friendica\Content\ForumManager;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Hook;
use Friendica\Database\DBA;
use Friendica\DI;

49
src/App.php

@ -25,12 +25,12 @@ use Exception;
use Friendica\App\Arguments;
use Friendica\App\BaseURL;
use Friendica\App\Module;
use Friendica\Factory\ConfigFactory;
use Friendica\Core\Config\Factory\Config;
use Friendica\Module\Maintenance;
use Friendica\Security\Authentication;
use Friendica\Core\Config\Cache;
use Friendica\Core\Config\IConfig;
use Friendica\Core\PConfig\IPConfig;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Core\Theme;
@ -39,7 +39,6 @@ use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Module\Special\HTTPException as ModuleHTTPException;
use Friendica\Network\HTTPException;
use Friendica\Util\ConfigFileLoader;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\HTTPSignature;
use Friendica\Util\Profiler;
@ -89,7 +88,7 @@ class App
private $currentMobileTheme;
/**
* @var IConfig The config
* @var IManageConfigValues The config
*/
private $config;
@ -124,7 +123,7 @@ class App
private $process;
/**
* @var IPConfig
* @var IManagePersonalConfigValues
*/
private $pConfig;
@ -306,18 +305,18 @@ class App
}
/**
* @param Database $database The Friendica Database
* @param IConfig $config The Configuration
* @param App\Mode $mode The mode of this Friendica app
* @param BaseURL $baseURL The full base URL of this Friendica app
* @param LoggerInterface $logger The current app logger
* @param Profiler $profiler The profiler of this application
* @param L10n $l10n The translator instance
* @param App\Arguments $args The Friendica Arguments of the call
* @param Core\Process $process The process methods
* @param IPConfig $pConfig Personal configuration
* @param Database $database The Friendica Database
* @param IManageConfigValues $config The Configuration
* @param App\Mode $mode The mode of this Friendica app
* @param BaseURL $baseURL The full base URL of this Friendica app
* @param LoggerInterface $logger The current app logger
* @param Profiler $profiler The profiler of this application
* @param L10n $l10n The translator instance
* @param App\Arguments $args The Friendica Arguments of the call
* @param Core\Process $process The process methods
* @param IManagePersonalConfigValues $pConfig Personal configuration
*/
public function __construct(Database $database, IConfig $config, App\Mode $mode, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, Core\Process $process, IPConfig $pConfig)
public function __construct(Database $database, IManageConfigValues $config, App\Mode $mode, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, Core\Process $process, IManagePersonalConfigValues $pConfig)
{
$this->database = $database;
$this->config = $config;
@ -358,7 +357,7 @@ class App
$this->profiler->update($this->config);
Core\Hook::loadHooks();
$loader = (new ConfigFactory())->createConfigFileLoader($this->getBasePath(), $_SERVER);
$loader = (new Config())->createConfigFileLoader($this->getBasePath(), $_SERVER);
Core\Hook::callAll('load_config', $loader);
}
@ -553,16 +552,16 @@ class App
*
* This probably should change to limit the size of this monster method.
*
* @param App\Module $module The determined module
* @param App\Router $router
* @param IPConfig $pconfig
* @param Authentication $auth The Authentication backend of the node
* @param App\Page $page The Friendica page printing container
* @param App\Module $module The determined module
* @param App\Router $router
* @param IManagePersonalConfigValues $pconfig
* @param Authentication $auth The Authentication backend of the node
* @param App\Page $page The Friendica page printing container
*
* @throws HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public function runFrontend(App\Module $module, App\Router $router, IPConfig $pconfig, Authentication $auth, App\Page $page, float $start_time)
public function runFrontend(App\Module $module, App\Router $router, IManagePersonalConfigValues $pconfig, Authentication $auth, App\Page $page, float $start_time)
{
$this->profiler->set($start_time, 'start');
$this->profiler->set(microtime(true), 'classinit');

10
src/App/BaseURL.php

@ -21,7 +21,7 @@
namespace Friendica\App;
use Friendica\Core\Config\IConfig;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\System;
use Friendica\Util\Network;
use Friendica\Util\Strings;
@ -56,7 +56,7 @@ class BaseURL
/**
* The Friendica Config
*
* @var IConfig
* @var IManageConfigValues
*/
private $config;
@ -272,10 +272,10 @@ class BaseURL
}
/**
* @param IConfig $config The Friendica IConfiguration
* @param array $server The $_SERVER array
* @param IManageConfigValues $config The Friendica IConfiguration
* @param array $server The $_SERVER array
*/
public function __construct(IConfig $config, array $server)
public function __construct(IManageConfigValues $config, array $server)
{
$this->config = $config;
$this->server = $server;

2
src/App/Mode.php

@ -22,7 +22,7 @@
namespace Friendica\App;
use Detection\MobileDetect;
use Friendica\Core\Config\Cache;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Database\Database;
use Friendica\Util\BasePath;

9
src/App/Module.php

@ -24,6 +24,7 @@ namespace Friendica\App;
use Friendica\App;
use Friendica\BaseModule;
use Friendica\Core;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\LegacyModule;
use Friendica\Module\Home;
use Friendica\Module\HTTPException\MethodNotAllowed;
@ -168,15 +169,15 @@ class Module
/**
* Determine the class of the current module
*
* @param Arguments $args The Friendica execution arguments
* @param Router $router The Friendica routing instance
* @param Core\Config\IConfig $config The Friendica Configuration
* @param Arguments $args The Friendica execution arguments
* @param Router $router The Friendica routing instance
* @param IManageConfigValues $config The Friendica Configuration
*
* @return Module The determined module of this call
*
* @throws \Exception
*/
public function determineClass(Arguments $args, Router $router, Core\Config\IConfig $config)
public function determineClass(Arguments $args, Router $router, IManageConfigValues $config)
{
$printNotAllowedAddon = false;

32
src/App/Page.php

@ -26,8 +26,8 @@ use DOMDocument;
use DOMXPath;
use Friendica\App;
use Friendica\Content\Nav;
use Friendica\Core\Config\IConfig;
use Friendica\Core\PConfig\IPConfig;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
@ -190,15 +190,15 @@ class Page implements ArrayAccess
* - Infinite scroll data
* - head.tpl template
*
* @param App $app The Friendica App instance
* @param Module $module The loaded Friendica module
* @param L10n $l10n The l10n language instance
* @param IConfig $config The Friendica configuration
* @param IPConfig $pConfig The Friendica personal configuration (for user)
* @param App $app The Friendica App instance
* @param Module $module The loaded Friendica module
* @param L10n $l10n The l10n language instance
* @param IManageConfigValues $config The Friendica configuration
* @param IManagePersonalConfigValues $pConfig The Friendica personal configuration (for user)
*
* @throws HTTPException\InternalServerErrorException
*/
private function initHead(App $app, Module $module, L10n $l10n, IConfig $config, IPConfig $pConfig)
private function initHead(App $app, Module $module, L10n $l10n, IManageConfigValues $config, IManagePersonalConfigValues $pConfig)
{
$interval = ((local_user()) ? $pConfig->get(local_user(), 'system', 'update_interval') : 40000);
@ -367,17 +367,17 @@ class Page implements ArrayAccess
/**
* Executes the creation of the current page and prints it to the screen
*
* @param App $app The Friendica App
* @param BaseURL $baseURL The Friendica Base URL
* @param Mode $mode The current node mode
* @param Module $module The loaded Friendica module
* @param L10n $l10n The l10n language class
* @param IConfig $config The Configuration of this node
* @param IPConfig $pconfig The personal/user configuration
* @param App $app The Friendica App
* @param BaseURL $baseURL The Friendica Base URL
* @param Mode $mode The current node mode
* @param Module $module The loaded Friendica module
* @param L10n $l10n The l10n language class
* @param IManageConfigValues $config The Configuration of this node
* @param IManagePersonalConfigValues $pconfig The personal/user configuration
*
* @throws HTTPException\InternalServerErrorException
*/
public function run(App $app, BaseURL $baseURL, Mode $mode, Module $module, L10n $l10n, Profiler $profiler, IConfig $config, IPConfig $pconfig)
public function run(App $app, BaseURL $baseURL, Mode $mode, Module $module, L10n $l10n, Profiler $profiler, IManageConfigValues $config, IManagePersonalConfigValues $pconfig)
{
$moduleName = $module->getName();

14
src/App/Router.php

@ -26,11 +26,11 @@ use FastRoute\DataGenerator\GroupCountBased;
use FastRoute\Dispatcher;
use FastRoute\RouteCollector;
use FastRoute\RouteParser\Std;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\ICache;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Cache\Capability\ICanCache;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Lock\ILock;
use Friendica\Core\Lock\Capability\ICanLock;
use Friendica\Network\HTTPException;
/**
@ -77,10 +77,10 @@ class Router
/** @var L10n */
private $l10n;
/** @var ICache */
/** @var ICanCache */
private $cache;
/** @var ILock */
/** @var ICanLock */
private $lock;
/** @var string */
@ -90,10 +90,10 @@ class Router
* @param array $server The $_SERVER variable
* @param string $baseRoutesFilepath The path to a base routes file to leverage cache, can be empty
* @param L10n $l10n
* @param ICache $cache
* @param ICanCache $cache
* @param RouteCollector|null $routeCollector
*/
public function __construct(array $server, string $baseRoutesFilepath, L10n $l10n, ICache $cache, ILock $lock, RouteCollector $routeCollector = null)
public function __construct(array $server, string $baseRoutesFilepath, L10n $l10n, ICanCache $cache, ICanLock $lock, RouteCollector $routeCollector = null)
{
$this->baseRoutesFilepath = $baseRoutesFilepath;
$this->l10n = $l10n;

14
src/Console/AutomaticInstallation.php

@ -24,8 +24,8 @@ namespace Friendica\Console;
use Asika\SimpleConsole\Console;
use Friendica\App;
use Friendica\App\BaseURL;
use Friendica\Core\Config\IConfig;
use Friendica\Core\Config\Cache;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Core\Installer;
use Friendica\Core\Theme;
use Friendica\Database\Database;
@ -36,9 +36,9 @@ class AutomaticInstallation extends Console
{
/** @var App\Mode */
private $appMode;
/** @var Cache */
/** @var \Friendica\Core\Config\ValueObject\Cache */
private $configCache;
/** @var IConfig */
/** @var IManageConfigValues */
private $config;
/** @var Database */
private $dba;
@ -98,7 +98,7 @@ Examples
HELP;
}
public function __construct(App\Mode $appMode, Cache $configCache, IConfig $config, Database $dba, array $argv = null)
public function __construct(App\Mode $appMode, Cache $configCache, IManageConfigValues $config, Database $dba, array $argv = null)
{
parent::__construct($argv);
@ -252,8 +252,8 @@ HELP;
}
/**
* @param Installer $installer The Installer instance
* @param Cache $configCache The config cache
* @param Installer $installer The Installer instance
* @param \Friendica\Core\Config\ValueObject\Cache $configCache The config cache
*
* @return bool true if checks were successfully, otherwise false
* @throws \Friendica\Network\HTTPException\InternalServerErrorException

8
src/Console/Cache.php

@ -23,8 +23,8 @@ namespace Friendica\Console;
use Asika\SimpleConsole\CommandArgsException;
use Friendica\App;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\ICache;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Cache\Capability\ICanCache;
use RuntimeException;
/**
@ -44,7 +44,7 @@ class Cache extends \Asika\SimpleConsole\Console
private $appMode;
/**
* @var ICache
* @var ICanCache
*/
private $cache;
@ -82,7 +82,7 @@ HELP;
return $help;
}
public function __construct(App\Mode $appMode, ICache $cache, array $argv = null)
public function __construct(App\Mode $appMode, ICanCache $cache, array $argv = null)
{
parent::__construct($argv);

6
src/Console/Config.php

@ -23,7 +23,7 @@ namespace Friendica\Console;
use Asika\SimpleConsole\CommandArgsException;
use Friendica\App;
use Friendica\Core\Config\IConfig;
use Friendica\Core\Config\Capability\IManageConfigValues;
use RuntimeException;
/**
@ -56,7 +56,7 @@ class Config extends \Asika\SimpleConsole\Console
*/
private $appMode;
/**
* @var IConfig
* @var IManageConfigValues
*/
private $config;
@ -94,7 +94,7 @@ HELP;
return $help;
}
public function __construct(App\Mode $appMode, IConfig $config, array $argv = null)
public function __construct(App\Mode $appMode, IManageConfigValues $config, array $argv = null)
{
parent::__construct($argv);

2
src/Console/DatabaseStructure.php

@ -21,7 +21,7 @@
namespace Friendica\Console;
use Friendica\Core\Config\Cache;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Core\Update;
use Friendica\Database\Database;
use Friendica\Database\DBStructure;

6
src/Console/Lock.php

@ -23,7 +23,7 @@ namespace Friendica\Console;
use Asika\SimpleConsole\CommandArgsException;
use Friendica\App;
use Friendica\Core\Lock\ILock;
use Friendica\Core\Lock\Capability\ICanLock;
use RuntimeException;
/**
@ -42,7 +42,7 @@ class Lock extends \Asika\SimpleConsole\Console
private $appMode;
/**
* @var ILock
* @var ICanLock
*/
private $lock;
@ -76,7 +76,7 @@ HELP;
return $help;
}
public function __construct(App\Mode $appMode, ILock $lock, array $argv = null)
public function __construct(App\Mode $appMode, ICanLock $lock, array $argv = null)
{
parent::__construct($argv);

6
src/Console/Maintenance.php

@ -22,7 +22,7 @@
namespace Friendica\Console;
use Friendica\App;
use Friendica\Core\Config\IConfig;
use Friendica\Core\Config\Capability\IManageConfigValues;
/**
* Sets maintenance mode for this node
@ -36,7 +36,7 @@ class Maintenance extends \Asika\SimpleConsole\Console
*/
private $appMode;
/**
* @var IConfig
* @var IManageConfigValues
*/
private $config;
@ -69,7 +69,7 @@ HELP;
return $help;
}
public function __construct(App\Mode $appMode, IConfig $config, $argv = null)
public function __construct(App\Mode $appMode, IManageConfigValues $config, $argv = null)
{
parent::__construct($argv);

6
src/Console/PostUpdate.php

@ -22,7 +22,7 @@
namespace Friendica\Console;
use Friendica\App;
use Friendica\Core\Config\IConfig;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\L10n;
use Friendica\Core\Update;
@ -38,7 +38,7 @@ class PostUpdate extends \Asika\SimpleConsole\Console
*/
private $appMode;
/**
* @var IConfig
* @var IManageConfigValues
*/
private $config;
/**
@ -60,7 +60,7 @@ HELP;
return $help;
}
public function __construct(App\Mode $appMode, IConfig $config, L10n $l10n, array $argv = null)
public function __construct(App\Mode $appMode, IManageConfigValues $config, L10n $l10n, array $argv = null)
{
parent::__construct($argv);

26
src/Console/ServerBlock.php

@ -24,7 +24,7 @@ namespace Friendica\Console;
use Asika\SimpleConsole\CommandArgsException;
use Asika\SimpleConsole\Console;
use Console_Table;
use Friendica\Core\Config\IConfig;
use Friendica\Core\Config\Capability\IManageConfigValues;
/**
* Manage blocked servers
@ -39,7 +39,7 @@ class ServerBlock extends Console
protected $helpOptions = ['h', 'help', '?'];
/**
* @var IConfig
* @var IManageConfigValues
*/
private $config;
@ -72,7 +72,7 @@ HELP;
return $help;
}
public function __construct(IConfig $config, $argv = null)
public function __construct(IManageConfigValues $config, $argv = null)
{
parent::__construct($argv);
@ -105,9 +105,9 @@ HELP;
* Exports the list of blocked domains including the reason for the
* block to a CSV file.
*
* @param IConfig $config
* @param IManageConfigValues $config
*/
private function exportBlockedServers(IConfig $config)
private function exportBlockedServers(IManageConfigValues $config)
{
$filename = $this->getArgument(1);
$blocklist = $config->get('system', 'blocklist', []);
@ -123,9 +123,9 @@ HELP;
* Imports a list of domains and a reason for the block from a CSV
* file, e.g. created with the export function.
*
* @param IConfig $config
* @param IManageConfigValues $config
*/
private function importBlockedServers(IConfig $config)
private function importBlockedServers(IManageConfigValues $config)
{
$filename = $this->getArgument(1);
$currBlockList = $config->get('system', 'blocklist', []);
@ -167,9 +167,9 @@ HELP;
/**
* Prints the whole list of blocked domains including the reason
*
* @param IConfig $config
* @param IManageConfigValues $config
*/
private function printBlockedServers(IConfig $config)
private function printBlockedServers(IManageConfigValues $config)
{
$table = new Console_Table();
$table->setHeaders(['Domain', 'Reason']);
@ -183,11 +183,11 @@ HELP;
/**
* Adds a server to the blocked list
*
* @param IConfig $config
* @param IManageConfigValues $config
*
* @return int The return code (0 = success, 1 = failed)
*/
private function addBlockedServer(IConfig $config)
private function addBlockedServer(IManageConfigValues $config)
{
if (count($this->args) < 2 || count($this->args) > 3) {
throw new CommandArgsException('Add needs a domain and optional a reason.');
@ -235,11 +235,11 @@ HELP;
/**
* Removes a server from the blocked list
*
* @param IConfig $config
* @param IManageConfigValues $config
*
* @return int The return code (0 = success, 1 = failed)
*/
private function removeBlockedServer(IConfig $config)
private function removeBlockedServer(IManageConfigValues $config)
{
if (count($this->args) !== 2) {
throw new CommandArgsException('Remove needs a second parameter.');

6
src/Console/Typo.php

@ -21,7 +21,7 @@
namespace Friendica\Console;
use Friendica\Core\Config\IConfig;
use Friendica\Core\Config\Capability\IManageConfigValues;
/**
* Tired of chasing typos and finding them after a commit.
@ -32,7 +32,7 @@ class Typo extends \Asika\SimpleConsole\Console
protected $helpOptions = ['h', 'help', '?'];
/**
* @var IConfig
* @var IManageConfigValues
*/
private $config;
@ -53,7 +53,7 @@ HELP;
return $help;
}
public function __construct(IConfig $config, array $argv = null)
public function __construct(IManageConfigValues $config, array $argv = null)
{
parent::__construct($argv);

6
src/Console/User.php

@ -25,7 +25,7 @@ use Console_Table;
use Friendica\App;
use Friendica\Content\Pager;
use Friendica\Core\L10n;
use Friendica\Core\PConfig\IPConfig;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Model\Register;
use Friendica\Model\User as UserModel;
use Friendica\Util\Temporal;
@ -48,7 +48,7 @@ class User extends \Asika\SimpleConsole\Console
*/
private $l10n;
/**
* @var IPConfig
* @var IManagePersonalConfigValues
*/
private $pConfig;
@ -88,7 +88,7 @@ HELP;
return $help;
}
public function __construct(App\Mode $appMode, L10n $l10n, IPConfig $pConfig, array $argv = null)
public function __construct(App\Mode $appMode, L10n $l10n, IManagePersonalConfigValues $pConfig, array $argv = null)
{
parent::__construct($argv);

12
src/Content/Conversation.php

@ -26,10 +26,10 @@ use Friendica\App\Arguments;
use Friendica\App\BaseURL;
use Friendica\BaseModule;
use Friendica\Core\ACL;
use Friendica\Core\Config\IConfig;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\PConfig\IPConfig;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
@ -66,11 +66,11 @@ class Conversation
private $item;
/** @var App\Arguments */
private $args;
/** @var IPConfig */
/** @var IManagePersonalConfigValues */
private $pConfig;
/** @var BaseURL */
private $baseURL;
/** @var IConfig */
/** @var IManageConfigValues */
private $config;
/** @var App */
private $app;
@ -79,7 +79,7 @@ class Conversation
/** @var App\Mode */
private $mode;
public function __construct(LoggerInterface $logger, Profiler $profiler, Activity $activity, L10n $l10n, Item $item, Arguments $args, BaseURL $baseURL, IConfig $config, IPConfig $pConfig, App\Page $page, App\Mode $mode, App $app)
public function __construct(LoggerInterface $logger, Profiler $profiler, Activity $activity, L10n $l10n, Item $item, Arguments $args, BaseURL $baseURL, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, App\Page $page, App\Mode $mode, App $app)
{
$this->activity = $activity;
$this->item = $item;
@ -629,7 +629,7 @@ class Conversation
$body_html = ItemModel::prepareBody($item, true, $preview);
list($categories, $folders) = $this->item->determineCategoriesTerms($item, local_user());
[$categories, $folders] = $this->item->determineCategoriesTerms($item, local_user());
if (!empty($item['content-warning']) && $this->pConfig->get(local_user(), 'system', 'disable_cw', false)) {
$title = ucfirst($item['content-warning']);

2
src/Content/OEmbed.php

@ -26,7 +26,7 @@ use DOMNode;
use DOMText;
use DOMXPath;
use Exception;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Hook;
use Friendica\Core\Renderer;
use Friendica\Database\Database;

2
src/Content/Widget.php

@ -22,7 +22,7 @@
namespace Friendica\Content;
use Friendica\Core\Addon;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;

42
src/Core/Cache/ICache.php → src/Core/Cache/Capability/ICanCache.php

@ -19,21 +19,24 @@
*
*/
namespace Friendica\Core\Cache;
namespace Friendica\Core\Cache\Capability;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Cache\Exception\CachePersistenceException;
/**
* Cache Interface
* Interface for caches
*/
interface ICache
interface ICanCache
{
/**
* Lists all cache keys
*
* @param string prefix optional a prefix to search
* @param string|null prefix optional a prefix to search
*
* @return array Empty if it isn't supported by the cache driver
*/
public function getAllKeys($prefix = null);
public function getAllKeys(?string $prefix = null): array;
/**
* Fetches cached data according to the key
@ -41,41 +44,50 @@ interface ICache
* @param string $key The key to the cached data
*
* @return mixed Cached $value or "null" if not found
*
* @throws CachePersistenceException In case the underlying cache driver has errors during persistence
*/
public function get($key);
public function get(string $key);
/**
* Stores data in the cache identified by the key. The input $value can have multiple formats.
*
* @param string $key The cache key
* @param mixed $value The value to store
* @param integer $ttl The cache lifespan, must be one of the Cache constants
* @param string $key The cache key
* @param mixed $value The value to store
* @param integer $ttl The cache lifespan, must be one of the Cache constants
*
* @return bool
*
* @throws CachePersistenceException In case the underlying cache driver has errors during persistence
*/
public function set($key, $value, $ttl = Duration::FIVE_MINUTES);
public function set(string $key, $value, int $ttl = Duration::FIVE_MINUTES): bool;
/**
* Delete a key from the cache
*
* @param string $key The cache key
* @param string $key The cache key
*
* @return bool
*
* @throws CachePersistenceException In case the underlying cache driver has errors during persistence
*/
public function delete($key);
public function delete(string $key): bool;
/**
* Remove outdated data from the cache
* @param boolean $outdated just remove outdated values
*
* @param boolean $outdated just remove outdated values
*
* @return bool
*
* @throws CachePersistenceException In case the underlying cache driver has errors during persistence
*/
public function clear($outdated = true);
public function clear(bool $outdated = true): bool;
/**
* Returns the name of the current cache
*
* @return string
*/
public function getName();
public function getName(): string;
}

39
src/Core/Cache/IMemoryCache.php → src/Core/Cache/Capability/ICanCacheInMemory.php

@ -19,41 +19,52 @@
*
*/
namespace Friendica\Core\Cache;
namespace Friendica\Core\Cache\Capability;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Cache\Exception\CachePersistenceException;
/**
* This interface defines methods for Memory-Caches only
*/
interface IMemoryCache extends ICache
interface ICanCacheInMemory extends ICanCache
{
/**
* Sets a value if it's not already stored
*
* @param string $key The cache key
* @param mixed $value The old value we know from the cache
* @param int $ttl The cache lifespan, must be one of the Cache constants
* @param string $key The cache key
* @param mixed $value The old value we know from the cache
* @param int $ttl The cache lifespan, must be one of the Cache constants
*
* @return bool
*
* @throws CachePersistenceException In case the underlying cache driver has errors during persistence
*/
public function add($key, $value, $ttl = Duration::FIVE_MINUTES);
public function add(string $key, $value, int $ttl = Duration::FIVE_MINUTES): bool;
/**
* Compares if the old value is set and sets the new value
*
* @param string $key The cache key
* @param mixed $oldValue The old value we know from the cache
* @param mixed $newValue The new value we want to set
* @param int $ttl The cache lifespan, must be one of the Cache constants
* @param string $key The cache key
* @param mixed $oldValue The old value we know from the cache
* @param mixed $newValue The new value we want to set
* @param int $ttl The cache lifespan, must be one of the Cache constants
*
* @return bool
*
* @throws CachePersistenceException In case the underlying cache driver has errors during persistence
*/
public function compareSet($key, $oldValue, $newValue, $ttl = Duration::FIVE_MINUTES);
public function compareSet(string $key, $oldValue, $newValue, int $ttl = Duration::FIVE_MINUTES): bool;
/**
* Compares if the old value is set and removes it
*
* @param string $key The cache key
* @param mixed $value The old value we know and want to delete
* @param string $key The cache key
* @param mixed $value The old value we know and want to delete
*
* @return bool
*
* @throws CachePersistenceException In case the underlying cache driver has errors during persistence
*/
public function compareDelete($key, $value);
public function compareDelete(string $key, $value): bool;
}

138
src/Core/Cache/DatabaseCache.php

@ -1,138 +0,0 @@
<?php
/**
* @copyright Copyright (C) 2010-2021, 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;
use Friendica\Database\Database;
use Friendica\Util\DateTimeFormat;
use Friendica\Core\BaseCache;
/**
* Database Cache
*/
class DatabaseCache extends BaseCache implements ICache
{
/**
* @var Database
*/
private $dba;
public function __construct(string $hostname, Database $dba)
{
parent::__construct($hostname);
$this->dba = $dba;
}
/**
* (@inheritdoc)
*/
public function getAllKeys($prefix = null)
{
if (empty($prefix)) {
$where = ['`expires` >= ?', DateTimeFormat::utcNow()];
} else {
$where = ['`expires` >= ? AND `k` LIKE CONCAT(?, \'%\')', DateTimeFormat::utcNow(), $prefix];
}
$stmt = $this->dba->select('cache', ['k'], $where);
$keys = [];
while ($key = $this->dba->fetch($stmt)) {
array_push($keys, $key['k']);
}
$this->dba->close($stmt);
return $keys;
}
/**
* (@inheritdoc)
*/
public function get($key)
{
$cache = $this->dba->selectFirst('cache', ['v'], ['`k` = ? AND (`expires` >= ? OR `expires` = -1)', $key, DateTimeFormat::utcNow()]);
if ($this->dba->isResult($cache)) {
$cached = $cache['v'];
$value = @unserialize($cached);
// Only return a value if the serialized value is valid.
// We also check if the db entry is a serialized
// boolean 'false' value (which we want to return).
if ($cached === serialize(false) || $value !== false) {
return $value;
}
}
return null;
}
/**
* (@inheritdoc)
*/
public function set($key, $value, $ttl = Duration::FIVE_MINUTES)
{
if ($ttl > 0) {
$fields = [
'v' => serialize($value),
'expires' => DateTimeFormat::utc('now + ' . $ttl . 'seconds'),
'updated' => DateTimeFormat::utcNow()
];
} else {
$fields = [
'v' => serialize($value),
'expires' => -1,
'updated' => DateTimeFormat::utcNow()
];
}
return $this->dba->update('cache', $fields, ['k' => $key], true);
}
/**
* (@inheritdoc)
*/
public function delete($key)
{
return $this->dba->delete('cache', ['k' => $key]);
}
/**
* (@inheritdoc)
*/
public function clear($outdated = true)
{
if ($outdated) {
return $this->dba->delete('cache', ['`expires` < NOW()']);
} else {
return $this->dba->delete('cache', ['`k` IS NOT NULL ']);
}
}
/**
* {@inheritDoc}
*/
public function getName()
{
return Type::DATABASE;
}
}

2
src/Core/Cache/Duration.php → src/Core/Cache/Enum/Duration.php

@ -19,7 +19,7 @@
*
*/
namespace Friendica\Core\Cache;
namespace Friendica\Core\Cache\Enum;
/**
* Enumeration for cache durations

2
src/Core/Cache/Type.php → src/Core/Cache/Enum/Type.php

@ -19,7 +19,7 @@
*
*/
namespace Friendica\Core\Cache;
namespace Friendica\Core\Cache\Enum;
/**
* Enumeration for cache types

13
src/Core/Cache/Exception/CachePersistenceException.php

@ -0,0 +1,13 @@
<?php
namespace Friendica\Core\Cache\Exception;
use Throwable;
class CachePersistenceException extends \RuntimeException
{
public function __construct($message = "", Throwable $previous = null)
{
parent::__construct($message, 500, $previous);
}
}

13
src/Core/Cache/Exception/InvalidCacheDriverException.php

@ -0,0 +1,13 @@
<?php
namespace Friendica\Core\Cache\Exception;
use Throwable;
class InvalidCacheDriverException extends \RuntimeException
{
public function __construct($message = "", Throwable $previous = null)
{
parent::__construct($message, 500, $previous);
}
}

49
src/Factory/CacheFactory.php → src/Core/Cache/Factory/Cache.php

@ -19,12 +19,15 @@
*
*/
namespace Friendica\Factory;
namespace Friendica\Core\Cache\Factory;
use Friendica\App\BaseURL;
use Friendica\Core\Cache;
use Friendica\Core\Cache\ICache;
use Friendica\Core\Config\IConfig;
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\Util\Profiler;
use Psr\Log\LoggerInterface;
@ -36,15 +39,15 @@ use Psr\Log\LoggerInterface;
*
* A basic class to generate a CacheDriver
*/
class CacheFactory
class Cache
{
/**
* @var string The default cache if nothing set
*/
const DEFAULT_TYPE = Cache\Type::DATABASE;
const DEFAULT_TYPE = Enum\Type::DATABASE;
/**
* @var IConfig The IConfiguration to read parameters out of the config
* @var IManageConfigValues The IConfiguration to read parameters out of the config
*/
private $config;
@ -68,7 +71,7 @@ class CacheFactory
*/
private $logger;
public function __construct(BaseURL $baseURL, IConfig $config, Database $dba, Profiler $profiler, LoggerInterface $logger)
public function __construct(BaseURL $baseURL, IManageConfigValues $config, Database $dba, Profiler $profiler, LoggerInterface $logger)
{
$this->hostname = $baseURL->getHostname();
$this->config = $config;
@ -80,39 +83,41 @@ class CacheFactory
/**
* This method creates a CacheDriver for the given cache driver name
*
* @param string $type The cache type to create (default is per config)
* @param string|null $type The cache type to create (default is per config)
*
* @return ICache The instance of the CacheDriver
* @throws \Exception The exception if something went wrong during the CacheDriver creation
* @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 create(string $type = null)
public function create(string $type = null): ICanCache
{
if (empty($type)) {
$type = $this->config->get('system', 'cache_driver', self::DEFAULT_TYPE);
}
switch ($type) {
case Cache\Type::MEMCACHE:
$cache = new Cache\MemcacheCache($this->hostname, $this->config);
case Enum\Type::MEMCACHE:
$cache = new Type\MemcacheCache($this->hostname, $this->config);
break;
case Cache\Type::MEMCACHED:
$cache = new Cache\MemcachedCache($this->hostname, $this->config, $this->logger);
case Enum\Type::MEMCACHED:
$cache = new Type\MemcachedCache($this->hostname, $this->config, $this->logger);
break;
case Cache\Type::REDIS:
$cache = new Cache\RedisCache($this->hostname, $this->config);
case Enum\Type::REDIS:
$cache = new Type\RedisCache($this->hostname, $this->config);
break;
case Cache\Type::APCU:
$cache = new Cache\APCuCache($this->hostname);
case Enum\Type::APCU:
$cache = new Type\APCuCache($this->hostname);
break;
default:
$cache = new Cache\DatabaseCache($this->hostname, $this->dba);
$cache = new Type\DatabaseCache($this->hostname, $this->dba);
}
$profiling = $this->config->get('system', 'profiling', false);
// In case profiling is enabled, wrap the ProfilerCache around the current cache
if (isset($profiling) && $profiling !== false) {
return new Cache\ProfilerCache($cache, $this->profiler);
return new Type\ProfilerCacheDecorator($cache, $this->profiler);
} else {
return $cache;
}

63
src/Core/Cache/APCuCache.php → src/Core/Cache/Type/APCuCache.php

@ -19,26 +19,30 @@
*
*/
namespace Friendica\Core\Cache;
namespace Friendica\Core\Cache\Type;
use Exception;
use Friendica\Core\BaseCache;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Cache\Capability\ICanCacheInMemory;
use Friendica\Core\Cache\Enum\Type;
use Friendica\Core\Cache\Exception\InvalidCacheDriverException;
/**
* APCu Cache.
*/
class APCuCache extends BaseCache implements IMemoryCache
class APCuCache extends AbstractCache implements ICanCacheInMemory
{
use TraitCompareSet;
use TraitCompareDelete;
use CompareSetTrait;
use CompareDeleteTrait;
/**
* @throws Exception
* @param string $hostname
*
* @throws InvalidCacheDriverException
*/
public function __construct(string $hostname)
{
if (!self::isAvailable()) {
throw new Exception('APCu is not available.');
throw new InvalidCacheDriverException('APCu is not available.');
}
parent::__construct($hostname);
@ -47,9 +51,9 @@ class APCuCache extends BaseCache implements IMemoryCache
/**
* (@inheritdoc)
*/
public function getAllKeys($prefix = null)
public function getAllKeys(?string $prefix = null): array
{
$ns = $this->getCacheKey($prefix);
$ns = $this->getCacheKey($prefix ?? '');
$ns = preg_quote($ns, '/');
if (class_exists('\APCIterator')) {
@ -69,12 +73,11 @@ class APCuCache extends BaseCache implements IMemoryCache
/**
* (@inheritdoc)
*/
public function get($key)
public function get(string $key)
{
$return = null;
$cachekey = $this->getCacheKey($key);
$cacheKey = $this->getCacheKey($key);
$cached = apcu_fetch($cachekey, $success);
$cached = apcu_fetch($cacheKey, $success);
if (!$success) {
return null;
}
@ -85,30 +88,30 @@ class APCuCache extends BaseCache implements IMemoryCache
// We also check if the db entry is a serialized
// boolean 'false' value (which we want to return).
if ($cached === serialize(false) || $value !== false) {
$return = $value;
return $value;
}
return $return;
return null;
}
/**
* (@inheritdoc)
*/
public function set($key, $value, $ttl = Duration::FIVE_MINUTES)
public function set(string $key, $value, int $ttl = Duration::FIVE_MINUTES): bool
{
$cachekey = $this->getCacheKey($key);
$cacheKey = $this->getCacheKey($key);
$cached = serialize($value);
if ($ttl > 0) {
return apcu_store(
$cachekey,
$cacheKey,
$cached,
$ttl
);
} else {
return apcu_store(
$cachekey,
$cacheKey,
$cached
);
}
@ -117,16 +120,16 @@ class APCuCache extends BaseCache implements IMemoryCache
/**
* (@inheritdoc)