Don't use file_get_contents for HTTP requests.
This commit is contained in:
parent
e8edf8b5f3
commit
91dd716b3c
2 changed files with 7 additions and 5 deletions
|
@ -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 = [];
|
||||
|
|
|
@ -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;
|
||||
|
|
Reference in a new issue