/** * 2015-11-27 * @return array(string => mixed) * @throws \Exception */ private function responseA() { if (!isset($this->{__METHOD__})) { /** @var bool $debug */ $debug = true; /** @var array(string => mixed) $result */ $result = df_json_decode($debug || !S::s()->serverApiKey() ? df_http_get('https://mage2.pro/google-fonts.json') : df_http_get('https://www.googleapis.com/webfonts/v1/webfonts', ['key' => S::s()->serverApiKey(), 'sort' => 'alpha'])); /** * 2015-11-17 * В документации об этом ни слова не сказано, * однако в случае сбоя Google API возвращает JSON следующией структуры: { error: { errors: [ { domain: "usageLimits", reason: "accessNotConfigured", message: "Access Not Configured. The API (Google Fonts Developer API) is not enabled for your project. Please use the Google Developers Console to update your configuration.", extendedHelp: "https://console.developers.google.com" } ], code: 403, message: "Access Not Configured. The API (Google Fonts Developer API) is not enabled for your project. Please use the Google Developers Console to update your configuration." } } * https://developers.google.com/fonts/docs/developer_api */ /** @var array(string => mixed)|null $result */ $error = dfa($result, 'error'); if ($error) { throw (new Exception($error))->standard(); } /** * 2015-11-27 * https://developers.google.com/fonts/docs/developer_api#Example */ $result = dfa($result, 'items'); df_result_array($result); $this->{__METHOD__} = $result; } return $this->{__METHOD__}; }
/** * 2016-04-13 * @param string $urlBase * @param array(string => string) $params [optional] * @param int|null $timeout [optional] * @return array(string => mixed) */ function df_http_json($urlBase, array $params = [], $timeout = null) { /** @var array|mixed $result */ $result = []; /** @var string|bool $json */ $json = df_http_get($urlBase, $params, $timeout); if (false !== $json) { /** @var bool|array|null $decoded */ $decoded = df_json_decode($json); if (is_array($decoded)) { $result = $decoded; } } return $result; }