/** * 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 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); $cacheId = $this->cache->generateCacheIdUsingContext(get_class($this) . serialize($requestedServices)); $cachedSchemaContent = $this->cache->load($cacheId); if ($cachedSchemaContent !== false) { return $cachedSchemaContent; } $allowedServicesMetadata = $this->getAllowedServicesMetadata($requestedServices); $this->collectCallInfo($allowedServicesMetadata); $schemaContent = $this->generateSchema($allowedServicesMetadata, $requestScheme, $requestHost, $endPointUrl); $this->cache->save($schemaContent, $cacheId, [Webapi::CACHE_TAG]); return $schemaContent; }
/** * 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; }