Passed
Push — master ( 7adf61...2dd150 )
by Peter
03:00
created

Routes::getLogoutPath()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 14
rs 10
cc 3
nc 3
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Admin\Config;
6
7
use AbterPhp\Admin\Constant\Routes as RoutesConstant;
8
use AbterPhp\Framework\Exception\Config as ConfigException;
9
use Opulence\Environments\Environment;
10
11
class Routes
12
{
13
    const ADMIN_LOGIN_PATH  = 'ADMIN_LOGIN_PATH';
14
    const ADMIN_LOGOUT_PATH = 'ADMIN_LOGOUT_PATH';
15
    const ADMIN_BASE_PATH   = 'ADMIN_BASE_PATH';
16
    const API_BASE_PATH     = 'API_BASE_PATH';
17
18
    /** @var string|null */
19
    protected static $loginPath;
20
21
    /** @var string|null */
22
    protected static $logoutPath;
23
24
    /** @var string|null */
25
    protected static $adminBasePath;
26
27
    /** @var string|null */
28
    protected static $apiBasePath;
29
30
    /**
31
     * @param string $loginPath
32
     */
33
    public static function setLoginPath(string $loginPath): void
34
    {
35
        static::$loginPath = $loginPath;
36
    }
37
38
    /**
39
     * @return string
40
     */
41
    public static function getLoginPath(): string
42
    {
43
        if (null !== static::$loginPath) {
44
            return static::$loginPath;
45
        }
46
47
        $loginPath = Environment::getVar(static::ADMIN_LOGIN_PATH);
48
        if (null === $loginPath) {
49
            throw new ConfigException(__CLASS__, [static::ADMIN_LOGIN_PATH]);
50
        }
51
52
        static::$loginPath = (string)$loginPath;
53
54
        return static::$loginPath;
55
    }
56
57
    /**
58
     * @param string $logoutPath
59
     */
60
    public static function setLogoutPath(string $logoutPath): void
61
    {
62
        static::$logoutPath = $logoutPath;
63
    }
64
65
    /**
66
     * @return string
67
     */
68
    public static function getLogoutPath(): string
69
    {
70
        if (null !== static::$logoutPath) {
71
            return static::$logoutPath;
72
        }
73
74
        $logoutPath = Environment::getVar(static::ADMIN_LOGOUT_PATH);
75
        if (null === $logoutPath) {
76
            throw new ConfigException(__CLASS__, [static::ADMIN_LOGOUT_PATH]);
77
        }
78
79
        static::$logoutPath = (string)$logoutPath;
80
81
        return static::$logoutPath;
82
    }
83
84
    /**
85
     * @param string $adminBasePath
86
     */
87
    public static function setAdminBasePath(string $adminBasePath): void
88
    {
89
        static::$adminBasePath = $adminBasePath;
90
    }
91
92
    /**
93
     * @return string
94
     */
95
    public static function getAdminBasePath(): string
96
    {
97
        if (null !== static::$adminBasePath) {
98
            return static::$adminBasePath;
99
        }
100
101
        $adminBasePath = Environment::getVar(static::ADMIN_BASE_PATH);
102
        if (null === $adminBasePath) {
103
            throw new ConfigException(__CLASS__, [static::ADMIN_BASE_PATH]);
104
        }
105
106
        static::$adminBasePath = (string)$adminBasePath;
107
108
        return static::$adminBasePath;
109
    }
110
111
    /**
112
     * @param string $apiBasePath
113
     */
114
    public static function setApiBasePath(string $apiBasePath): void
115
    {
116
        static::$apiBasePath = $apiBasePath;
117
    }
118
119
    /**
120
     * @return string
121
     */
122
    public static function getApiBasePath(): string
123
    {
124
        if (null !== static::$apiBasePath) {
125
            return static::$apiBasePath;
126
        }
127
128
        $apiBasePath = Environment::getVar(static::API_BASE_PATH);
129
        if (null === $apiBasePath) {
130
            throw new ConfigException(__CLASS__, [static::API_BASE_PATH]);
131
        }
132
133
        static::$apiBasePath = (string)$apiBasePath;
134
135
        return static::$apiBasePath;
136
    }
137
138
    /**
139
     * @return string
140
     */
141
    public static function getLoginFailurePath(): string
142
    {
143
        return static::getAdminBasePath();
144
    }
145
146
    /**
147
     * @return string
148
     */
149
    public static function getLoginSuccessPath(): string
150
    {
151
        return static::getAdminBasePath() . RoutesConstant::PATH_DASHBOARD;
152
    }
153
}
154