<?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);
/** * @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))); }
/** * @expectedException \Retrinko\Serializer\Exceptions\Exception */ public function test_bySerializedContentType_withUnsupportedContentType_thowsException() { SerializerFactory::bySerializedContentType('unsupported content type'); }