本文整理汇总了PHP中JMS\Serializer\SerializerInterface类的典型用法代码示例。如果您正苦于以下问题:PHP SerializerInterface类的具体用法?PHP SerializerInterface怎么用?PHP SerializerInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SerializerInterface类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: it_can_serialize_with_context_and_format
/**
* @test
*/
public function it_can_serialize_with_context_and_format()
{
$format = 'yml';
$context = Mock::mock(SerializationContext::class);
$this->jmsSerializer->shouldReceive('serialize')->once()->with([1234], $format, $context);
$serializer = new JmsSerializer($this->jmsSerializer, $format, $context);
$serializer->serialize([1234]);
}
开发者ID:treehouselabs,项目名称:queue,代码行数:11,代码来源:JmsSerializerTest.php
示例17: 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
示例18: 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
示例19: 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
示例20: buildEvent
/**
* @param string $title
* @param object $object
*
* @return Event
*
* @throws LogicException
*/
private function buildEvent($title, $object)
{
if (!is_object($object)) {
throw new LogicException(sprintf('Connector only allows publish objects, "%s" given', gettype($object)));
}
$event = new Event();
$event->setTitle($title)->setNamespace(get_class($object))->setPayload($this->serializer->serialize($object, 'json'));
return $event;
}
开发者ID:nicolasdewez,项目名称:events-bundle,代码行数:17,代码来源:Publisher.php
注:本文中的JMS\Serializer\SerializerInterface类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论