Exemplo n.º 1
0
<?php

use Retrinko\Serializer\SerializerFactory;
use Retrinko\Serializer\Serializers\JsonSerializer;
use Retrinko\Serializer\Serializers\PhpSerializer;
require_once __DIR__ . '/../vendor/autoload.php';
$value = ['a', 'b', 'c'];
printf('Original value: %s', PHP_EOL);
var_dump($value);
$serializer = SerializerFactory::bySerializedContentType(JsonSerializer::SERIALIZED_CONTENT_TYPE);
$serializedValue = $serializer->serialize($value);
printf('Serialized value using %s: %s', 'JsonSerializer', PHP_EOL);
var_dump($serializedValue);
$serializer = SerializerFactory::bySerializedContentType(PhpSerializer::SERIALIZED_CONTENT_TYPE);
$serializedValue = $serializer->serialize($value);
printf('Serialized value using %s: %s', 'PhpSerializer', PHP_EOL);
var_dump($serializedValue);
Exemplo n.º 2
0
 /**
  * @param PayloadInterface $data
  * @param null $contentType
  *
  * @throws \Retrinko\Serializer\Exceptions\Exception
  */
 public function setPayload(PayloadInterface $data, $contentType = null)
 {
     $contentType = is_null($contentType) ? $this->getContentType() : $contentType;
     $this->setBody($data->serialize(SerializerFactory::bySerializedContentType($contentType)));
 }
Exemplo n.º 3
0
 /**
  * @expectedException \Retrinko\Serializer\Exceptions\Exception
  */
 public function test_bySerializedContentType_withUnsupportedContentType_thowsException()
 {
     SerializerFactory::bySerializedContentType('unsupported content type');
 }