<?php

namespace Fifa\ConnectId\Sdk\Util\Serialization;

use Fifa\ConnectId\Sdk\Util\XmlDeserializer\XmlDeserializer;
use XML_Serializer;

class ValidatingXmlSerializer extends ValidatingXmlSerializerBase
{
    /**
     * @var callable
     */
    private $nullifyCallable;

    /**
     * ValidatingXmlSerializer constructor.
     * @param XML_Serializer $serializer - internal serializer
     * @param XmlDeserializer $deserializer - internal deserializer
     * @param callable $nullifyUnsetArrays - Iterates over all array-typed properties and sets them to null if they are empty. Param: $item
     */
    public function __construct(XML_Serializer $serializer, XmlDeserializer $deserializer, callable $nullifyUnsetArrays)
    {
        $this->nullifyCallable = $nullifyUnsetArrays;

        parent::__construct($serializer, $deserializer);
    }

    /**
     * @inheritDoc
     */
    protected function nullifyUnsetArrays($item)
    {
        call_user_func($this->nullifyCallable, $item);
    }
}