1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AbterPhp\Framework\Config; |
6
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Constant\Env; |
8
|
|
|
use AbterPhp\Framework\Environments\Environment; |
9
|
|
|
|
10
|
|
|
class Routes |
11
|
|
|
{ |
12
|
|
|
public const ASSETS_PATH = '/:path'; |
13
|
|
|
|
14
|
|
|
protected ?string $mediaUrl = null; |
15
|
|
|
|
16
|
|
|
protected ?string $cacheUrl = null; |
17
|
|
|
|
18
|
|
|
protected ?string $assetsPath = null; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param string $mediaUrl |
22
|
|
|
*/ |
23
|
|
|
public function setMediaUrl(string $mediaUrl): void |
24
|
|
|
{ |
25
|
|
|
$this->mediaUrl = $mediaUrl; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return string |
30
|
|
|
*/ |
31
|
|
|
public function getMediaUrl(): string |
32
|
|
|
{ |
33
|
|
|
if (null !== $this->mediaUrl) { |
34
|
|
|
return $this->mediaUrl; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$this->mediaUrl = Environment::mustGetVar(Env::MEDIA_BASE_URL); |
38
|
|
|
|
39
|
|
|
return $this->mediaUrl; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param string $cacheUrl |
44
|
|
|
*/ |
45
|
|
|
public function setCacheUrl(string $cacheUrl): void |
46
|
|
|
{ |
47
|
|
|
$this->cacheUrl = $cacheUrl; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
public function getCacheUrl(): string |
54
|
|
|
{ |
55
|
|
|
if (null !== $this->cacheUrl) { |
56
|
|
|
return $this->cacheUrl; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$cachePath = Environment::getVar(Env::CACHE_BASE_PATH, ''); |
60
|
|
|
if (!$cachePath) { |
61
|
|
|
return ''; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$this->cacheUrl = sprintf( |
65
|
|
|
'%s%s%s', |
66
|
|
|
rtrim($this->getMediaUrl(), DIRECTORY_SEPARATOR), |
67
|
|
|
DIRECTORY_SEPARATOR, |
68
|
|
|
ltrim($cachePath, DIRECTORY_SEPARATOR) |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
return $this->cacheUrl; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param string $assetsPath |
76
|
|
|
*/ |
77
|
|
|
public function setAssetsPath(string $assetsPath): void |
78
|
|
|
{ |
79
|
|
|
$this->assetsPath = $assetsPath; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
public function getAssetsPath(): string |
86
|
|
|
{ |
87
|
|
|
if (null !== $this->assetsPath) { |
88
|
|
|
return $this->assetsPath; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$basePath = Environment::getVar(Env::CACHE_BASE_PATH, ''); |
92
|
|
|
if (!$basePath) { |
93
|
|
|
return ''; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$path = sprintf('%s%s', $basePath, static::ASSETS_PATH); |
97
|
|
|
|
98
|
|
|
$this->assetsPath = $path; |
99
|
|
|
|
100
|
|
|
return $path; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|