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 static $class = __CLASS__; |
15
|
|
|
|
16
|
|
|
protected ?string $mediaUrl = null; |
17
|
|
|
|
18
|
|
|
protected ?string $cacheUrl = null; |
19
|
|
|
|
20
|
|
|
protected ?string $assetsPath = null; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @return static |
24
|
|
|
*/ |
25
|
|
|
public static function new(): static |
26
|
|
|
{ |
27
|
|
|
return static::$class(); |
|
|
|
|
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string $mediaUrl |
32
|
|
|
*/ |
33
|
|
|
public function setMediaUrl(string $mediaUrl): void |
34
|
|
|
{ |
35
|
|
|
$this->mediaUrl = $mediaUrl; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
|
|
public function getMediaUrl(): string |
42
|
|
|
{ |
43
|
|
|
if (null !== $this->mediaUrl) { |
44
|
|
|
return $this->mediaUrl; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$this->mediaUrl = Environment::mustGetVar(Env::MEDIA_BASE_URL); |
48
|
|
|
|
49
|
|
|
return $this->mediaUrl; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $cacheUrl |
54
|
|
|
*/ |
55
|
|
|
public function setCacheUrl(string $cacheUrl): void |
56
|
|
|
{ |
57
|
|
|
$this->cacheUrl = $cacheUrl; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
|
|
public function getCacheUrl(): string |
64
|
|
|
{ |
65
|
|
|
if (null !== $this->cacheUrl) { |
66
|
|
|
return $this->cacheUrl; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$cachePath = Environment::getVar(Env::CACHE_BASE_PATH, ''); |
70
|
|
|
if (!$cachePath) { |
71
|
|
|
return ''; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$this->cacheUrl = sprintf( |
75
|
|
|
'%s%s%s', |
76
|
|
|
rtrim($this->getMediaUrl(), DIRECTORY_SEPARATOR), |
77
|
|
|
DIRECTORY_SEPARATOR, |
78
|
|
|
ltrim($cachePath, DIRECTORY_SEPARATOR) |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
return $this->cacheUrl; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param string $assetsPath |
86
|
|
|
*/ |
87
|
|
|
public function setAssetsPath(string $assetsPath): void |
88
|
|
|
{ |
89
|
|
|
$this->assetsPath = $assetsPath; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
|
|
public function getAssetsPath(): string |
96
|
|
|
{ |
97
|
|
|
if (null !== $this->assetsPath) { |
98
|
|
|
return $this->assetsPath; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
$basePath = Environment::getVar(Env::CACHE_BASE_PATH, ''); |
102
|
|
|
if (!$basePath) { |
103
|
|
|
return ''; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$path = sprintf('%s%s', $basePath, static::ASSETS_PATH); |
107
|
|
|
|
108
|
|
|
$this->assetsPath = $path; |
109
|
|
|
|
110
|
|
|
return $path; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|