for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Chubbyphp\Serialization;
use Chubbyphp\Serialization\Encoder\EncoderInterface;
use Chubbyphp\Serialization\Normalizer\NormalizerContextInterface;
use Chubbyphp\Serialization\Normalizer\NormalizerInterface;
final class Serializer implements SerializerInterface
{
/**
* @var NormalizerInterface
*/
private $normalizer;
* @var EncoderInterface
private $encoder;
public function __construct(NormalizerInterface $normalizer, EncoderInterface $encoder)
$this->normalizer = $normalizer;
$this->encoder = $encoder;
}
* @param object $object
* @param string $path
public function serialize(
$object,
string $contentType,
NormalizerContextInterface $context = null,
$path = ''
): string {
return $this->encoder->encode($this->normalizer->normalize($object, $context, $path), $contentType);
*
* @throws SerializerLogicException
public function normalize($object, NormalizerContextInterface $context = null, string $path = ''): array
return $this->normalizer->normalize($object, $context, $path);
* @return string[]
public function getContentTypes(): array
return $this->encoder->getContentTypes();
public function encode(array $data, string $contentType): string
return $this->encoder->encode($data, $contentType);