forked from jeroendesloovere/vcard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTelephone.php
99 lines (78 loc) · 2.32 KB
/
Telephone.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
declare(strict_types=1);
namespace JeroenDesloovere\VCard\Property;
use Brick\PhoneNumber\PhoneNumber;
use Brick\PhoneNumber\PhoneNumberFormat;
use JeroenDesloovere\VCard\Formatter\Property\NodeFormatterInterface;
use JeroenDesloovere\VCard\Formatter\Property\TelephoneFormatter;
use JeroenDesloovere\VCard\Parser\Property\NodeParserInterface;
use JeroenDesloovere\VCard\Parser\Property\TelephoneParser;
use JeroenDesloovere\VCard\Property\Parameter\Type;
use JeroenDesloovere\VCard\Property\Parameter\Value;
final class Telephone implements PropertyInterface, NodeInterface
{
/** @var string */
protected $telephoneNumber;
/** @var PhoneNumber */
protected $phoneNumber;
/** @var Type */
private $type;
/** @var Value */
private $value;
public function __construct(string $telephoneNumber, Type $type = null, Value $value = null)
{
$regionCode = \Locale::getRegion(\Locale::getDefault());
$this->phoneNumber = PhoneNumber::parse($telephoneNumber, $regionCode);
$this->telephoneNumber = $this->phoneNumber->format(PhoneNumberFormat::NATIONAL);
$this->type = $type ?? Type::home();
$this->value = $value ?? Value::uri();
}
public function __toString(): string
{
return $this->telephoneNumber;
}
public function getFormatter(): NodeFormatterInterface
{
return new TelephoneFormatter($this);
}
public static function getNode(): string
{
return 'TEL';
}
public function getTelephoneNumber(): string
{
return $this->telephoneNumber;
}
public function getTelephoneNumberURI(): string
{
return $this->phoneNumber->format(PhoneNumberFormat::RFC3966);
}
public function getPhoneNumber(): PhoneNumber
{
return $this->phoneNumber;
}
public static function getParser(): NodeParserInterface
{
return new TelephoneParser();
}
public function isAllowedMultipleTimes(): bool
{
return true;
}
public function getType(): Type
{
return $this->type;
}
public function setType(Type $type)
{
$this->type = $type;
}
public function getValue(): Value
{
return $this->value;
}
public function setValue(Value $value)
{
$this->value = $value;
}
}