Passed
Push — master ( 3039c7...cdcb0a )
by Peter
02:28
created

Routes::getAssetsPath()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
nc 3
nop 0
dl 0
loc 16
c 0
b 0
f 0
cc 3
rs 10
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 static $mediaUrl;
16
17
    /** @var string|null */
18
    protected static $cacheUrl;
19
20
    /** @var string|null */
21
    protected static $assetsPath;
22
23
    /**
24
     * @param string $mediaUrl
25
     */
26
    public static function setMediaUrl(string $mediaUrl): void
27
    {
28
        static::$mediaUrl = $mediaUrl;
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public static function getMediaUrl(): string
35
    {
36
        if (null !== static::$mediaUrl) {
37
            return static::$mediaUrl;
38
        }
39
40
        static::$mediaUrl = (string)Environment::getVar(Env::MEDIA_BASE_URL);
41
42
        return static::$mediaUrl;
43
    }
44
45
    /**
46
     * @param string $cacheUrl
47
     */
48
    public static function setCacheUrl(string $cacheUrl): void
49
    {
50
        static::$cacheUrl = $cacheUrl;
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public static function getCacheUrl(): string
57
    {
58
        if (null !== static::$cacheUrl) {
59
            return static::$cacheUrl;
60
        }
61
62
        $cachePath = Environment::getVar(Env::CACHE_BASE_PATH, '');
63
        if (!$cachePath) {
64
            return '';
65
        }
66
67
        $cacheUrl = sprintf(
68
            '%s%s%s',
69
            rtrim(static::getMediaUrl(), DIRECTORY_SEPARATOR),
70
            DIRECTORY_SEPARATOR,
71
            ltrim($cachePath, DIRECTORY_SEPARATOR)
72
        );
73
74
        static::$cacheUrl = (string)$cacheUrl;
75
76
        return static::$cacheUrl;
77
    }
78
79
    /**
80
     * @return string
81
     */
82
    public static function getAssetsPath(): string
83
    {
84
        if (null !== static::$assetsPath) {
85
            return static::$assetsPath;
86
        }
87
88
        $basePath = Environment::getVar(Env::CACHE_BASE_PATH, '');
89
        if (!$basePath) {
90
            return '';
91
        }
92
93
        $assetsPath = sprintf('%s%s', $basePath, static::ASSETS_PATH);
94
95
        static::$assetsPath = (string)$assetsPath;
96
97
        return static::$assetsPath;
98
    }
99
}
100