1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Keppler\Url\Scheme\Schemes\Mailto\Bags; |
5
|
|
|
|
6
|
|
|
use Keppler\Url\Interfaces\Immutable\ImmutableBagInterface; |
7
|
|
|
use Keppler\Url\Scheme\Schemes\AbstractImmutable; |
8
|
|
|
use Keppler\Url\Traits\Accessor; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class MailtoImmutablePath |
12
|
|
|
* |
13
|
|
|
* @package Keppler\Url\Scheme\Schemes\Mailto\Bags |
14
|
|
|
*/ |
15
|
|
|
class MailtoImmutablePath extends AbstractImmutable implements ImmutableBagInterface |
16
|
|
|
{ |
17
|
|
|
use Accessor; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The path can be either a string or a comma separated value of strings |
21
|
|
|
* |
22
|
|
|
* @example mailto:[email protected],[email protected] |
23
|
|
|
* @example mailto:[email protected] |
24
|
|
|
* |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
private $path = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private $raw = ''; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* MailtoImmutablePath constructor. |
36
|
|
|
* |
37
|
|
|
* @param string $raw |
38
|
|
|
*/ |
39
|
|
|
public function __construct(string $raw = '') |
40
|
|
|
{ |
41
|
|
|
$this->raw = $raw; |
42
|
|
|
if (!empty(trim($raw))) { |
43
|
|
|
// If a comma is present assume that the url contains more than one email address |
44
|
|
|
// Also assume that the url isn't malformed in some way |
45
|
|
|
// No validation of emails will occur, it's the job of the caller to do that |
46
|
|
|
if (false !== strpos($raw, ',')) { |
47
|
|
|
$this->path = explode(',', $raw); |
48
|
|
|
} else { |
49
|
|
|
$this->path = []; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
///////////////////////// |
55
|
|
|
/// GETTER FUNCTIONS /// |
56
|
|
|
//////////////////////// |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return null|string |
60
|
|
|
*/ |
61
|
|
|
public function first(): ?string |
62
|
|
|
{ |
63
|
|
|
return $this->firstInPath($this->path); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return null|string |
68
|
|
|
*/ |
69
|
|
|
public function last(): ?string |
70
|
|
|
{ |
71
|
|
|
return $this->lastInPath($this->path); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param string $value |
76
|
|
|
* @return bool |
77
|
|
|
*/ |
78
|
|
|
public function hasInPath(string $value): bool |
79
|
|
|
{ |
80
|
|
|
return $this->hasValueIn($this->path, $value); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
///////////////////////////////// |
84
|
|
|
/// INTERFACE IMPLEMENTATION /// |
85
|
|
|
///////////////////////////////// |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return array |
89
|
|
|
*/ |
90
|
|
|
public function getPath(): array |
91
|
|
|
{ |
92
|
|
|
return $this->path; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return array |
97
|
|
|
*/ |
98
|
|
|
public function all(): array |
99
|
|
|
{ |
100
|
|
|
return $this->path; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
|
|
public function raw(): string |
107
|
|
|
{ |
108
|
|
|
return $this->raw; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|