domain(); } else { $storage = Cache::get('STORAGE_ENGINE'); if (!$storage) { $storage = ConfigService::get('storage', $default); Cache::set('STORAGE_ENGINE', $storage); } $domain = $storage ? $storage['domain'] : ''; } return self::format($domain, $uri); } /** * @notes 转相对路径 * @param $uri * @return mixed * @author 张无忌 * @date 2021/7/28 15:09 */ public static function setFileUrl($uri) { $default = ConfigService::get('storage', 'default', 'local'); if ($default === 'local') { $domain = request()->domain(); return str_replace($domain.'/', '', $uri); } else { $storage = ConfigService::get('storage', $default); return str_replace($storage['domain'].'/', '', $uri); } } /** * @notes 格式化url * @param $domain * @param $uri * @return string * @author 段誉 * @date 2022/7/11 10:36 */ public static function format($domain, $uri) { // 处理域名 $domainLen = strlen($domain); $domainRight = substr($domain, $domainLen -1, 1); if ('/' == $domainRight) { $domain = substr_replace($domain,'',$domainLen -1, 1); } // 处理uri $uriLeft = substr($uri, 0, 1); if('/' == $uriLeft) { $uri = substr_replace($uri,'',0, 1); } return trim($domain) . '/' . trim($uri); } }