From 2f7f13d9fe95da680900d8cdc597e01b7fbbb2f9 Mon Sep 17 00:00:00 2001 From: Eugene Molotov Date: Sun, 20 Nov 2022 16:41:38 +0500 Subject: [PATCH] [core] Implement SetBridgeCacheAction to store bridge's cache remotely (#3156) --- actions/SetBridgeCacheAction.php | 55 ++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 actions/SetBridgeCacheAction.php diff --git a/actions/SetBridgeCacheAction.php b/actions/SetBridgeCacheAction.php new file mode 100644 index 00000000..8bd4b545 --- /dev/null +++ b/actions/SetBridgeCacheAction.php @@ -0,0 +1,55 @@ +sanitizeBridgeName($request['bridge']); + } + + if ($bridgeClassName === null) { + throw new \InvalidArgumentException('Bridge name invalid!'); + } + + // whitelist control + if (!$bridgeFactory->isWhitelisted($bridgeClassName)) { + throw new \Exception('This bridge is not whitelisted', 401); + die; + } + + $bridge = $bridgeFactory->create($bridgeClassName); + $bridge->loadConfiguration(); + $value = $request['value']; + + $cacheFactory = new CacheFactory(); + + $cache = $cacheFactory->create(); + $cache->setScope(get_class($bridge)); + $cache->setKey($key); + $cache->saveData($value); + + header('Content-Type: text/plain'); + echo 'done'; + } +}