nepada / email-address-doctrine
Email address type for Doctrine.
Installs: 5 158
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=8.1.0 <8.5
- doctrine/dbal: ^3.0@dev || ^4.0@dev
- nepada/email-address: ^2.3@dev || ^3.0@dev
Requires (Dev)
- mockery/mockery: 1.6.12
- nepada/coding-standard: 7.14.0
- nepada/phpstan-nette-tester: 1.2.1
- nette/tester: 2.5.4
- nette/utils: >=3.2.7
- php-parallel-lint/php-parallel-lint: 1.4.0
- phpstan/phpstan: 1.12.5
- phpstan/phpstan-mockery: 1.1.3
- phpstan/phpstan-nette: 1.3.8
- phpstan/phpstan-strict-rules: 1.6.1
- shipmonk/phpstan-rules: 3.2.0
- spaze/phpstan-disallowed-calls: 3.4.0
README
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:
RfcEmailAddressType
for storing emails represented byRfcEmailAddress
.CaseInsensitiveEmailAddressType
for storing emails represented byCaseInsensitiveEmailAddress
.
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\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; } }
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();