本文整理汇总了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);
}
示例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;
}
}
示例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);
}
示例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);
}
示例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);
}
}
示例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;
}
示例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');
}
}
示例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);
}
示例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');
}
示例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);
}
}
示例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;
}
示例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.');
}
}
示例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);
}
示例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');
}
示例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([]);
}
}