| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\librarys\storage\helpers;
- class UrlConverter
- {
- public $replaceUrl;
- public $region;
- public function __construct($replaceUrl = '', $region = '')
- {
- $this->replaceUrl = $replaceUrl;
- $this->region = $region;
- }
- public function __invoke($objectUrl, $saveTo, $driver)
- {
- if ($this->replaceUrl == '') {
- return $objectUrl;
- }
- if ($this->region != '') {
- $objectUrl = str_replace($this->region, '', $objectUrl);
- }
-
- return static::replaceUrl($objectUrl, $this->replaceUrl);
- }
- public static function replaceUrl($url, $replaceTo)
- {
- $urlParts = parse_url($url);
- $replaceParts = parse_url($replaceTo);
- $finalParts = array_merge($urlParts, $replaceParts);
- return static::buildUrl($finalParts);
- }
- public static function buildUrl($parts)
- {
- return (isset($parts['scheme']) ? "{$parts['scheme']}:" : '') . ((isset($parts['user']) || isset($parts['host'])) ? '//' : '') . (isset($parts['user']) ? "{$parts['user']}" : '') . (isset($parts['pass']) ? ":{$parts['pass']}" : '') . (isset($parts['user']) ? '@' : '') . (isset($parts['host']) ? "{$parts['host']}" : '') . (isset($parts['port']) ? ":{$parts['port']}" : '') . (isset($parts['path']) ? "{$parts['path']}" : '') . (isset($parts['query']) ? "?{$parts['query']}" : '') . (isset($parts['fragment']) ? "#{$parts['fragment']}" : '');
- }
- }
|