Refactoring Core class structures ...

This commit is contained in:
Philipp 2021-10-26 21:44:29 +02:00
parent 57b4c008cb
commit b216317477
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
130 changed files with 1625 additions and 1397 deletions

View file

@ -22,9 +22,12 @@
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\Enum\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\Enum\Type::MEMCACHE:
$cache = new Cache\Type\MemcacheCache($this->hostname, $this->config);
case Enum\Type::MEMCACHE:
$cache = new Type\MemcacheCache($this->hostname, $this->config);
break;
case Cache\Enum\Type::MEMCACHED:
$cache = new Cache\Type\MemcachedCache($this->hostname, $this->config, $this->logger);
case Enum\Type::MEMCACHED:
$cache = new Type\MemcachedCache($this->hostname, $this->config, $this->logger);
break;
case Cache\Enum\Type::REDIS:
$cache = new Cache\Type\RedisCache($this->hostname, $this->config);
case Enum\Type::REDIS:
$cache = new Type\RedisCache($this->hostname, $this->config);
break;
case Cache\Enum\Type::APCU:
$cache = new Cache\Type\APCuCache($this->hostname);
case Enum\Type::APCU:
$cache = new Type\APCuCache($this->hostname);
break;
default:
$cache = new Cache\Type\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\Type\ProfilerCache($cache, $this->profiler);
return new Type\ProfilerCacheDecorator($cache, $this->profiler);
} else {
return $cache;
}