mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-06-22 19:04:23 +02:00
refactor: use static values for cache scope
This fixes a future problem when code is placed under a namespace because `get_class($bridge)` will then return e.g. `RssBridge\Bridge\TwitterBridge` instead of the the current value `TwitterBridge`. Also a bit refactoring of `Configuration.php`.
This commit is contained in:
@ -280,7 +280,8 @@ abstract class BridgeAbstract implements BridgeInterface
|
||||
public function loadConfiguration()
|
||||
{
|
||||
foreach (static::CONFIGURATION as $optionName => $optionValue) {
|
||||
$configurationOption = Configuration::getConfig(get_class($this), $optionName);
|
||||
$section = (new ReflectionClass($this))->getShortName();
|
||||
$configurationOption = Configuration::getConfig($section, $optionName);
|
||||
|
||||
if ($configurationOption !== null) {
|
||||
$this->configuration[$optionName] = $configurationOption;
|
||||
@ -408,7 +409,9 @@ abstract class BridgeAbstract implements BridgeInterface
|
||||
$cacheFactory = new CacheFactory();
|
||||
|
||||
$cache = $cacheFactory->create();
|
||||
$cache->setScope(get_called_class());
|
||||
// Create class name without the namespace part
|
||||
$scope = (new ReflectionClass($this))->getShortName();
|
||||
$cache->setScope($scope);
|
||||
$cache->setKey($key);
|
||||
if ($cache->getTime() < time() - $duration) {
|
||||
return null;
|
||||
@ -427,7 +430,8 @@ abstract class BridgeAbstract implements BridgeInterface
|
||||
$cacheFactory = new CacheFactory();
|
||||
|
||||
$cache = $cacheFactory->create();
|
||||
$cache->setScope(get_called_class());
|
||||
$scope = (new ReflectionClass($this))->getShortName();
|
||||
$cache->setScope($scope);
|
||||
$cache->setKey($key);
|
||||
$cache->saveData($value);
|
||||
}
|
||||
|
Reference in New Issue
Block a user