Skip to content

nordic-alliance/email-address-doctrine

Repository files navigation

Email Address Doctrine type

PHP version Software License Build Status Coverage Status Quality Score

The nordic/email-address-doctrine package provides the ability to use nordic/email-address as a Doctrine field type.

Install

Via Composer

$ composer require nordic/email-address-doctrine

Configuration

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

Usage

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;
    }
}

Credits

License

The MIT License (MIT). Please see License File for more information.