当前位置: 首页>>代码示例>>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;未经允许,请勿转载。