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


PHP SerializerBuilder::deserialize方法代码示例

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


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

示例1: json

 /**
  * Get API response.
  * 
  * @param string $call
  * @param string $type
  * @param array  $parameters
  */
 public function json($call, $type, $parameters = [])
 {
     try {
         $content = $this->plain($call, $parameters);
         return $this->serializer->deserialize($content, $type, 'json');
     } catch (\Exception $e) {
         throw new Exception\ApiException($e->getMessage(), $call);
     }
 }
开发者ID:andyftw,项目名称:ssllabs-php,代码行数:16,代码来源:Request.php

示例2: syncDatabase

 /**
  * Iterates all configured api requests, fetches the result and tries to
  * deserialize the response to the mapped entities chosen for the
  * corresponding api request.
  *
  * Notes on your entities:
  * * your entities must implement VirtualIdentity\TwitterBundle\Interfaces\TwitterEntity
  * * the attributes must define the JMS\Serializer\Annotation\Type annotation
  * * the result from twitter is flattened before its deserialized
  *
  * What does the last point mean? This means that if your response has a key
  * $entry['id_str'] the property "idStr" is populated. If the response has a
  * key $entry['user']['screen_name'] the property "userScreenName" is
  * populated. Therefore you can persist whatever information you want to
  * persist from the direct response by using the correct name for the
  * entity-field.
  *
  * Hint (1):
  * If your fields don't get deserialized correctly, make use of the
  * JMS\Serializer\Annotation\SerializedName annotation.
  *
  * Hint (2):
  * If you have special code executed in your setters, you must use the
  * JMS\Serializer\Annotation\AccessType annotation! Per default reflection
  * is used and the properties are set directly!
  *
  * Warning:
  * You may not want that the id is populated by deserializing because you
  * want it to be an incremental value. In this case use a combination of
  * JMS\Serializer\Annotation\ExclusionPolicy and
  * JMS\Serializer\Annotation\Exclude or JMS\Serializer\Annotation\Expose
  * annotations.
  *
  * @param array requestIds which requestIds should be executed
  * @return void
  */
 public function syncDatabase(array $requestIds = array())
 {
     if (!$this->api) {
         throw new ApiException('Api not initialized! Use setAuthentication to implicitly initialize the api.');
     }
     foreach ($this->apiRequests as $twitterRequestEntity) {
         if (count($requestIds) && !in_array($twitterRequestEntity->getId(), $requestIds)) {
             continue;
         }
         if (count($requestIds) == 0 && $twitterRequestEntity->getLastExecutionTime() + $twitterRequestEntity->getRefreshLifeTime() > time()) {
             // we only execute requests if their lifetime is over
             continue;
         }
         $socialEntityClass = $twitterRequestEntity->getMappedEntity();
         if (!class_exists($socialEntityClass) && !in_array('VirtualIdentity\\TwitterBundle\\Interfaces\\TwitterEntityInterface', class_implements($socialEntityClass))) {
             continue;
         }
         $start = microtime(true);
         $url = $twitterRequestEntity->getUrl();
         $params = array();
         $query = parse_url($url, PHP_URL_QUERY);
         parse_str($query, $params);
         $lastMaxId = $twitterRequestEntity->getLastMaxId();
         if ($twitterRequestEntity->getUseSinceId() && is_numeric($lastMaxId)) {
             $params['since_id'] = $lastMaxId;
         }
         // twitter limits the maximum amount of tweets that can be fetched
         // per api request to 200, so making this configurable for the user
         // seems to make no sense
         $params['count'] = 200;
         $status = $this->api->request('GET', $this->api->url($url), $params);
         if ($status == 200) {
             $response = json_decode($this->api->response['response'], true);
             if (isset($response['statuses'])) {
                 $response = $response['statuses'];
             }
             $repository = $this->em->getRepository($socialEntityClass);
             foreach ($response as $rawTweet) {
                 if (!isset($rawTweet['id_str'])) {
                     throw new ApiException('Tweet could not be recognized! There was no id_str in the entity: ' . print_r($rawTweet, 1));
                 }
                 if (!count($repository->findOneByIdStr($rawTweet['id_str']))) {
                     $flattened = self::flatten($rawTweet);
                     $rawData = json_encode($flattened);
                     $twitterEntity = $this->serializer->deserialize($rawData, $socialEntityClass, 'json');
                     $twitterEntity->setRequestId($twitterRequestEntity->getId());
                     $twitterEntity->setRaw(json_encode($rawTweet));
                     $twitterEntity->setApproved($this->autoApprove);
                     $this->em->persist($twitterEntity);
                     if ($rawTweet['id_str'] > $lastMaxId) {
                         $lastMaxId = $rawTweet['id_str'];
                     }
                 } else {
                     continue;
                 }
             }
             $this->em->flush();
         } else {
             $twitterRequestEntity->setLastExecutionDuration(-1);
             $twitterRequestEntity->setLastMaxId($lastMaxId);
             $this->em->persist($twitterRequestEntity);
             $this->em->flush();
             throw new ApiException('Request was unsuccessful! Status code: ' . $status . '. Response was: ' . $this->api->response['response']);
         }
//.........这里部分代码省略.........
开发者ID:beecms,项目名称:virtual-identity,代码行数:101,代码来源:TwitterService.php

示例3: deserialize

 /**
  * @param string $jsonString
  *
  * @return RedashApiClient\Response
  */
 private function deserialize($jsonString)
 {
     return $this->serializer->deserialize($jsonString, Response::class, 'json');
 }
开发者ID:ariarijp,项目名称:redash-api-client,代码行数:9,代码来源:Client.php


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