first commit

This commit is contained in:
2025-08-02 16:30:27 +02:00
commit 23646bfcee
14851 changed files with 1750626 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
namespace KupShop\SynchronizationBundle\Util;
use KupShop\SynchronizationBundle\Exception\SynchronizationConfigException;
class SynchronizationConfiguration
{
private array $configLoader = [];
public function set(string $key, callable $loader, int $ttl = 3600): void
{
$this->configLoader[$key] = [
'loader' => $loader,
'ttl' => $ttl,
];
}
public function has(string $key): bool
{
return isset($this->configLoader[$key]);
}
public function get(string $key)
{
if (!$this->has($key)) {
throw new SynchronizationConfigException(sprintf('Key "%s" does not exists ibn configuration!', $key));
}
if (!($config = getCache($this->getCacheKey($key)))) {
// naloaduju config
$config = $this->configLoader[$key]['loader']();
// zacahuje config
setCache($this->getCacheKey($key), $config, $this->configLoader[$key]['ttl']);
}
return $config;
}
public function clear(string $key): bool
{
if ($this->has($key) || getCache($this->getCacheKey($key))) {
clearCache($this->getCacheKey($key));
return true;
}
return false;
}
private function getCacheKey(string $key): string
{
return 'synchronizationConfig_'.$key;
}
}