nepada / phone-number-doctrine
Phone number type for Doctrine.
Installs: 29 077
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: >=8.1.0 <8.5
- brick/phonenumber: ^0.2.2@dev || ^0.3@dev || ^0.4@dev || ^0.5@dev || ^0.6@dev
- doctrine/dbal: ^3.4@dev || ^4.0@dev
Requires (Dev)
- giggsey/libphonenumber-for-php: >=8.13.47
- mockery/mockery: 1.6.12
- nepada/coding-standard: 7.14.0
- nepada/phpstan-nette-tester: 1.2.1
- nette/tester: 2.5.4
- php-parallel-lint/php-parallel-lint: 1.4.0
- phpstan/phpstan: 1.12.5
- phpstan/phpstan-mockery: 1.1.3
- phpstan/phpstan-strict-rules: 1.6.1
- shipmonk/phpstan-rules: 3.2.0
- spaze/phpstan-disallowed-calls: 3.4.0
README
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();