<?php

namespace {{ namespace }};

use Oro\Bundle\EmailBundle\Entity\Util\EmailUtil;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Type;
use JMS\Serializer\Annotation\Exclude;
use Oro\Bundle\EmailBundle\Entity\EmailAddress;
use Oro\Bundle\EmailBundle\Entity\EmailOwnerInterface;

class {{ className }} extends EmailAddress
{
{% for owner in owners %}
    /**
     * @var EmailOwnerInterface
     * @Exclude
     */
    private ${{ owner.fieldName }};
{% endfor %}

    /**
     * {@inheritdoc}
     */
    public function getOwner()
    {
{% for owner in owners %}
        if ($this->{{ owner.fieldName }} !== null) {
            return $this->{{ owner.fieldName }};
        }
{% endfor %}

        return null;
    }

    /**
     * {@inheritdoc}
     */
    public function setOwner(EmailOwnerInterface $owner = null)
    {
{% for owner in owners %}
        if ($owner !== null && is_a($owner, '{{ owner.targetEntity }}')) {
            $this->{{ owner.fieldName }} = $owner;
        } else {
            $this->{{ owner.fieldName }} = null;
        }
{% endfor %}
        $this->hasOwner = ($owner !== null);

        return $this;
    }

    /**
     * Pre persist event listener
     */
    public function beforeSave()
    {
        $date = EmailUtil::currentUTCDateTime();
        $this->setCreatedAt($date);
        $this->setUpdatedAt($date);
    }

    /**
     * Pre update event listener
     */
    public function beforeUpdate()
    {
        $this->setUpdatedAt(EmailUtil::currentUTCDateTime());
    }
}

<?php

namespace {{ namespace }};

use Oro\Bundle\EmailBundle\Entity\Util\EmailUtil;
use Oro\Bundle\EmailBundle\Entity\EmailAddress;
use Oro\Bundle\EmailBundle\Entity\EmailOwnerInterface;

class {{ className }} extends EmailAddress
{
{% for owner in owners %}
    /**
     * @var EmailOwnerInterface
     */
    private ${{ owner.fieldName }};
{% endfor %}

    /**
     * {@inheritdoc}
     */
    public function getOwner()
    {
{% for owner in owners %}
        if ($this->{{ owner.fieldName }} !== null) {
            return $this->{{ owner.fieldName }};
        }
{% endfor %}

        return null;
    }

    /**
     * {@inheritdoc}
     */
    public function setOwner(EmailOwnerInterface $owner = null)
    {
{% for owner in owners %}
        if ($owner !== null && is_a($owner, '{{ owner.targetEntity }}')) {
            $this->{{ owner.fieldName }} = $owner;
        } else {
            $this->{{ owner.fieldName }} = null;
        }
{% endfor %}
        $this->hasOwner = ($owner !== null);

        return $this;
    }

    /**
     * Pre persist event listener
     */
    public function beforeSave()
    {
        $date = EmailUtil::currentUTCDateTime();
        $this->setCreatedAt($date);
        $this->setUpdatedAt($date);
    }

    /**
     * Pre update event listener
     */
    public function beforeUpdate()
    {
        $this->setUpdatedAt(EmailUtil::currentUTCDateTime());
    }
}

Relocate Email Proxy to cache folder
BAP-2561: Relocate Email Proxy to cache folder
