mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-30 19:43:49 +00:00
add leadiing country code while seraching numbers
This commit is contained in:
@@ -11,8 +11,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Search\Utils;
|
||||
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
use LogicException;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use function count;
|
||||
use function implode;
|
||||
use function preg_match;
|
||||
@@ -24,6 +26,13 @@ class ExtractPhonenumberFromPattern
|
||||
{
|
||||
private const PATTERN = '([\\+]{0,1}[0-9\\ ]{5,})';
|
||||
|
||||
private string $defaultCarrierCode;
|
||||
|
||||
public function __construct(ParameterBagInterface $parameterBag)
|
||||
{
|
||||
$this->defaultCarrierCode = $parameterBag->get('chill_main')['phone_helper']['default_carrier_code'];
|
||||
}
|
||||
|
||||
public function extractPhonenumber(string $subject): SearchExtractionResult
|
||||
{
|
||||
$matches = [];
|
||||
@@ -35,11 +44,20 @@ class ExtractPhonenumberFromPattern
|
||||
|
||||
foreach (str_split(trim($matches[0])) as $key => $char) {
|
||||
switch ($char) {
|
||||
case '+':
|
||||
if (0 === $key) {
|
||||
$phonenumber[] = $char;
|
||||
} else {
|
||||
throw new LogicException('should not match not alnum character');
|
||||
}
|
||||
break;
|
||||
|
||||
case '0':
|
||||
$length++;
|
||||
|
||||
if (0 === $key) {
|
||||
$phonenumber[] = '+32';
|
||||
$util = PhoneNumberUtil::getInstance();
|
||||
$phonenumber[] = '+'.$util->getCountryCodeForRegion($this->defaultCarrierCode);
|
||||
} else {
|
||||
$phonenumber[] = $char;
|
||||
}
|
||||
|
Reference in New Issue
Block a user