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