Componette

Componette

nepada

nepada / phone-number-doctrine v2.3.0

Phone number type for Doctrine.

download-cloud-line composer require nepada/phone-number-doctrine

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(
    \Brick\PhoneNumber\PhoneNumber::class,
    \Nepada\PhoneNumberDoctrine\PhoneNumberType::class
);

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

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.

Example usage in the entity:

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:

$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();
  • v2.3.0 2.3.0

    • Add Doctrine DBAL 4.x support
    • Drop Doctrine DBAL <3.4 support
  • v2.2.1 2.2.1

    • Add support for brick/phonenumber 0.6.x
  • v2.2.0 2.2.0

    • Drop support for PHP <8.1
    • Use PHP8 native typehints
    • Drop useless annotations
    • PHP 8.3 compatibility
  • v2.1.2 2.1.2

    • Add support for brick/phonenumber 0.5.x
  • v2.1.1 2.1.1

    • PHP 8.2 compatibility
  • v2.1.0 2.1.0

    • PHP 8.1 compatibility.
    • Add support for doctrine/dbal 3.x.
    • Add support for brick/phonenumber 0.3.x and 0.4.x.
  • v2.0.1 2.0.1

    • PHP 8.0 compatibility.
  • v2.0.0 2.0.0

    • BC break: Use the value object class name (Brick\PhoneNumber\PhoneNumber) as a doctrine type name instead of phone_number.
  • 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.
Componette Componette felix@nette.org