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


PHP SerializerInterface::deserialize方法代碼示例

本文整理匯總了PHP中JMS\Serializer\SerializerInterface::deserialize方法的典型用法代碼示例。如果您正苦於以下問題:PHP SerializerInterface::deserialize方法的具體用法?PHP SerializerInterface::deserialize怎麽用?PHP SerializerInterface::deserialize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在JMS\Serializer\SerializerInterface的用法示例。


在下文中一共展示了SerializerInterface::deserialize方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: deserialize

 /**
  * @param string|array $serialized
  * @param int          $format
  *
  * @return GameInterface
  */
 public function deserialize($serialized, $format)
 {
     if ($format === self::FORMAT_ARRAY) {
         $serialized = json_encode($serialized, true);
     }
     return $this->serializer->deserialize($serialized, Game::class, self::FORMAT_JSON, $this->deserializationContext);
 }
開發者ID:cleentfaar,項目名稱:windmill,代碼行數:13,代碼來源:GameSerializer.php

示例2: call

 /**
  * @param $id
  * @return Result
  */
 protected function call($method, $resource, $body = null, $acceptedCodes = array(200))
 {
     try {
         $response = $this->client->request($method, $resource, array('body' => $body));
         $responseBody = (string) $response->getBody();
         if ($responseBody) {
             /** @var Result $result */
             $result = $this->serializer->deserialize($responseBody, $this->getResultClass(), 'json');
             $result->deserializeData($this->serializer, $this->getModel());
         } else {
             $result = new Result();
         }
         $result->setSuccess(in_array($response->getStatusCode(), $acceptedCodes))->setMessage($response->getReasonPhrase());
         return $result;
     } catch (GuzzleException $ge) {
         if ($ge->getCode() == \Symfony\Component\HttpFoundation\Response::HTTP_TOO_MANY_REQUESTS && php_sapi_name() == "cli") {
             sleep(5);
             return $this->call($method, $resource, $body, $acceptedCodes);
         } else {
             $result = new Result();
             $result->setSuccess(false)->setMessage(sprintf("Client error: %s", $ge->getMessage()));
             return $result;
         }
     } catch (\Exception $e) {
         $result = new Result();
         $result->setSuccess(false)->setMessage(sprintf("General error: %s", $e->getMessage()));
         return $result;
     }
 }
開發者ID:progrupa,項目名稱:MailjetBundle,代碼行數:33,代碼來源:AbstractApi.php

示例3: testSerializationToJson

 public function testSerializationToJson()
 {
     $subject = new Message('to', 'from', 'subject', 'message');
     $data = $this->serializer->serialize($subject, 'json');
     $object = $this->serializer->deserialize($data, get_class($subject), 'json');
     $this->assertEquals($subject, $object);
 }
開發者ID:aboutcoders,項目名稱:job-bundle,代碼行數:7,代碼來源:MessageTest.php

示例4: deserialize

 /**
  * @inheritdoc
  */
 public function deserialize($data, $type, $format, $groups = null)
 {
     $context = null;
     if ($groups) {
         $context = DeserializationContext::create()->setGroups($groups);
     }
     return $this->serializer->deserialize($data, $type, $format, $context);
 }
開發者ID:hellofresh,項目名稱:engine,代碼行數:11,代碼來源:JmsSerializerAdapter.php

示例5: deserialize

 public function deserialize(SerializedObjectInterface $data)
 {
     try {
         return $this->serializer->deserialize($data->getData(), $data->getContentType(), 'json');
     } catch (\Exception $ex) {
         throw new UnknownSerializedTypeException($data->getType(), $ex);
     }
 }
開發者ID:fcm,項目名稱:GovernorFramework,代碼行數:8,代碼來源:JMSSerializer.php

示例6: deserialize

 /**
  * @param string                 $json
  * @param string                 $type
  * @param DeserializationContext $context
  *
  * @return object|null
  */
 protected function deserialize($json, $type, DeserializationContext $context = null)
 {
     $object = $this->serializer->deserialize($json, $type, 'json', $context);
     if (!$object instanceof $type) {
         return null;
     }
     return $object;
 }
開發者ID:adlogix,項目名稱:confluence-rest-php-client,代碼行數:15,代碼來源:AbstractService.php

示例7: createCampaignSuppressionImport

 /**
  * {@inheritdoc}
  */
 public function createCampaignSuppressionImport($campaignId, $source, $location, $data)
 {
     try {
         return $this->client->getCommand('createCampaignSuppressionImport', array('campaignId' => $campaignId, 'suppression_import' => array('source' => $source, 'location' => $location, 'data' => $data)))->execute();
     } catch (ClientErrorResponseException $e) {
         return $this->serializer->deserialize($e->getResponse()->getBody(), 'EBC\\AdvertiserClient\\Campaign\\InvalidImportResponse', 'json');
     }
 }
開發者ID:emailbidding,項目名稱:advertiser-client-php,代碼行數:11,代碼來源:AdvertiserClient.php

示例8: testSerializationToJson

 public function testSerializationToJson()
 {
     $exception = new \Exception('foobar', 100);
     $subject = new ExceptionResponse($exception);
     $data = $this->serializer->serialize($subject, 'json');
     $object = $this->serializer->deserialize($data, ExceptionResponse::class, 'json');
     $this->assertEquals($subject, $object);
 }
開發者ID:aboutcoders,項目名稱:job-bundle,代碼行數:8,代碼來源:ExceptionResponseTest.php

示例9: load

 /**
  * Load the Satis JSON.
  *
  * @return \KevinDierkx\Muse\Repositories\Satis\SatisInterface
  */
 public function load()
 {
     if (!Storage::has('satis.json')) {
         throw new \RuntimeException("The 'satis.json' does not exist.");
     }
     $data = Storage::get('satis.json');
     return $this->serializer->deserialize($data, $this->getModel(), 'json');
 }
開發者ID:kevindierkx,項目名稱:muse,代碼行數:13,代碼來源:Persister.php

示例10: deserialize

 /**
  * Deserialize XML into a BaseResponse
  *
  * @param $xml
  * @return BaseResponse
  * @throws SerializationException
  */
 public function deserialize($xml)
 {
     try {
         return $this->serializer->deserialize($xml, 'SMH\\Enom\\Response\\BaseResponse', 'xml');
     } catch (\RuntimeException $ex) {
         throw new SerializationException($ex->getMessage(), null, $ex);
     }
 }
開發者ID:shaunhardy,項目名稱:enom,代碼行數:15,代碼來源:JMSSerializer.php

示例11: apply

 /**
  * {@inheritdoc}
  */
 public function apply(Request $request, ParamConverter $configuration)
 {
     $json = $request->getContent();
     /** @var Event $event */
     $event = $this->serializer->deserialize($json, 'Ndewez\\EventsBundle\\Model\\Event', 'json');
     $request->attributes->set('event', $event);
     return true;
 }
開發者ID:nicolasdewez,項目名稱:events-bundle,代碼行數:11,代碼來源:EventConverter.php

示例12: deserializeRequest

 /**
  * @param Request $request
  *
  * @return array
  */
 public function deserializeRequest(Request $request)
 {
     $format = $this->checkAcceptHeader($request);
     try {
         return $this->serializer->deserialize($request->getContent(), 'array', $format);
     } catch (\Exception $e) {
         throw new \RuntimeException('Could not deserialize content from the request.');
     }
 }
開發者ID:saimaz,項目名稱:ApiBundle,代碼行數:14,代碼來源:RequestSerializer.php

示例13: listen

 /**
  * @param Event $event
  */
 public function listen(Event $event)
 {
     if (!in_array($event->getTitle(), $this->events, true)) {
         return;
     }
     $payload = $this->serializer->deserialize($event->getPayload(), $event->getNamespace(), 'json');
     $ndewezEvent = new NdewezEvent($payload);
     $this->dispatcher->dispatch(sprintf('ndewez_events.%s', $event->getTitle()), $ndewezEvent);
 }
開發者ID:nicolasdewez,項目名稱:events-bundle,代碼行數:12,代碼來源:Listener.php

示例14: sendRequest

 /**
  * Send a request to fastbill.
  *
  * @param mixed $request The request to send.
  * @param string $responseClass The class that should be used to unserialize the response.
  * @return ApiResponseInterface
  */
 protected function sendRequest(RequestInterface $request, $responseClass)
 {
     if (!in_array(ApiResponseInterface::class, class_implements($responseClass))) {
         throw new \InvalidArgumentException('The response class must implement "' . ApiResponseInterface::class . '".');
     }
     $body = $this->serializer->serialize($request, 'json');
     $response = $this->transport->sendRequest($body);
     return $this->serializer->deserialize($response, $responseClass, 'json');
 }
開發者ID:cezarystepkowski,項目名稱:fastbill-api,代碼行數:16,代碼來源:AbstractService.php

示例15: enrichRequestWithParsedBody

 public function enrichRequestWithParsedBody(ServerRequestInterface $request)
 {
     if ($request->hasHeader(HeaderName::CONTENT_TYPE) && $request->getHeaderLine(HeaderName::CONTENT_TYPE) === 'application/json') {
         $parsedBody = $this->serializer->deserialize($request->getBody()->__toString(), 'array', 'json');
         return $request->withParsedBody($parsedBody);
     } else {
         return $request->withParsedBody([]);
     }
 }
開發者ID:jonasrudolph,項目名稱:php-component-web-project,代碼行數:9,代碼來源:RequestBodyParser.php


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