Componette

Componette

nepada

nepada / email-address-doctrine v1.4.1

Email address type for Doctrine.

download-cloud-line composer require nepada/email-address-doctrine

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\EmailAddress\RfcEmailAddress::class,
    \Nepada\EmailAddressDoctrine\RfcEmailAddressType::class
);
\Doctrine\DBAL\Types\Type::addType(
    \Nepada\EmailAddress\CaseInsensitiveEmailAddress::class,
    \Nepada\EmailAddressDoctrine\CaseInsensitiveEmailAddressType::class
);

In Nette with nettrine/dbal integration, you can register the types in your configuration:

dbal:
    connection:
        types:
            Nepada\EmailAddress\RfcEmailAddress: Nepada\EmailAddressDoctrine\RfcEmailAddressType
            Nepada\EmailAddress\CaseInsensitiveEmailAddress: Nepada\EmailAddressDoctrine\CaseInsensitiveEmailAddressType

Usage

This package provides two Doctrine types:

  1. RfcEmailAddressType for storing emails represented by RfcEmailAddress.
  2. CaseInsensitiveEmailAddressType for storing emails represented by CaseInsensitiveEmailAddress.

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. See nepada/email-address for further details.

Example usage in the entity:

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

/**
 * @ORM\Entity
 */
class Contact
{

    /** @ORM\Column(type=CaseInsensitiveEmailAddress::class, nullable=false) */
    private CaseInsensitiveEmailAddress $email;

    public function getEmailAddress(): CaseInsensitiveEmailAddress
    {
        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', CaseInsensitiveEmailAddress::class)
    ->getQuery()
    ->getResult();
  • v1.4.1 1.4.1

    • PHP 8.0 compatibility.
  • v1.4.0 1.4.0

    • Introduce two new types for mapping of addresses represented by RfcEmailAddress and CaseInsensitiveEmailAddress.
    • Deprecated the original types: use RfcEmailAddressType instead of legacy email_address, and CaseInsensitiveEmailAddressType instead of legacy email_address_lowercase.
  • v1.3.1 1.3.1

    • Improved type annotations for easier use with phpstan/phpstan-doctrine.
  • v1.3.0 1.3.0

    • Requires PHP >=7.4.
  • v1.2.0 1.2.0

    • Requires PHP >=7.2.
    • PHP 7.4 compatibility.
  • v1.1.1 1.1.1

    • Throw ConversionException on type conversion failure.
    • CI improvements.
  • 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.
bar-chart-fill

Statistics

download-cloud-fill
1671
star-fill
2
bug-fill
0
flashlight-fill
22d
price-tag-2-line

Badges

guide-fill

Dependencies

php (>=7.1.0)
doctrine/dbal (^2.6@dev)
Componette Componette felix@nette.org