Statistics
1406
1
1
4d
Badges
Dependencies

Phone number Doctrine type

Build Status Coverage Status Downloads this Month Latest stable

Installation

Via Composer:

$ composer require nepada/phone-number-doctrine

Register the type in your bootstrap:

\Doctrine\DBAL\Types\Type::addType(
    \Nepada\PhoneNumberDoctrine\PhoneNumberType::NAME,
    \Nepada\PhoneNumberDoctrine\PhoneNumberType::class
);

In Nette with nettrine/dbal integration, you can register the types in your configuration:

dbal:
    connection:
        types:
            phone_number: 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.

Example usage in the entity:

use Doctrine\ORM\Mapping as ORM;
use Brick\PhoneNumber\PhoneNumber;

/**
 * @ORM\Entity
 */
class Contact
{

    /** @ORM\Column(type="phone_number", nullable=false) */
    private PhoneNumber $phoneNumber;

    public function getPhoneNumber(): PhoneNumber
    {
        return $this->phoneNumber;
    }

}

Example usage in query builder:

$result = $repository->createQueryBuilder('foo')
    ->select('foo')
    ->where('foo.phoneNumber = :phoneNumber')
     // the parameter value is automatically normalized to +420123456789
    ->setParameter('phoneNumber', '+420 123 456 789', PhoneNumberType::NAME)
    ->getQuery()
    ->getResult()
  • v1.2.1 1.2.1

    • Improved type annotations for easier use with phpstan/phpstan-doctrine.
  • v1.2.0 1.2.0

    • Requires PHP >=7.4.
  • v1.1.0 1.1.0

    • Requires PHP >=7.2.
    • PHP 7.4 compatibility.
  • v1.0.1 1.0.1

    • Throw ConversionException on type conversion failure.
    • CI improvements.
  • v1.0.0 1.0.0

    • Initial release.

Is this addon outdated? Did you find an issue? Please report it.

Componette Componette admin@componette.com