Statistics
267
2
0
48d
Badges
Tags
mail
Dependencies

Email address Doctrine type

Build Status Coverage Status Downloads this Month Latest stable

Installation

Via Composer:

$ composer require nepada/email-address-doctrine

Register the types in your bootstrap:

\Doctrine\DBAL\Types\Type::addType(
    \Nepada\EmailAddressDoctrine\EmailAddressType::NAME,
    \Nepada\EmailAddressDoctrine\EmailAddressType::class
);
\Doctrine\DBAL\Types\Type::addType(
    \Nepada\EmailAddressDoctrine\EmailAddressLowercaseType::NAME,
    \Nepada\EmailAddressDoctrine\EmailAddressLowercaseType::class
);

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

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

Usage

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('ExAmPlE@ExAmPlE.com') will be stored as string ExAmPlE@example.com.

EmailAddressLowercaseType converts local part of the address to lowercase before storing it, e.g. new EmailAddress('ExAmPlE@ExAmPlE.com') will be stored as string example@example.com. 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')
    ->select('foo')
    ->where('foo.email = :emailAddress')
     // the parameter value is automatically normalized to example@example.com
    ->setParameter('emailAddress', 'Example@Example.com', EmailAddressLowercaseType::NAME)
    ->getQuery()
    ->getResult()
  • v1.1.0 1.1.0

    • Uses nepada/email-address 2.0.
  • v1.0.1 1.0.1

    • Improved method annotations.
  • v1.0.0 1.0.0

    • Initial release.

Is this addon outdated? Did you find an issue? Please report it.

Componette Componette admin@componette.com