Phone number Doctrine type
, (*1)
Installation
Via Composer:, (*2)
$ composer require nepada/phone-number-doctrine
Register the type in your bootstrap:, (*3)
\Doctrine\DBAL\Types\Type::addType(
\Brick\PhoneNumber\PhoneNumber::class,
\Nepada\PhoneNumberDoctrine\PhoneNumberType::class
);
In Nette with nettrine/dbal integration, you can register the types in your configuration:, (*4)
dbal:
connection:
types:
Brick\PhoneNumber\PhoneNumber: Nepada\PhoneNumberDoctrine\PhoneNumberType
Usage
PhoneNumberType
maps database value to phone number value object (see brick/phonenumber for further details) and back. The phone number is stored using E164 format, i.e. a '+' sign followed by a series of digits comprising the country code and national number., (*5)
Example usage in the entity:, (*6)
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Brick\PhoneNumber\PhoneNumber;
#[Entity]
class Contact
{
#[Column(type: PhoneNumber::class, nullable: false)]
private PhoneNumber $phoneNumber;
public function getPhoneNumber(): PhoneNumber
{
return $this->phoneNumber;
}
}
Example usage in query builder:, (*7)
$result = $repository->createQueryBuilder('foo')
->select('foo')
->where('foo.phoneNumber = :phoneNumber')
// the parameter value is automatically normalized to +420123456789
->setParameter('phoneNumber', '+420 123 456 789', \Brick\PhoneNumber\PhoneNumber::class)
->getQuery()
->getResult();