-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPhone.php
39 lines (29 loc) · 1.13 KB
/
Phone.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
require '../../vendor/autoload.php';
use SerendipityHQ\Component\ValueObjects\Phone\Phone;
echo '<h1>Example usage of PHPValueObjects Phone.</h1>';
$phoneUtils = \libphonenumber\PhoneNumberUtil::getInstance();
dd($phoneUtils->parse('+393493176188'));
// ucfirst is applied automatically to find the right setter
$values = [
'number' => '3493534998',
'region' => 'IT',
];
$phone = new Phone($values);
dump($phone);
echo '<h2>Keep Raw Input</h2>';
$values = [
'number' => '3493534998',
'region' => 'IT',
'keepRawInput' => true
];
$phone = new Phone($values);
dump($phone);
echo '<h2>Public methods</h2>';
echo 'Phone number (RAW): ' . $phone->getRawInput() . "<br />\n";
echo 'Country code: ' . $phone->getCountryCode() . "<br />\n";
echo 'Country code source: ' . $phone->getCountryCodeSource() . "<br />\n";
echo 'Extension: ' . $phone->getExtension() . "<br />\n";
echo 'National number: ' . $phone->getNationalNumber() . "<br />\n";
echo 'Number of leading zeros: ' . $phone->getNumberOfLeadingZeros() . "<br />\n";
echo 'Preferred domestic carrier code: ' . $phone->getPreferredDomesticCarrierCode() . "<br />\n";