选择语言 :

 Module_Storage_Driver_Swift::__construct

初始化对象

配置可以是一个数值也可以是一个字符串,例如

 $config = array
 (
     'driver'        => 'Swift',
     'driver_config' => 'https://username:password@localhost:8080/v2.0?region=test&tenant_name=default&warehouses=mytest&prefix=test',
 );
 $storage = new Storage($config);

数值形式

 $config = array
 (
     'driver' => 'Swift',
     'driver_config' => array
     (
         'host'              => 'localhost',     // 服务器IP或域名
         'user'              => 'username',      // 用户名
         'pass'              => 'password',      // 密码(key)
         'warehouses'        => 'mytest',        // 储存仓库,类似数据库的库,可不设置,默认为 default
         // 以下是token接口为v2.0的时候必须
         'tenant_name'       => 'default',       // Tenant 名称
         'region'            => 'test',          // Region
         // 以下为可选参数
         'https'             => true,            // true || false , 默认 false
         'token_api_version' => 'v2.0',          // 版本,不设置则默认 v2.0
         'port'              => 8080,            // 端口,默认http 为 80,https 为 443
         'prefix'            => 'test',          // key的前缀,默认为空
     ),
 );
 $storage = new Storage($config);
null Module_Storage_Driver_Swift::__construct( [ string $config_name = string(7) "default" ] )

参数列表

参数 类型 描述 默认值
$config_name string | array $config_name 配置名或数组 string(7) "default"
File: ./modules/storage/driver/swift.class.php
public function __construct($config_name = 'default')
{
    if (is_array($config_name))
    {
        $config = $config_name;
        $config_name = md5(serialize($config_name));
    }
    else if (is_string($config_name) && strpos($config_name, '://')!==false)
    {
        $config = parse_url($config_name);
        if (isset($config['query']) && $config['query'])
        {
            parse_str($config['query'], $query);
            if ($query && is_array($query))
            {
                $config += $query;
            }
        }

        $path = trim($config['path'], '/');
        if ($path)
        {
            $config['token_api_version'] = $path;
            unset($path);
        }


        $config['https'] = $config['scheme']=='https'?true:false;
    }
    else
    {
        $config = Core::config('storage/swift.' . $config_name);

        if (is_string($config_name) && strpos($config_name, '://')!==false)
        {
            $config = parse_url($config_name);
        }
    }

    $this->account  = $config['user'];
    $this->key      = $config['pass'];
    $this->host     = $config['host'];

    if (isset($config['https']) && $config['https'])
    {
        $this->protocol = 'https';
    }

    if (isset($config['token_api_version']) && $config['token_api_version'])
    {
        $this->token_api_version = $config['token_api_version'];
    }

    if (isset($config['tenant_name']) && $config['tenant_name'])
    {
        $this->tenant_name = $config['tenant_name'];
    }

    if (isset($config['region']) && $config['region'])
    {
        $this->region = $config['region'];
    }

    if (isset($config['warehouses']) && $config['warehouses'])
    {
        $this->warehouses = $config['warehouses'];
    }

    if (!isset($config['port']) || !$config['port'])
    {
        $this->port = $this->protocol=='https'?443:80;
    }

    if (isset($config['prefix']) && $config['prefix'])
    {
        $this->set_prefix($config['prefix']);
    }

    if (!$this->host)
    {
        throw new Exception(__('The storage swift config does not exist'));
    }

    $this->config = $config;

    # 增加自动关闭连接列队
    Core::add_close_connect_class('Storage_Driver_Swift');
}