mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 04:03:26 +00:00
Use Requests library to get help from Github.
This commit is contained in:
@@ -3,9 +3,9 @@ declare(strict_types = 1);
|
||||
namespace FireflyIII\Helpers\Help;
|
||||
|
||||
use Cache;
|
||||
use ErrorException;
|
||||
use League\CommonMark\CommonMarkConverter;
|
||||
use Log;
|
||||
use Requests;
|
||||
use Route;
|
||||
|
||||
/**
|
||||
@@ -23,34 +23,42 @@ class Help implements HelpInterface
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFromCache(string $key)
|
||||
public function getFromCache(string $key): string
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param string $language
|
||||
* @param string $route
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFromGithub(string $route)
|
||||
public function getFromGithub(string $language, string $route): array
|
||||
{
|
||||
$uri = 'https://raw.githubusercontent.com/JC5/firefly-iii-help/master/en/' . e($route) . '.md';
|
||||
|
||||
$uri = sprintf('https://raw.githubusercontent.com/JC5/firefly-iii-help/master/%s/%s.md', $language, $route);
|
||||
$routeIndex = str_replace('.', '-', $route);
|
||||
$title = trans('help.' . $routeIndex);
|
||||
$content = [
|
||||
'text' => '<p>There is no help for this route!</p>',
|
||||
'text' => '<p>There is no help for this route, or there is no help available in your language.</p>',
|
||||
'title' => $title,
|
||||
];
|
||||
try {
|
||||
$content['text'] = file_get_contents($uri);
|
||||
} catch (ErrorException $e) {
|
||||
Log::error(trim($e->getMessage()));
|
||||
|
||||
Log::debug('Going to get from Github: ' . $uri);
|
||||
|
||||
$result = Requests::get($uri);
|
||||
|
||||
Log::debug('Status code was ' . $result->status_code . '.');
|
||||
|
||||
if ($result->status_code === 200) {
|
||||
$content['text'] = $result->body;
|
||||
}
|
||||
|
||||
|
||||
if (strlen(trim($content['text'])) == 0) {
|
||||
$content['text'] = '<p>There is no help for this route.</p>';
|
||||
Log::debug('No actual help text for this route (even though a page was found).');
|
||||
$content['text'] = '<p>There is no help for this route, or there is no help available in your language.</p>';
|
||||
}
|
||||
$converter = new CommonMarkConverter();
|
||||
$content['text'] = $converter->convertToHtml($content['text']);
|
||||
@@ -66,7 +74,7 @@ class Help implements HelpInterface
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasRoute(string $route)
|
||||
public function hasRoute(string $route):bool
|
||||
{
|
||||
return Route::has($route);
|
||||
}
|
||||
@@ -78,7 +86,7 @@ class Help implements HelpInterface
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function inCache(string $route)
|
||||
public function inCache(string $route):bool
|
||||
{
|
||||
return Cache::has('help.' . $route . '.title') && Cache::has('help.' . $route . '.text');
|
||||
}
|
||||
|
@@ -15,34 +15,32 @@ interface HelpInterface
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFromCache(string $key);
|
||||
public function getFromCache(string $key): string;
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFromGithub(string $route);
|
||||
public function getFromGithub(string $language, string $route):array;
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasRoute(string $route);
|
||||
public function hasRoute(string $route): bool;
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function inCache(string $route);
|
||||
public function inCache(string $route): bool;
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $content
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function putInCache(string $route, array $content);
|
||||
}
|
||||
|
Reference in New Issue
Block a user