src/Qcloud/Cos/BucketStyleListener.php
public function onCommandAfterPrepare(Event $event) {

        $command = $event['command'];
        $bucket = $command['Bucket'];
        $request = $command->getRequest();
        if ($command->getName() == 'ListBuckets')
        {
            if ($this->ipport != null) {
                $request->setHost($this->ipport);
                $request->setHeader('Host', 'service.cos.myqcloud.com');
            } else if ($this->endpoint != null) {
                $request->setHost($this->endpoint);
                $request->setHeader('Host', 'service.cos.myqcloud.com');
            }
            else {

                $request->setHost('service.cos.myqcloud.com');
            }
            return ;
        }
        if ($key = $command['Key']) {
            // Modify the command Key to account for the {/Key*} explosion into an array
            if (is_array($key)) {
                $command['Key'] = $key = implode('/', $key);
            }
        }
        $request->setHeader('Date', gmdate('D, d M Y H:i:s T'));
        $request->setPath(preg_replace("#^/{$bucket}#", '', $request->getPath()));

        if ($this->appId != null && endWith($bucket,'-'.$this->appId) == False)
        {
            $bucket = $bucket.'-'.$this->appId;
        }
//        $request->setPath(urldecode($request->getPath()));
        $request->getParams()->set('bucket', $bucket)->set('key', $key);

        $realHost = $bucket. '.' . $request->getHost();
        if($this->ipport != null) {
            $request->setHost($this->ipport);
            $request->setHeader('Host', $realHost);
        } else {
            if($this->endpoint != null) {
                $tmp = $bucket. '.' . $this->endpoint;
                $request->setHost($tmp);
            } else {
                $request->setHost($realHost);
            }
        }
        if (!$bucket) {
            $request->getParams()->set('cos.resource', '/');
        } else {
            // Bucket style needs a trailing slash
            $request->getParams()->set(
                'cos.resource',
                '/' . rawurlencode($bucket) . ($key ? ('/' . Client::encodeKey($key)) : '/')
            );
        }
    }
public function onCommandAfterPrepare(Event $event) {

        $command = $event['command'];
        $bucket = $command['Bucket'];
        $request = $command->getRequest();
        if ($command->getName() == 'ListBuckets')
        {
            if ($this->ipport != null) {
                $request->setHost($this->ipport);
                $request->setHeader('Host', 'service.cos.myqcloud.com');
            } else if ($this->endpoint != null) {
                $request->setHost($this->endpoint);
                $request->setHeader('Host', 'service.cos.myqcloud.com');
            }
            else {

                $request->setHost('service.cos.myqcloud.com');
            }
            return ;
        }
        if ($key = $command['Key']) {
            // Modify the command Key to account for the {/Key*} explosion into an array
            if (is_array($key)) {
                $command['Key'] = $key = implode('/', $key);
            }
        }
        $request->setHeader('Date', gmdate('D, d M Y H:i:s T'));
        $request->setPath(preg_replace("#^/{$bucket}#", '', $request->getPath()));

        if ($this->appId != null && endWith($bucket,'-'.$this->appId) == False)
        {
            $bucket = $bucket.'-'.$this->appId;
        }
//        $request->setPath(urldecode($request->getPath()));
        $request->getParams()->set('bucket', $bucket)->set('key', $key);

        $realHost = $bucket. '.' . $request->getHost();
        if($this->ipport != null) {
            $request->setHost($this->ipport);
            $request->setHeader('Host', $realHost);
        } else {
            if($this->endpoint != null) {
                $tmp = $bucket. '.' . $this->endpoint;
                $request->setHost($tmp);
            } else {
                $request->setHost($realHost);
            }
        }
        if (!$bucket) {
            $request->getParams()->set('cos.resource', '/');
        } else {
            // Bucket style needs a trailing slash
            $request->getParams()->set(
                'cos.resource',
                '/' . rawurlencode($bucket) . ($key ? ('/' . Client::encodeKey($key)) : '/')
            );
        }
    }
public function onCommandAfterPrepare ( Event $ event ) { $ command = $ event [ 'command' ] ; $ bucket = $ command [ 'Bucket' ] ; $ request = $ command -> getRequest ( ) ; if ( $ command -> getName ( ) == 'ListBuckets' ) { if ( $ this -> ipport != null ) { $ request -> setHost ( $ this -> ipport ) ; $ request -> setHeader ( 'Host' , 'service.cos.myqcloud.com' ) ; } else if ( $ this -> endpoint != null ) { $ request -> setHost ( $ this -> endpoint ) ; $ request -> setHeader ( 'Host' , 'service.cos.myqcloud.com' ) ; } else { $ request -> setHost ( 'service.cos.myqcloud.com' ) ; } return ; } if ( $ key = $ command [ 'Key' ] ) { // Modify the command Key to account for the {/Key*} explosion into an array if ( is_array ( $ key ) ) { $ command [ 'Key' ] = $ key = implode ( '/' , $ key ) ; } } $ request -> setHeader ( 'Date' , gmdate ( 'D, d M Y H:i:s T' ) ) ; $ request -> setPath ( preg_replace ( "#^/{$bucket}#" , '' , $ request -> getPath ( ) ) ) ; if ( $ this -> appId != null && endWith ( $ bucket , '-' . $ this -> appId ) == False ) { $ bucket = $ bucket . '-' . $ this -> appId ; } //        $request->setPath(urldecode($request->getPath())); $ request -> getParams ( ) -> set ( 'bucket' , $ bucket ) -> set ( 'key' , $ key ) ; $ realHost = $ bucket . '.' . $ request -> getHost ( ) ; if ( $ this -> ipport != null ) { $ request -> setHost ( $ this -> ipport ) ; $ request -> setHeader ( 'Host' , $ realHost ) ; } else { if ( $ this -> endpoint != null ) { $ tmp = $ bucket . '.' . $ this -> endpoint ; $ request -> setHost ( $ tmp ) ; } else { $ request -> setHost ( $ realHost ) ; } } if ( ! $ bucket ) { $ request -> getParams ( ) -> set ( 'cos.resource' , '/' ) ; } else { // Bucket style needs a trailing slash $ request -> getParams ( ) -> set ( 'cos.resource' , '/' . rawurlencode ( $ bucket ) . ( $ key ? ( '/' . Client :: encodeKey ( $ key ) ) : '/' ) ) ; } }
Change from path style to host style.
@param Event $event Event emitted.
Change from path style to host style .