Don't use file_get_contents for HTTP requests.

This commit is contained in:
flash 2023-11-06 16:51:52 +00:00
parent e8edf8b5f3
commit 91dd716b3c
2 changed files with 7 additions and 5 deletions

View file

@ -2,6 +2,7 @@
namespace Satori\Dictionary;
use Syokuhou\IConfig;
use Satori\SHttp;
class DictionaryContext {
private IConfig $config;
@ -15,13 +16,13 @@ class DictionaryContext {
}
public function defineWord(string $word): array {
$data = json_decode(file_get_contents(sprintf(
$data = SHttp::getJson(sprintf(
'https://api.wordnik.com/v4/word.json/%s/definitions?limit=5&includeRelated=false&sourceDictionaries=ahd-5%%2Cwordnet&useCanonical=true&includeTags=false&api_key=%s',
rawurlencode($word),
$this->config->getString('token')
)), true);
));
if(empty($data))
if(empty($data) || !empty($data['statusCode']))
return [];
$results = [];

View file

@ -3,6 +3,7 @@ namespace Satori\ExRate;
use Index\Data\IDbConnection;
use Syokuhou\IConfig;
use Satori\SHttp;
class ExRateContext {
private const BASE_CURRENCY = 'EUR';
@ -41,11 +42,11 @@ class ExRateContext {
public function refreshRates(): void {
// HTTPS is a paid feature?????????
$data = json_decode(file_get_contents(sprintf(
$data = SHttp::getJsonCached(sprintf(
'http://api.exchangerate.host/live?source=%s&access_key=%s',
self::BASE_CURRENCY,
$this->config->getString('token')
)), true);
));
if(empty($data) || !$data['success'])
return;