abterphp /
admin
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace AbterPhp\Admin\Config; |
||
| 6 | |||
| 7 | use AbterPhp\Framework\Exception\Config; |
||
| 8 | use Opulence\Environments\Environment; |
||
| 9 | |||
| 10 | class Routes |
||
| 11 | { |
||
| 12 | const OPTION_NAME = 'name'; |
||
| 13 | const OPTION_VARS = 'vars'; |
||
| 14 | const OPTION_MIDDLEWARE = 'middleware'; |
||
| 15 | |||
| 16 | const ADMIN_LOGIN_PATH = 'ADMIN_LOGIN_PATH'; |
||
| 17 | const ADMIN_BASE_PATH = 'ADMIN_BASE_PATH'; |
||
| 18 | const API_BASE_PATH = 'API_BASE_PATH'; |
||
| 19 | |||
| 20 | /** @var string */ |
||
| 21 | protected static $loginPath; |
||
| 22 | |||
| 23 | /** @var string */ |
||
| 24 | protected static $adminBasePath; |
||
| 25 | |||
| 26 | /** @var string */ |
||
| 27 | protected static $apiBasePath; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @param string $loginPath |
||
| 31 | */ |
||
| 32 | public static function setLoginPath(string $loginPath): void |
||
| 33 | { |
||
| 34 | static::$loginPath = $loginPath; |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @return string |
||
| 39 | */ |
||
| 40 | public static function getLoginPath(): string |
||
| 41 | { |
||
| 42 | if (null === static::$loginPath) { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 43 | static::$loginPath = Environment::getVar(static::ADMIN_LOGIN_PATH); |
||
| 44 | } |
||
| 45 | |||
| 46 | if (null === static::$loginPath) { |
||
|
0 ignored issues
–
show
|
|||
| 47 | throw new Config(__CLASS__, [static::ADMIN_LOGIN_PATH]); |
||
| 48 | } |
||
| 49 | |||
| 50 | return static::$loginPath; |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param string $adminBasePath |
||
| 55 | */ |
||
| 56 | public static function setAdminBasePath(string $adminBasePath): void |
||
| 57 | { |
||
| 58 | static::$adminBasePath = $adminBasePath; |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @return string |
||
| 63 | */ |
||
| 64 | public static function getAdminBasePath(): string |
||
| 65 | { |
||
| 66 | if (null === static::$adminBasePath) { |
||
|
0 ignored issues
–
show
|
|||
| 67 | static::$adminBasePath = Environment::getVar(static::ADMIN_BASE_PATH); |
||
| 68 | } |
||
| 69 | |||
| 70 | if (null === static::$adminBasePath) { |
||
|
0 ignored issues
–
show
|
|||
| 71 | throw new Config(__CLASS__, [static::ADMIN_BASE_PATH]); |
||
| 72 | } |
||
| 73 | |||
| 74 | return static::$adminBasePath; |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @param string $apiBasePath |
||
| 79 | */ |
||
| 80 | public static function setApiBasePath(string $apiBasePath): void |
||
| 81 | { |
||
| 82 | static::$apiBasePath = $apiBasePath; |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @return string |
||
| 87 | */ |
||
| 88 | public static function getApiBasePath(): string |
||
| 89 | { |
||
| 90 | if (null === static::$apiBasePath) { |
||
|
0 ignored issues
–
show
|
|||
| 91 | static::$apiBasePath = Environment::getVar(static::API_BASE_PATH); |
||
| 92 | } |
||
| 93 | |||
| 94 | if (null === static::$apiBasePath) { |
||
|
0 ignored issues
–
show
|
|||
| 95 | throw new Config(__CLASS__, [static::API_BASE_PATH]); |
||
| 96 | } |
||
| 97 | |||
| 98 | return static::$apiBasePath; |
||
| 99 | } |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @return string |
||
| 103 | */ |
||
| 104 | public static function getLoginFailurePath(): string |
||
| 105 | { |
||
| 106 | return static::getAdminBasePath(); |
||
| 107 | } |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @return string |
||
| 111 | */ |
||
| 112 | public static function getLoginSuccessPath(): string |
||
| 113 | { |
||
| 114 | return static::getAdminBasePath() . \AbterPhp\Admin\Constant\Routes::PATH_DASHBOARD; |
||
| 115 | } |
||
| 116 | } |
||
| 117 |