PHP code example of nepada / email-address-doctrine

1. Go to this page and download the library: Download nepada/email-address-doctrine library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nepada / email-address-doctrine example snippets


\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
);

use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Nepada\EmailAddress\CaseInsensitiveEmailAddress;

#[Entity]
class Contact
{

    #[Column(type: CaseInsensitiveEmailAddress::class, nullable: false)]
    private CaseInsensitiveEmailAddress $email;

    public function getEmailAddress(): CaseInsensitiveEmailAddress
    {
        return $this->emailAddress;
    }

}

$result = $repository->createQueryBuilder('foo')
    ->select('foo')
    ->where('foo.email = :emailAddress')
     // the parameter value is automatically normalized to [email protected]
    ->setParameter('emailAddress', '[email protected]', CaseInsensitiveEmailAddress::class)
    ->getQuery()
    ->getResult();