7 declare(strict_types=1);
28 private $webApiConfig;
38 private $asyncServices;
53 $this->webApiConfig = $webApiConfig;
62 if (
null === $this->asyncServices) {
63 $services = $this->cache->load(self::CACHE_ID);
65 $this->asyncServices = $this->serializer->unserialize(
$services);
67 $this->asyncServices = $this->generateTopicsDataFromWebapiConfig();
68 $this->cache->save($this->serializer->serialize($this->asyncServices),
self::CACHE_ID);
72 return $this->asyncServices;
81 $topicName = $this->generateTopicNameByRouteData(
86 if (array_key_exists($topicName,
$services) ===
false) {
88 __(
'WebapiAsync config for "%topicName" does not exist.', [
'topicName' => $topicName])
92 return $services[$topicName][self::SERVICE_PARAM_KEY_TOPIC];
98 private function generateTopicsDataFromWebapiConfig()
100 $webApiConfig = $this->webApiConfig->getServices();
103 foreach ($routeData as $httpMethod => $httpMethodData) {
104 if ($httpMethod !== \
Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET) {
108 $topicName = $this->generateTopicNameByRouteData(
113 self::SERVICE_PARAM_KEY_INTERFACE => $serviceInterface,
114 self::SERVICE_PARAM_KEY_METHOD => $serviceMethod,
115 self::SERVICE_PARAM_KEY_TOPIC => $topicName,
134 private function generateTopicNameByRouteData($routeUrl, $httpMethod)
136 return self::TOPIC_PREFIX . $this->generateTopicName($routeUrl, $httpMethod,
'/',
false);
146 private function generateTopicName($typeName, $methodName, $delimiter =
'\\', $lcfirst =
true)
148 $parts = explode($delimiter, ltrim($typeName, $delimiter));
149 foreach ($parts as &$part) {
150 $part = ltrim($part,
':');
151 if ($lcfirst ===
true) {
152 $part = lcfirst($part);
156 return implode(
'.', $parts) .
'.' . $methodName;
__construct(WebapiCache $cache, WebapiConfig $webApiConfig, SerializerInterface $serializer=null)
getTopicName($routeUrl, $httpMethod)