當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Host::loadFromJson方法代碼示例

本文整理匯總了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);
 }
開發者ID:gpenverne,項目名稱:dropbox-sdk-php,代碼行數:31,代碼來源:AuthInfo.php

示例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);
 }
開發者ID:Radiergummi,項目名稱:anacronism,代碼行數:42,代碼來源:AppInfo.php


注:本文中的Host::loadFromJson方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。