当前位置: 首页>>代码示例>>PHP>>正文


PHP JsonHelper::toJson方法代码示例

本文整理汇总了PHP中JsonHelper::toJson方法的典型用法代码示例。如果您正苦于以下问题:PHP JsonHelper::toJson方法的具体用法?PHP JsonHelper::toJson怎么用?PHP JsonHelper::toJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonHelper的用法示例。


在下文中一共展示了JsonHelper::toJson方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sendMessage

 /**
  * Sends a message.
  * @param mixed $message
  * @return MessageResponse|HttpResponse|null
  * @throws ErrorException
  */
 public function sendMessage($message)
 {
     $resource = "/messages/";
     if (is_null($message)) {
         throw new ErrorException("Parameter 'message' cannot be null");
     } elseif (!$message instanceof Message && !is_array($message)) {
         throw new ErrorException("Parameter 'message' must be an instance of Message or an array");
     }
     try {
         $params = array();
         $params = is_array($message) ? $message : json_decode(JsonHelper::toJson($message), true);
         $params["Direction"] = MessageDirection::OUT;
         $response = $this->httpClient->post($resource, $params);
         if ($response instanceof HttpResponse) {
             if ($response->getStatus() === HttpStatusCode::HTTP_CREATED) {
                 $json = JsonHelper::getJson($response->getBody());
                 if (isset($json)) {
                     return new MessageResponse($json);
                 }
             } else {
                 return $response;
             }
         }
     } catch (Exception $ex) {
         echo $ex->getTraceAsString();
     }
     return null;
 }
开发者ID:fredrickabayie,项目名称:MyBankWeb,代码行数:34,代码来源:MessagingApi.php

示例2: addContactGroup

 /**
  * Creates a new Contact Group
  * @param mixed $group The contact group data. It can be an associative array or an instance of ContactGroup
  * @return HttpResponse|null|ContactGroup
  * @throws ErrorException
  */
 public function addContactGroup($group)
 {
     $resource = "/contacts/groups/";
     if (is_null($group)) {
         throw new ErrorException("Parameter 'group' cannot be null");
     }
     if (!is_string($group) || !$group instanceof ContactGroup || !is_array($group)) {
         throw new ErrorException("Parameter 'group' must be of type ContactGroup or an array or a string");
     }
     try {
         $params = array();
         if (is_string($group)) {
             $params["Name"] = $group;
         } else {
             $params = is_array($group) ? $group : json_decode(JsonHelper::toJson($group), true);
         }
         $response = $this->httpClient->post($resource, $params);
         if ($response instanceof HttpResponse) {
             if ($response->getStatus() === HttpStatusCode::HTTP_CREATED) {
                 $json = JsonHelper::getJson($response->getBody());
                 if (isset($json)) {
                     return new ContactGroup($json);
                 }
             } else {
                 return $response;
             }
         }
     } catch (\Exception $ex) {
         echo $ex->getTraceAsString();
     }
     return null;
 }
开发者ID:natino45,项目名称:smsghapi-php,代码行数:38,代码来源:ContactApi.php

示例3: updateSupportTicket

 /**
  * Replies to a Support Ticket
  * @param integer $ticketId
  * @param mixed $request
  * @return HttpResponse|null|Ticket
  * @throws \ErrorException
  */
 public function updateSupportTicket($ticketId, $request)
 {
     $resource = "/tickets/";
     if (is_null($ticketId)) {
         throw new \ErrorException("Parameter 'ticketId' cannot be null");
     } elseif (!is_int($ticketId)) {
         throw new \ErrorException("Parameter 'ticketId' must be an integer");
     }
     if (is_null($request)) {
         throw new \ErrorException("Parameter 'request' cannot be null");
     } elseif (!$request instanceof TicketResponse || !is_array($request)) {
         throw new \ErrorException("Parameter 'request' must be of type TicketResponse or an array");
     }
     try {
         $params = array();
         $params = is_array($request) ? $request : json_decode(JsonHelper::toJson($request), true);
         $response = $this->httpClient->put($resource, $params);
         if ($response instanceof HttpResponse) {
             if ($response->getStatus() === HttpStatusCode::HTTP_OK) {
                 $json = JsonHelper::getJson($response->getBody());
                 if (isset($json)) {
                     return new Ticket($json);
                 }
             } else {
                 return $response;
             }
         }
     } catch (\Exception $ex) {
         echo $ex->getTraceAsString();
     }
     return null;
 }
开发者ID:natino45,项目名称:smsghapi-php,代码行数:39,代码来源:SupportApi.php

示例4: updateContentMedia

 /**
  * Updates the details of an existing content media.
  * @param UUID $mediaId The content media
  * @param MediaInfo $mediaInfo The content media details
  * @return HttpResponse|ContentMedia|null
  * @throws ErrorException
  */
 public function updateContentMedia($mediaId, $mediaInfo = null)
 {
     $resource = "/media/";
     if (is_null($mediaId)) {
         throw new ErrorException("Parameter 'mediaId' cannot be null");
     } elseif (!CommonUtil::is_uuid($mediaId)) {
         throw new ErrorException("Parameter 'mediaId' must be a valid UUID");
     }
     if (!is_null($mediaInfo) && !$mediaInfo instanceof MediaInfo) {
         throw new ErrorException("Parameter 'mediaInfo' cannot be null and must be an instance of MediaInfo.");
     }
     try {
         $resource .= $mediaId;
         // Set the mediainfo data
         $params["ContentName"] = $mediaInfo->contentName;
         $params["LibraryId"] = $mediaInfo->libraryId;
         $params["DestinationFolder"] = $mediaInfo->destinationFolder;
         $params["Preference"] = $mediaInfo->preference;
         $params["Width"] = $mediaInfo->width;
         $params["Height"] = $mediaInfo->height;
         $params["DrmProtect"] = $mediaInfo->drmProtect;
         $params["Streamable"] = $mediaInfo->streamable;
         $params["DisplayText"] = $mediaInfo->displayText;
         $params["ContentText"] = $mediaInfo->contentText;
         $params["Tags"] = "";
         // set the medainfo tags
         if (!is_null($mediaInfo->tags) && is_array($mediaInfo->tags) && count($mediaInfo->tags) > 0) {
             $params["Tags"] = JsonHelper::toJson($mediaInfo->tags);
         }
         $response = $this->httpClient->put($resource, $params);
         if ($response instanceof HttpResponse) {
             if ($response->getStatus() === HttpStatusCode::HTTP_OK) {
                 $json = JsonHelper::getJson($response->getBody());
                 if (isset($json)) {
                     return new ContentMedia($json);
                 }
             } else {
                 return $response;
             }
         }
     } catch (Exception $ex) {
         $ex->getTraceAsString();
     }
     return null;
 }
开发者ID:fredrickabayie,项目名称:MyBankWeb,代码行数:52,代码来源:ContentApi.php

示例5: updateAccountSettings

 /**
  * Update Account Settings or Preferences and returns the updated preference object.
  * In case of errors an error is triggered
  * @param mixed $request Preference Object to update
  * @return Setting|HttpResponse|null Updated preference
  * @throws ErrorException
  */
 public function updateAccountSettings($request)
 {
     $resource = "/account/settings/";
     if (is_null($request)) {
         throw new ErrorException("Parameter 'preference' cannot be null");
     } elseif (!is_array($request) || !$request instanceof Setting) {
         throw new ErrorException("Parameter 'request' must be an array");
     }
     try {
         $params = array();
         $params = is_array($request) ? $request : json_decode(JsonHelper::toJson($request), true);
         $response = $this->httpClient->post($resource, $params);
         if ($response instanceof HttpResponse) {
             if ($response->getStatus() === HttpStatusCode::HTTP_OK) {
                 $json = JsonHelper::getJson($response->getBody());
                 if (isset($json)) {
                     return new Setting($json);
                 }
             } else {
                 return $response;
             }
         }
     } catch (Exception $ex) {
         echo $ex->getTraceAsString();
     }
     return null;
 }
开发者ID:fredrickabayie,项目名称:MyBankWeb,代码行数:34,代码来源:AccountApi.php


注:本文中的JsonHelper::toJson方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。