选择语言 :

 Module_Storage_Driver_Swift::get_token

获取token

string Module_Storage_Driver_Swift::get_token( )
返回值
  • string
File: ./modules/storage/driver/swift.class.php
protected function get_token()
{
    # 缓存key
    $key = 'swift_storage_auth_' . $this->host . '_' . $this->account;

    # 获取缓存token
    $token = Cache::instance()->get($key);

    if ($token)
    {
        $this->token       = $token[0];
        $this->storage_url = $token[1];
        $expires           = $token[2];

        if (time()<$expires)
        {
            $need_get = false;

            $h = parse_url($this->storage_url);

            $this->storage_host     = $h['host'];
            $this->storage_path     = $h['path'];
            $this->storage_protocol = $h['scheme'];
            $this->storage_port     = $h['port']?$h['port']:$h['scheme']=='https'?443:80;

            if (IS_DEBUG)Core::debug()->info($this->token, 'Swift Token From Cache');
        }
        else
        {
            $need_get = true;
        }
    }
    else
    {
        $need_get = true;
    }

    if ($need_get)
    {
        if ($this->token_api_version=='v1.0')
        {
            # 获取token
            $this->get_real_token_v1();
        }
        elseif ($this->token_api_version=='v2.0')
        {
            $this->get_real_token_v2();
        }

        # 设置缓存
        Cache::instance()->set($key, array($this->token, $this->storage_url, time()+$this->token_timeout), $this->token_timeout);
    }
}