1 | <?php |
||
9 | class Manager |
||
10 | { |
||
11 | |||
12 | protected $config = []; |
||
13 | |||
14 | protected $cache; |
||
15 | protected $localCache; |
||
16 | protected $builder; |
||
17 | protected $configurationLocation; |
||
18 | |||
19 | public function __construct( |
||
29 | |||
30 | public function getBuilder() |
||
34 | |||
35 | /** |
||
36 | * @param string $context The (configurable) context for the needed configuration object |
||
37 | * @return Config |
||
38 | * @throws NoConfigurationException |
||
39 | */ |
||
40 | |||
41 | public function getConfiguration($context = Config::CONTEXT_DEFAULT, $storeScopeLocally = false) |
||
42 | { |
||
43 | $key = 'current_cache_object_' . $context; |
||
44 | if (isset($this->config[$key]) && $this->config[$key] instanceof Config) { |
||
45 | return $this->config[$key]; |
||
46 | } |
||
47 | |||
48 | // By default we will get the config location from the remote server for each request. But we can override that. |
||
49 | if ($this->localCache instanceof StorageInterface && $storeScopeLocally) { |
||
50 | // If a local cache is defined we check there for the current scope key first |
||
51 | $currentConfigItem = $this->localCache->getItem($key); |
||
52 | // if we don't find the scope key we check the global cache |
||
53 | if (!$currentConfigItem) { |
||
54 | $currentConfigItem = $this->cache->getItem($key); |
||
55 | // If the primary cache gives us a value we store it locally |
||
56 | if ($currentConfigItem) { |
||
57 | $this->localCache->setItem($key, $currentConfigItem); |
||
58 | } |
||
59 | } |
||
60 | } else { |
||
61 | // Local cache is not configured, so we get the current config cache key from the global cache. |
||
62 | $currentConfigItem = $this->cache->getItem($key); |
||
63 | } |
||
64 | |||
65 | $config = null; |
||
66 | if ($this->localCache instanceof StorageInterface) { |
||
67 | // First we check the local cache for the configuration object if it exists. |
||
68 | $config = $this->localCache->getItem($currentConfigItem); |
||
69 | } |
||
70 | |||
71 | // Either way, if the config is null we check the global cache |
||
72 | if ($config === null) { |
||
73 | $config = $this->cache->getItem($currentConfigItem); |
||
74 | if ($config !== null) { |
||
75 | if ($this->localCache instanceof StorageInterface) { |
||
76 | $this->localCache->setItem($currentConfigItem, $config); |
||
77 | } |
||
78 | } |
||
79 | } |
||
92 |