$this->userAgent]; $content = ''; try { $result = Requests::get($uri, [], $opt); } catch (Requests_Exception $e) { Log::error($e); return ''; } Log::debug(sprintf('Status code is %d', $result->status_code)); if ($result->status_code === 200) { $content = trim($result->body); } if (strlen($content) > 0) { Log::debug('Content is longer than zero. Expect something.'); $converter = new CommonMarkConverter(); $content = $converter->convertToHtml($content); } if (strlen($content) === 0) { Log::warning('Raw content length is zero.'); } return $content; } /** * * @param string $route * * @return bool */ public function hasRoute(string $route):bool { return Route::has($route); } /** * @param string $route * @param string $language * * @return bool */ public function inCache(string $route, string $language):bool { $line = sprintf('help.%s.%s', $route, $language); $result = Cache::has($line); if ($result) { Log::debug(sprintf('Cache has this entry: %s', 'help.' . $route . '.' . $language)); } if (!$result) { Log::debug(sprintf('Cache does not have this entry: %s', 'help.' . $route . '.' . $language)); } return $result; } /** * * @param string $route * @param string $language * @param string $content * */ public function putInCache(string $route, string $language, string $content) { $key = sprintf('help.%s.%s', $route, $language); if (strlen($content) > 0) { Log::debug(sprintf('Will store entry in cache: %s', $key)); Cache::put($key, $content, 10080); // a week. return; } Log::info(sprintf('Will not cache %s because content is empty.', $key)); } }