Email address type for Doctrine.

v1.3.0 2019-12-23 14:49 UTC

This package is auto-updated.

Last update: 2020-02-16 16:27:50 UTC


Build Status Coverage Status Downloads this Month Latest stable


Via Composer:

$ composer require nepada/email-address-doctrine

Register the types in your bootstrap:


In Nette with kdyby/doctrine integration, you can register the types in your configuration:

        email_address: Nepada\EmailAddressDoctrine\EmailAddressType
        email_address_lowercase: Nepada\EmailAddressDoctrine\EmailAddressLowercaseType


There are two Doctrine types in this package - EmailAddressType and EmailAddressLowercaseType. Both types map database value to email address value object (see nepada/email-address for further details) and back. Both types normalize the domain part of the email address before storing it in database, but they differ in handling of the local part of the address.

EmailAddressType leaves the local part as is, e.g. new EmailAddress('') will be stored as string

EmailAddressLowercaseType converts local part of the address to lowercase before storing it, e.g. new EmailAddress('') will be stored as string This is not RFC 5321 compliant, however in practice all major mail providers treat local part in case insensitive manner.

Example usage in the entity:

use Doctrine\ORM\Mapping as ORM;
use Nepada\EmailAddress\EmailAddress;

 * @ORM\Entity
 * @ORM\Table(name="contacts")
class Contact

     * @ORM\Column(type="email_address_lowercase", nullable=false)
     * @var EmailAddress
    private $email;

    public function getEmailAddress(): EmailAddress
        return $this->emailAddress;


Example usage in query builder:

$result = $repository->createQueryBuilder('foo')
    ->where(' = :emailAddress')
     // the parameter value is automatically normalized to
    ->setParameter('emailAddress', '', EmailAddressLowercaseType::NAME)