PHP code example of nepada / phone-number-doctrine

1. Go to this page and download the library: Download nepada/phone-number-doctrine library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nepada / phone-number-doctrine example snippets


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

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

}

$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();