for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Chubbyphp\Serialization\Normalizer;
use Chubbyphp\Serialization\Accessor\AccessorInterface;
use Chubbyphp\Serialization\SerializerLogicException;
final class ReferenceFieldNormalizer implements FieldNormalizerInterface
{
/**
* @var AccessorInterface
*/
private $accessor;
* @param AccessorInterface $accessor
public function __construct(AccessorInterface $accessor)
$this->accessor = $accessor;
}
* @param string $path
* @param object $object
* @param NormalizerContextInterface $context
* @param NormalizerInterface|null $normalizer
public function normalizeField(
string $path,
$object,
NormalizerContextInterface $context,
NormalizerInterface $normalizer = null
) {
if (null === $normalizer) {
throw SerializerLogicException::createMissingNormalizer($path);
if (null === $value = $this->accessor->getValue($object)) {
return null;
return $normalizer->normalize($value, $context, $path);