1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace seosazi\PathConverter; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
class RemovePathWithPointPointSlash |
8
|
|
|
{ |
9
|
|
|
/** @var string */ |
10
|
|
|
private $path; |
11
|
|
|
/** @var string */ |
12
|
|
|
private $starterPath; |
13
|
|
|
/** @var string */ |
14
|
|
|
private $scheme; |
15
|
|
|
/** @var string */ |
16
|
|
|
private $domain; |
17
|
|
|
public function __construct(ConvertToAbsolutePath $convertToAbsolutePath, string $path) |
18
|
|
|
{ |
19
|
|
|
$this->setPath($path); |
20
|
|
|
$this->setStarterPath($convertToAbsolutePath->uptoLastDir($convertToAbsolutePath->getStarterPath())); |
21
|
|
|
$this->setScheme($convertToAbsolutePath->getScheme()); |
22
|
|
|
$this->setDomain($convertToAbsolutePath->getDomain()); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function compute() |
26
|
|
|
{ |
27
|
|
|
while(substr($this->getPath(), 0, 3) == '../') { |
28
|
|
|
$this->setStarterPath(preg_replace('/\/([^\/]+\/)$/i', '/', $this->getStarterPath())); |
29
|
|
|
$this->setPath(substr($this->getPath(), 3)); |
30
|
|
|
} |
31
|
|
|
if ($this->getStarterPath() === ($this->getScheme() . '://')) { |
32
|
|
|
$this->setStarterPath($this->getStarterPath() . $this->getDomain()); |
33
|
|
|
} elseif ($this->getStarterPath() ===($this->getScheme(). ':/')) { |
34
|
|
|
$this->setStarterPath($this->getStarterPath() . '/' . $this->getDomain()); |
35
|
|
|
} |
36
|
|
|
return $this->getStarterPath() . $this->getPath(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
|
|
public function getPath(): string |
45
|
|
|
{ |
46
|
|
|
return $this->path; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param string $path |
51
|
|
|
*/ |
52
|
|
|
public function setPath(string $path): void |
53
|
|
|
{ |
54
|
|
|
$this->path = $path; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function getStarterPath(): string |
61
|
|
|
{ |
62
|
|
|
return $this->starterPath; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param string $starterPath |
67
|
|
|
*/ |
68
|
|
|
public function setStarterPath(string $starterPath): void |
69
|
|
|
{ |
70
|
|
|
$this->starterPath = $starterPath; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
|
|
public function getScheme(): string |
77
|
|
|
{ |
78
|
|
|
return $this->scheme; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param string $scheme |
83
|
|
|
*/ |
84
|
|
|
public function setScheme(string $scheme): void |
85
|
|
|
{ |
86
|
|
|
$this->scheme = $scheme; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
public function getDomain(): string |
93
|
|
|
{ |
94
|
|
|
return $this->domain; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param string $domain |
99
|
|
|
*/ |
100
|
|
|
public function setDomain(string $domain): void |
101
|
|
|
{ |
102
|
|
|
$this->domain = $domain; |
103
|
|
|
} |
104
|
|
|
} |