<?php
/**
 * Class FormDataHandler
 * User: Nessandro
 * Date: 2019-10-01
 * Time: 08:46
 * @package ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Traits
 */

namespace ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Traits;


/**
 * Trait FormDataHandler
 * @package ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Traits
 */
trait FormDataHandler
{

    /**
     * @var array
     */
    protected $formData = [];

    /**
     * @return array
     */
    public function getFormData()
    {
        return $this->formData;
    }

    /**
     * @param $formData
     * @return $this
     */
    public function setFormData($formData)
    {
        foreach($formData as $key => &$value)
        {
            $this->updateEntity($value);
        }

        $this->formData = $formData;
        return $this;
    }

    /**
     * @param null $entity
     */
    public function updateEntity(&$entity = null)
    {
        if(is_array($entity))
        {
            foreach ($entity as $key => &$value)
            {
                $this->updateEntity($value);
            }
        }elseif(is_object($entity))
        {

        }else{
            $entity = html_entity_decode($entity, ENT_QUOTES);
        }

    }



}