ALIOSS::__construct PHP Метод

__construct() публичный Метод

默认构造函数
С версии: 2011-11-08
Автор: [email protected]
public __construct ( $access_id = null, string $access_key = null, string $hostname = null )
$access_key string (Optional)
$hostname string (Optional)
    public function __construct($access_id = null, $access_key = null, $hostname = null)
    {
        //验证access_id,access_key
        if (!$access_id && !defined('OSS_ACCESS_ID')) {
            throw new OSS_Exception(NOT_SET_OSS_ACCESS_ID);
        }
        if (!$access_key && !defined('OSS_ACCESS_KEY')) {
            throw new OSS_Exception(NOT_SET_OSS_ACCESS_KEY);
        }
        if ($access_id && $access_key) {
            $this->access_id = $access_id;
            $this->access_key = $access_key;
        } elseif (defined('OSS_ACCESS_ID') && defined('OSS_ACCESS_KEY')) {
            $this->access_id = OSS_ACCESS_ID;
            $this->access_key = OSS_ACCESS_KEY;
        } else {
            throw new OSS_Exception(NOT_SET_OSS_ACCESS_ID_AND_ACCESS_KEY);
        }
        //校验access_id&access_key
        if (empty($this->access_id) || empty($this->access_key)) {
            throw new OSS_Exception(OSS_ACCESS_ID_OR_ACCESS_KEY_EMPTY);
        }
        //校验hostname
        if (null === $hostname) {
            $this->hostname = self::DEFAULT_OSS_HOST;
        } else {
            $this->hostname = $hostname;
        }
    }

Usage Example

Пример #1
0
 public function __construct($ak, $sk, $host, $bucket, $ns = '', $cdn = '')
 {
     parent::__construct($ak, $sk, $host);
     $this->bucket = $bucket;
     $this->host = $host;
     $this->ns = $ns;
     $this->cdn = $cdn;
 }