/** * Based on the given ParsedApi instance, the method will create several cache file and update the * cache index. * * @param ParsedApi $parsedApi */ public function writeCacheFiles(ParsedApi $parsedApi) { $writtenCacheFiles = []; // first delete the cache foreach ($parsedApi->versions as $v => $parsedClass) { $this->cache->deleteCache($this->api, $parsedApi->apiClass); } // then build the cache foreach ($parsedApi->versions as $v => $parsedClass) { $compileArray = $this->compileCacheFile($parsedClass, $v); $this->cache->writeCacheFile($this->api, $parsedApi->apiClass, $v, $compileArray); $writtenCacheFiles[$v] = $compileArray; } // write current and latest versions (just include return a specific version) $this->cache->writeCacheFile($this->api, $parsedApi->apiClass, 'latest', $writtenCacheFiles[$parsedApi->latestVersion]); $this->cache->writeCacheFile($this->api, $parsedApi->apiClass, 'current', $writtenCacheFiles[$parsedApi->currentVersion]); }
/** * Process the api rest request and return the CallbackResult object. * * @return CallbackResult */ public function processRequest() { // get version cache file $version = $this->getVersion(); // get class data from the compiled cache files $classData = $this->compilerCache->getCacheContent($this->api, $this->class, $version); // match request return $this->matchRequest($classData); }
/** * Registers the class and creates a compile cache version of it. * * @throws RestException */ private function registerClass() { try { if (!$this->cacheInstance->isCacheValid($this->api, $this->class) || $this->isDevelopment()) { $this->parseClass(); } } catch (\Exception $e) { $exception = new RestException('Unable to register class "' . $this->class . '". ' . $e->getMessage()); $exception->setRequestedClass($this->class); throw $exception; } }
/** * Registers the class and creates a compile cache version of it. * * @throws RestException */ private function registerClass() { try { if (!$this->cacheInstance->isCacheValid($this->api, $this->class) || $this->isDevelopment()) { try { $this->parseClass(); } catch (\Exception $e) { throw new RestException('Error registering class "' . $this->class . '". ' . $e->getMessage()); } } } catch (\Exception $e) { throw new RestException('Unable to register class "' . $this->class . '". ' . $e->getMessage()); } }