Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update getUrl function #43

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Conversation

MrBaoquan
Copy link

 /***
     * OssClient.php
     * 检查endpoint的种类
     * 如有有协议头,剥去协议头
     * 并且根据参数 is_cname 和endpoint本身,判定域名类型,是ip,cname,还是专有域或者官网域名
     *
     * @param string $endpoint
     * @param boolean $isCName
     * @return string 剥掉协议头的域名
     */
    private function checkEndpoint($endpoint, $isCName)
    {
        $ret_endpoint = null;
        if (strpos($endpoint, 'http://') === 0) {
            $ret_endpoint = substr($endpoint, strlen('http://'));
        } elseif (strpos($endpoint, 'https://') === 0) {
            $ret_endpoint = substr($endpoint, strlen('https://'));
            $this->useSSL = true;
        } else {
            $ret_endpoint = $endpoint;
        }

        if ($isCName) {
            $this->hostType = self::OSS_HOST_TYPE_CNAME;
        } elseif (OssUtil::isIPFormat($ret_endpoint)) {
            $this->hostType = self::OSS_HOST_TYPE_IP;
        } else {
            $this->hostType = self::OSS_HOST_TYPE_NORMAL;
        }
        return $ret_endpoint;
    }

该函数会根据endpoint的协议头的类型是http 或者 https进行设置useSSL
所以'cdnDomain'     => '<CDN domain, cdn域名>',这部分应该填上域名使用的协议头
如'cdnDomain'=>'https://abc.example.com'

// AliOssAdapter.php
 public function getUrl( $path )
    {
        if (!$this->has($path)) throw new FileNotFoundException($filePath.' not found');
        return ( $this->ssl ? 'https://' : 'http://' ) . ( $this->isCname ? ( $this->cdnDomain == '' ? $this->endPoint : $this->cdnDomain ) : $this->bucket . '.' . $this->endPoint ) . '/' . ltrim($path, '/');
    }

该函数返回的地址不应该根据ssl变量进行判别cdn域名了。而应该改为

if($this->isCname)
+        {
+            return $this->cdnDomain.'/'.ltrim($path);
+        }else
+        {
+            return ( $this->ssl ? 'https://' : 'http://' ).( $this->cdnDomain == '' ? $this->endPoint : $this->cdnDomain ). '/' . ltrim($path, '/');
+        }

@@ -1,27 +1,27 @@
{
"name": "jacobcyl/ali-oss-storage",
"name": "mrbaoquan/ali-oss-storage",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you have changed namespace to yours?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants