-
/var/www/html/classes/Domains.php
- 49
public static function all(): array
- 50
{
- 51
if (isset(self::$_domains) == false) {
- 52
self::init();
- 53
}
- 54
- 55
return self::$_domains;
- 56
}
- 57
- 58
/**
- 59
* 특정 도메인정보를 가져온다.
- 60
*
- 61
* @param ?string $host 도메인 호스트명 (없을 경우 현재 호스트)
- 62
* @return Domain $domain
- 63
*/
- 64
public static function get(?string $host = null): Domain
- 65
{
- 66
$domain = self::has($host);
- 67
if ($domain === null) {
- 68
ErrorHandler::print(self::error('NOT_FOUND_DOMAIN', $host));
- 69
}
- 70
- 71
return $domain;
- 72
}
- 73
- 74
/**
- 75
* 특정 도메인정보가 존재한다면 가져온다.
- 76
*
- 77
* @param ?string $host 도메인 호스트명 (없을 경우 현재 호스트)
- 78
* @return ?Domain $domain
- 79
*/
- 80
public static function has(?string $host = null): ?Domain
- 81
{
- 82
if (isset(self::$_domains) == false) {
- 83
self::init();
- 84
}
- 85
- 86
$host ??= $_SERVER['HTTP_HOST'];
- 87
if (isset(self::$_domains[$host]) == true) {
- 88
return self::$_domains[$host];
- 89
}
-
/var/www/html/classes/Sites.php
- 78
$sites = array_merge($sites, array_values($languages));
- 79
}
- 80
- 81
return $sites;
- 82
}
- 83
- 84
/**
- 85
* 특정 사이트정보가 존재한다면 가져온다.
- 86
*
- 87
* @param ?string $host 사이트 호스트명 (없을 경우 현재 호스트)
- 88
* @param ?string $language 사이트 언어 (없을 경우 현재 언어)
- 89
* @return ?Site $site
- 90
*/
- 91
public static function has(?string $host = null, ?string $language = null): ?Site
- 92
{
- 93
if (isset(self::$_sites) == false) {
- 94
self::init();
- 95
}
- 96
- 97
$domain = Domains::get($host);
- 98
$host = $domain->getHost();
- 99
$language ??= Router::getLanguage();
- 100
- 101
if (isset(self::$_sites[$host][$language]) == true) {
- 102
return self::$_sites[$host][$language];
- 103
}
- 104
- 105
return null;
- 106
}
- 107
- 108
/**
- 109
* 사이트 관련 에러를 처리한다.
- 110
*
- 111
* @param string $code 에러코드
- 112
* @param ?string $message 에러메시지
- 113
* @param ?object $details 에러와 관련된 추가정보
- 114
* @return ErrorData $error
- 115
*/
- 116
public static function error(string $code, ?string $message = null, ?object $details = null): ErrorData
- 117
{
- 118
switch ($code) {
-
/var/www/html/classes/Sites.php
- 34
->get();
- 35
foreach ($sites as $site) {
- 36
self::$_sites[$site->host] ??= [];
- 37
self::$_sites[$site->host][$site->language] = new Site($site);
- 38
}
- 39
- 40
Cache::store('sites', self::$_sites);
- 41
}
- 42
}
- 43
- 44
/**
- 45
* 특정 사이트정보를 가져온다.
- 46
*
- 47
* @param ?string $host 사이트 호스트명 (없을 경우 현재 호스트)
- 48
* @param ?string $language 사이트 언어 (없을 경우 현재 언어)
- 49
* @return Site $site
- 50
*/
- 51
public static function get(?string $host = null, ?string $language = null): Site
- 52
{
- 53
$site = self::has($host, $language);
- 54
if ($site === null) {
- 55
ErrorHandler::print(self::error('NOT_FOUND_SITE'), $host . '/' . $language);
- 56
}
- 57
- 58
return $site;
- 59
}
- 60
- 61
/**
- 62
* 전체 사이트정보를 가져온다.
- 63
*
- 64
* @return Site[] $sites
- 65
*/
- 66
public static function all(?string $host = null): array
- 67
{
- 68
if (isset(self::$_sites) == false) {
- 69
self::init();
- 70
}
- 71
- 72
if ($host !== null) {
- 73
return isset(self::$_sites[$host]) == true ? array_values(self::$_sites[$host]) : [];
- 74
}
-
/var/www/html/classes/Router.php
- 99
{
- 100
$route = self::has($path);
- 101
if ($route === null) {
- 102
ErrorHandler::print(ErrorHandler::error('NOT_FOUND_URL'));
- 103
}
- 104
- 105
return $route;
- 106
}
- 107
- 108
/**
- 109
* 경로가 존재한다면 경로 객체를 반환한다.
- 110
*
- 111
* @param string $path 가져올경로 (NULL 인 경우 현재경로)
- 112
* @return Route $route
- 113
*/
- 114
public static function has(string $path = null): ?Route
- 115
{
- 116
$match = $path ?? self::getPath();
- 117
if ($match == '/' && isset(self::$_routes['/']) == false) {
- 118
Sites::get()->getIndex();
- 119
}
- 120
$paths = array_keys(self::$_routes);
- 121
$matched = null;
- 122
$matchedCount = 0;
- 123
foreach ($paths as $path) {
- 124
$matcher = $path;
- 125
$matcher = preg_replace('/{[^}]+}\/\*/', '([^/]+)/*', $matcher);
- 126
$matcher = str_replace('*', '(.*?)', $matcher);
- 127
$matcher = preg_replace('/{[^}]+}/', '(.*?)', $matcher);
- 128
$matcher = str_replace('/', '\/', $matcher);
- 129
- 130
if (
- 131
preg_match('/^' . $matcher . '$/', $match, $matches) == true ||
- 132
preg_match('/^' . $matcher . '$/', '/' . self::getLanguage() . $match, $matches) == true
- 133
) {
- 134
$statics = array_filter(
- 135
explode('/', preg_replace('/^\/' . self::getLanguage() . '\//', '', $path)),
- 136
function ($p) {
- 137
return $p !== '*';
- 138
}
- 139
);
-
/var/www/html/classes/Router.php
- 81
/**
- 82
* 현재 사이트 언어에 경로를 추가한다.
- 83
*/
- 84
case '@':
- 85
$language = Sites::get()->getLanguage();
- 86
- 87
default:
- 88
self::$_routes['/' . $language . $path] = new Route($path, $language, $type, $closure);
- 89
}
- 90
}
- 91
- 92
/**
- 93
* 현재 경로에 해당하는 객체를 가져온다.
- 94
*
- 95
* @param string $path 가져올경로 (NULL 인 경우 현재경로)
- 96
* @return Route $route
- 97
*/
- 98
public static function get(string $path = null): Route
- 99
{
- 100
$route = self::has($path);
- 101
if ($route === null) {
- 102
ErrorHandler::print(ErrorHandler::error('NOT_FOUND_URL'));
- 103
}
- 104
- 105
return $route;
- 106
}
- 107
- 108
/**
- 109
* 경로가 존재한다면 경로 객체를 반환한다.
- 110
*
- 111
* @param string $path 가져올경로 (NULL 인 경우 현재경로)
- 112
* @return Route $route
- 113
*/
- 114
public static function has(string $path = null): ?Route
- 115
{
- 116
$match = $path ?? self::getPath();
- 117
if ($match == '/' && isset(self::$_routes['/']) == false) {
- 118
Sites::get()->getIndex();
- 119
}
- 120
$paths = array_keys(self::$_routes);
- 121
$matched = null;