Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
normalizer.php
1<?php
9
12
13Loc::loadMessages(__FILE__);
14
20{
28 public static function normalize($code, $typeId = Type::EMAIL)
29 {
30 if (!$code)
31 {
32 return null;
33
34 }
35 switch ($typeId)
36 {
37 case Type::IM:
38 return self::normalizeIm($code);
39
40 case Type::PHONE:
41 return self::normalizePhone($code);
42
43 case Type::CRM_COMPANY_ID:
44 case Type::CRM_CONTACT_ID:
45 case Type::CRM_LEAD_ID:
46 return self::normalizeCrmEntityId($code);
47
48 case Type::EMAIL:
49 default:
50 return self::normalizeEmail($code);
51 }
52 }
53
60 public static function normalizeEmail($code)
61 {
62 return trim(mb_strtolower($code));
63 }
64
71 public static function normalizePhone($phone)
72 {
73 return PhoneNumber\Parser::getInstance()
74 ->parse($phone)
75 ->format(PhoneNumber\Format::E164);
76 }
77
84 public static function normalizeIm($code)
85 {
86 $code = trim($code);
87 if (mb_strpos($code, 'imol|') === 0)
88 {
89 $code = mb_substr($code, 5);
90 }
91
92 return $code;
93 }
94
101 public static function normalizeCrmEntityId($code)
102 {
103 return preg_replace("/[^0-9]/", '', $code);
104 }
105}
static loadMessages($file)
Definition loc.php:64
static normalize($code, $typeId=Type::EMAIL)