本文整理汇总了PHP中Host::loadFromJson方法的典型用法代码示例。如果您正苦于以下问题:PHP Host::loadFromJson方法的具体用法?PHP Host::loadFromJson怎么用?PHP Host::loadFromJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Host
的用法示例。
在下文中一共展示了Host::loadFromJson方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadFromJson
/**
* Parses a JSON object to build an AuthInfo object. If you would like to load this from a file,
* please use the @see loadFromJsonFile method.
*
* @param array $jsonArr
* A parsed JSON object, typcally the result of json_decode(..., true).
* @return array
* A <code>list(string $accessToken, Host $host)</code>.
*
* @throws AuthInfoLoadException
*/
private static function loadFromJson($jsonArr)
{
if (!is_array($jsonArr)) {
throw new AuthInfoLoadException("Expecting JSON object, found something else");
}
// Check access_token
if (!array_key_exists('access_token', $jsonArr)) {
throw new AuthInfoLoadException("Missing field \"access_token\"");
}
$accessToken = $jsonArr['access_token'];
if (!is_string($accessToken)) {
throw new AuthInfoLoadException("Expecting field \"access_token\" to be a string");
}
try {
$host = Host::loadFromJson($jsonArr);
} catch (HostLoadException $ex) {
throw new AuthInfoLoadException($ex->getMessage());
}
return array($accessToken, $host);
}
示例2: loadFromJson
/**
* Parses a JSON object to build an AppInfo object. If you would like to load this from a file,
* use the loadFromJsonFile() method.
*
* @param array $jsonArr Output from json_decode($str, true)
*
* @return AppInfo
*
* @throws AppInfoLoadException
*/
static function loadFromJson($jsonArr)
{
if (!is_array($jsonArr)) {
throw new AppInfoLoadException("Expecting JSON object, got something else");
}
$requiredKeys = array("key", "secret");
foreach ($requiredKeys as $key) {
if (!array_key_exists($key, $jsonArr)) {
throw new AppInfoLoadException("Missing field \"{$key}\"");
}
if (!is_string($jsonArr[$key])) {
throw new AppInfoLoadException("Expecting field \"{$key}\" to be a string");
}
}
// Check app_key and app_secret
$appKey = $jsonArr["key"];
$appSecret = $jsonArr["secret"];
$tokenErr = self::getTokenPartError($appKey);
if (!is_null($tokenErr)) {
throw new AppInfoLoadException("Field \"key\" doesn't look like a valid app key: {$tokenErr}");
}
$tokenErr = self::getTokenPartError($appSecret);
if (!is_null($tokenErr)) {
throw new AppInfoLoadException("Field \"secret\" doesn't look like a valid app secret: {$tokenErr}");
}
try {
$host = Host::loadFromJson($jsonArr);
} catch (HostLoadException $ex) {
throw new AppInfoLoadException($ex->getMessage());
}
return new AppInfo($appKey, $appSecret, $host);
}