/** * Return services loaded from cache if enabled or from files merged previously * * @return array */ public function getServices() { if (null === $this->services) { $services = $this->cache->load(self::CACHE_ID); if ($services && is_string($services)) { $this->services = unserialize($services); } else { $this->services = $this->configReader->read(); $this->cache->save(serialize($this->services), self::CACHE_ID); } } return $this->services; }
/** * Generate WSDL file based on requested services (uses cache) * * @param array $requestedServices * @param string $endPointUrl * @return string * @throws \Exception */ public function generate($requestedServices, $endPointUrl) { /** Sort requested services by names to prevent caching of the same wsdl file more than once. */ ksort($requestedServices); $currentStore = $this->storeManager->getStore(); $cacheId = self::WSDL_CACHE_ID . hash('md5', serialize($requestedServices) . $currentStore->getCode()); $cachedWsdlContent = $this->_cache->load($cacheId); if ($cachedWsdlContent !== false) { return $cachedWsdlContent; } $services = []; foreach ($requestedServices as $serviceName) { $services[$serviceName] = $this->_apiConfig->getServiceMetadata($serviceName); } $wsdlContent = $this->_generate($services, $endPointUrl); $this->_cache->save($wsdlContent, $cacheId, [\Magento\Framework\App\Cache\Type\Webapi::CACHE_TAG]); return $wsdlContent; }
/** * Generate schema based on requested services (uses cache) * * @param array $requestedServices * @param string $requestScheme * @param string $requestHost * @param string $endPointUrl * @return string */ public function generate($requestedServices, $requestScheme, $requestHost, $endPointUrl) { /** Sort requested services by names to prevent caching of the same schema file more than once. */ ksort($requestedServices); $currentStore = $this->storeManager->getStore(); $cacheId = get_class($this) . hash('md5', serialize($requestedServices) . $currentStore->getCode()); $cachedSchemaContent = $this->cache->load($cacheId); if ($cachedSchemaContent !== false) { return $cachedSchemaContent; } $requestedServiceMetadata = []; foreach ($requestedServices as $serviceName) { $requestedServiceMetadata[$serviceName] = $this->getServiceMetadata($serviceName); } $this->collectCallInfo($requestedServiceMetadata); $schemaContent = $this->generateSchema($requestedServiceMetadata, $requestScheme, $requestHost, $endPointUrl); $this->cache->save($schemaContent, $cacheId, [Webapi::CACHE_TAG]); return $schemaContent; }
/** * Return services loaded from cache if enabled or from files merged previously * * @return array */ protected function getSoapServicesConfig() { if (null === $this->soapServices) { $soapServicesConfig = $this->cache->load(self::CACHE_ID); if ($soapServicesConfig && is_string($soapServicesConfig)) { $this->soapServices = unserialize($soapServicesConfig); } else { $this->soapServices = $this->initServicesMetadata(); $this->cache->save(serialize($this->soapServices), self::CACHE_ID); } } return $this->soapServices; }
/** * Return routes loaded from cache if enabled or from files merged previously * * @return array */ public function getRoutesConfig() { if (null === $this->routes) { $routesConfig = $this->cache->load(self::ROUTES_CONFIG_CACHE_ID); $typesData = $this->cache->load(self::REFLECTED_TYPES_CACHE_ID); if ($routesConfig && is_string($routesConfig) && $typesData && is_string($typesData)) { $this->routes = unserialize($routesConfig); $this->typeProcessor->setTypesData(unserialize($typesData)); } else { $this->routes = $this->initRoutesMetadata(); $this->cache->save(serialize($this->routes), self::ROUTES_CONFIG_CACHE_ID); $this->cache->save(serialize($this->typeProcessor->getTypesData()), self::REFLECTED_TYPES_CACHE_ID); } } return $this->routes; }
/** * Retrieve requested service method params metadata. * * @param string $serviceClassName * @param string $serviceMethodName * @return array */ protected function getMethodParams($serviceClassName, $serviceMethodName) { $cacheId = self::CACHE_ID_PREFIX . hash('md5', $serviceClassName . $serviceMethodName); $params = $this->cache->load($cacheId); if ($params !== false) { return unserialize($params); } $serviceClass = new ClassReflection($serviceClassName); /** @var MethodReflection $serviceMethod */ $serviceMethod = $serviceClass->getMethod($serviceMethodName); $params = []; /** @var ParameterReflection $paramReflection */ foreach ($serviceMethod->getParameters() as $paramReflection) { $isDefaultValueAvailable = $paramReflection->isDefaultValueAvailable(); $params[] = ['name' => $paramReflection->getName(), 'type' => $this->typeProcessor->getParamType($paramReflection), 'isDefaultValueAvailable' => $isDefaultValueAvailable, 'defaultValue' => $isDefaultValueAvailable ? $paramReflection->getDefaultValue() : null]; } $this->cache->save(serialize($params), $cacheId, [WebapiCache::CACHE_TAG]); return $params; }