1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Keppler\Url\Scheme\Schemes\Ftp\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 HttpImmutablePath |
12
|
|
|
* @package Keppler\Url\Schemes\Http\Bags |
13
|
|
|
*/ |
14
|
|
|
class FtpImmutablePath extends AbstractImmutable implements ImmutableBagInterface |
15
|
|
|
{ |
16
|
|
|
use Accessor; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* path = path-abempty ; begins with "/" or is empty |
20
|
|
|
* |
21
|
|
|
* |
22
|
|
|
* / path-absolute ; begins with "/" but not "//" |
23
|
|
|
* / path-noscheme ; begins with a non-colon segment |
24
|
|
|
* / path-rootless ; begins with a segment |
25
|
|
|
* / path-empty ; zero characters |
26
|
|
|
* |
27
|
|
|
* path-abempty = *( "/" segment ) |
28
|
|
|
* path-absolute = "/" [ segment-nz *( "/" segment ) ] |
29
|
|
|
* path-noscheme = segment-nz-nc *( "/" segment ) |
30
|
|
|
* path-rootless = segment-nz *( "/" segment ) |
31
|
|
|
* path-empty = 0<pchar> |
32
|
|
|
* segment = *pchar |
33
|
|
|
* segment-nz = 1*pchar |
34
|
|
|
* segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" ) |
35
|
|
|
* ; non-zero-length segment without any colon ":" |
36
|
|
|
* |
37
|
|
|
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@ |
38
|
|
|
* |
39
|
|
|
* @see https://tools.ietf.org/html/rfc3986#page-22 |
40
|
|
|
* |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
private $path = []; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
private $raw = ''; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* This should be the ONLY entry point and it should accept ONLY the raw string |
52
|
|
|
* |
53
|
|
|
* FtpImmutablePath constructor. |
54
|
|
|
* |
55
|
|
|
* @param string $raw |
56
|
|
|
*/ |
57
|
|
|
public function __construct(string $raw = '') |
58
|
|
|
{ |
59
|
|
|
// Leave the class with defaults if no valid raw string is provided |
60
|
|
|
if ('' !== trim($raw)) { |
61
|
|
|
$this->raw = $raw; |
62
|
|
|
|
63
|
|
|
// explode by / |
64
|
|
|
$this->path = explode('/', trim($raw, '/')); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
////////////////////////// |
69
|
|
|
/// GETTER FUNCTIONS /// |
70
|
|
|
//////////////////////// |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return string|null |
74
|
|
|
*/ |
75
|
|
|
public function first(): ?string |
76
|
|
|
{ |
77
|
|
|
return $this->firstInPath($this->path); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
|
|
public function last(): ?string |
84
|
|
|
{ |
85
|
|
|
return $this->lastInPath($this->path); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param int $key |
90
|
|
|
* @return mixed |
91
|
|
|
* @throws \Keppler\Url\Exceptions\ComponentNotFoundException |
92
|
|
|
*/ |
93
|
|
|
public function get(int $key) |
94
|
|
|
{ |
95
|
|
|
return $this->getKeyIn($this->path, $key); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param int $key |
100
|
|
|
* @return bool |
101
|
|
|
*/ |
102
|
|
|
public function has(int $key): bool |
103
|
|
|
{ |
104
|
|
|
return $this->hasKeyIn($this->path, $key); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
///////////////////////////////// |
108
|
|
|
/// INTERFACE IMPLEMENTATION /// |
109
|
|
|
/////////////////////////////// |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Returns all the components of the query or path |
113
|
|
|
* |
114
|
|
|
* @return array |
115
|
|
|
*/ |
116
|
|
|
public function all(): array |
117
|
|
|
{ |
118
|
|
|
return $this->path; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Return the raw unaltered query or path |
123
|
|
|
* |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
|
|
public function raw(): string |
127
|
|
|
{ |
128
|
|
|
return $this->raw; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|