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


PHP Serializer\SerializerInterface類代碼示例

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


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

示例1: deserializeData

 public function deserializeData(SerializerInterface $serializer, $getModel)
 {
     foreach ($this->data as $objectArray) {
         $obj = $serializer->deserialize($objectArray, $getModel, 'array');
         $this->objects[] = $obj;
     }
 }
開發者ID:progrupa,項目名稱:MailjetBundle,代碼行數:7,代碼來源:Result.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: createResponse

 /**
  * @param array $data
  * @param string|null|array $serializationLevel
  * @return Response
  */
 public function createResponse(array $data, $serializationLevel = null)
 {
     $responseData = [static::KEY_STATUS => static::STATUS_SUCCESS, static::KEY_DATA => $data];
     $serializedData = $this->serializer->serialize($responseData, self::STANDARD_RESPONSE_FORMAT, $serializationLevel ? SerializationContext::create()->setGroups($serializationLevel) : SerializationContext::create());
     $response = $this->getJsonResponse($serializedData);
     return $response;
 }
開發者ID:keylightberlin,項目名稱:util,代碼行數:12,代碼來源:ApiResponseCreator.php

示例4: notifyCallback

 /**
  * {@inheritdoc}
  */
 public function notifyCallback($callbackUrl, $statusResponse)
 {
     $requestBody = $this->serializer->serialize($statusResponse, 'json');
     $request = new \cURL\Request($callbackUrl);
     $request->getOptions()->set(CURLOPT_FILE, fopen('/dev/null', 'w'))->set(CURLOPT_TIMEOUT, 5)->set(CURLOPT_RETURNTRANSFER, false)->set(CURLOPT_CUSTOMREQUEST, 'POST')->set(CURLOPT_POSTFIELDS, $requestBody)->set(CURLOPT_HTTPHEADER, array('Content-Type: application/json', sprintf('Content-Length: %d', strlen($requestBody))));
     $request->send();
 }
開發者ID:AlexEvesDeveloper,項目名稱:hl-stuff,代碼行數:10,代碼來源:CurlPostCallbackNotifier.php

示例5: success

 /**
  * @param $data
  * @param int $status
  * @param array $headers
  * @return \Symfony\Component\HttpFoundation\Response|static
  */
 protected function success($data, $status = 200, $headers = [])
 {
     $serialized_data = $this->serializer->serialize($data, 'json');
     $response = $this->jsonResponse;
     $response->setContent($serialized_data)->setStatusCode($status)->headers->add($headers);
     return $response;
 }
開發者ID:delirehberi,項目名稱:symfony-api-base,代碼行數:13,代碼來源:BaseController.php

示例6: 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

示例7: 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

示例8: getTrackOperationHistory

 /**
  * @param $track
  * @param $debug
  *
  * @throws RussianPostApiException
  * @throws InvalidTrackException
  *
  * @return OperationHistoryData
  */
 public function getTrackOperationHistory($track, &$debug, $language = "RUS")
 {
     if (!TrackValidator::validateTrack($track)) {
         throw new InvalidTrackException();
     }
     $track = TrackValidator::filterTrack($track);
     $client = $this->initClient();
     $AuthorizationHeader = self::createAuthorizationHeader($this->login, $this->password);
     $historyRequest = self::createOperationHistoryRequest($track, 0, $language);
     $parameters = ["AuthorizationHeader" => $this->serializer->serialize($AuthorizationHeader, 'array'), "historyRequest" => $this->serializer->serialize($historyRequest, 'array')];
     //($operation, $params=array(), $namespace='http://tempuri.org', $soapAction='', $headers=false, $rpcParams=null, $style='rpc', $use='encoded')
     $result = $client->call('GetOperationHistory', $parameters, 'http://russianpost.org/operationhistory');
     $debug = array("Request" => $client->request, "Response" => $client->response, "Debug" => $client->debug_str);
     if ($client->fault) {
         throw new RussianPostApiException(print_r($result, true));
     } else {
         $err = $client->getError();
         if ($err) {
             throw new RussianPostApiException($err);
         } else {
             /** @var OperationHistoryData $object */
             $object = $this->serializer->deserialize($result, 'a3mg\\RussianPostBundle\\Model\\OperationHistoryData', 'array');
             return $object;
         }
     }
 }
開發者ID:3mg,項目名稱:russian-post-bundle,代碼行數:35,代碼來源:RussianPostApi.php

示例9: publish

 /**
  * {@inheritdoc}
  */
 public function publish(Event $event)
 {
     try {
         $this->client->post(self::PUBLISH_URL, ['body' => $this->serializer->serialize($event, 'json')]);
     } catch (BadResponseException $exception) {
         throw new PublishException($exception->getMessage());
     }
 }
開發者ID:nicolasdewez,項目名稱:events-bundle,代碼行數:11,代碼來源:HttpConnector.php

示例10: 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

示例11: 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

示例12: jsonResponse

 protected function jsonResponse($data)
 {
     $context = new SerializationContext();
     $context->setSerializeNull(true);
     $content = $this->serializer->serialize($data, 'json', $context);
     $this->response->setContent($content);
     return $this->response;
 }
開發者ID:rmukras,項目名稱:coffee,代碼行數:8,代碼來源:BaseController.php

示例13: post

 /**
  * {@inheritdoc}
  */
 public function post($uri, $data = null, array $options = array())
 {
     if (is_array($data)) {
         $options = array_merge($data, $options);
         $data = new \StdClass();
     }
     $this->request('post', $uri, array('body' => $this->serializer->serialize($data, 'json', SerializationContext::create()->setAttribute('options', $options))));
 }
開發者ID:5haman,項目名稱:rancher-api,代碼行數:11,代碼來源:Client.php

示例14: 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

示例15: toSymfonyResponse

 /**
  * @param ApiResponse $apiResponse to convert to a Symfony Response.
  * @param Request $request that needs this Response.
  *
  * @return Response
  */
 public function toSymfonyResponse(ApiResponse $apiResponse, Request $request)
 {
     $format = $request->getRequestFormat($this->defaultResponseFormat);
     $serialized = $this->serializer->serialize($apiResponse->getData(), $format);
     $response = new Response($serialized, $apiResponse->getStatusCode(), $apiResponse->getHeaders());
     $response->headers->set('Content-Type', $request->getMimeType($format));
     return $response;
 }
開發者ID:alcalyn,項目名稱:serializable-api-response,代碼行數:14,代碼來源:ApiResponseFilter.php


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