The nordic/email-address-doctrine package provides the ability to use nordic/email-address as a Doctrine field type.
Via Composer
$ composer require nordic/email-address-doctrine
To configure Doctrine to use nordic/email-address as a field type, you'll need to set up the following in your bootstrap:
<?php
use Doctrine\DBAL\Types\Type;
use Nordic\EmailAddress\Doctrine\EmailAddressType;
Type::addType(EmailAddressType::EMAIL_ADDRESS, EmailAddressType::CLASS);
// or
Type::addType('email_address', 'Nordic\EmailAddress\Doctrine\EmailAddressType');
Now you can annotate properties in your entities:
use Doctrine\ORM\Mapping as ORM;
use Nordic\EmailAddress\EmailAddressInterface;
/**
* @ORM\Entity
* @ORM\Table(name="contacts")
*/
class Contact
{
/**
* @ORM\Column(type="email_address")
* @var EmailAddressInterface
*/
private $emailAddress;
public function getEmailAddress(): EmailAddressInterface
{
return $this->emailAddress;
}
}
The MIT License (MIT). Please see License File for more information.