本文整理匯總了PHP中Aws\S3\S3Client::isValidBucketName方法的典型用法代碼示例。如果您正苦於以下問題:PHP S3Client::isValidBucketName方法的具體用法?PHP S3Client::isValidBucketName怎麽用?PHP S3Client::isValidBucketName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Aws\S3\S3Client
的用法示例。
在下文中一共展示了S3Client::isValidBucketName方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: __construct
public function __construct($params)
{
if (!isset($params['key']) || !isset($params['secret']) || !isset($params['bucket'])) {
throw new \Exception("Access Key, Secret and Bucket have to be configured.");
}
$this->id = 'amazon::' . $params['key'] . md5($params['secret']);
$this->bucket = $params['bucket'];
$scheme = $params['use_ssl'] === 'false' ? 'http' : 'https';
$this->test = isset($params['test']);
$this->timeout = !isset($params['timeout']) ? 15 : $params['timeout'];
$params['region'] = !isset($params['region']) || $params['region'] === '' ? 'eu-west-1' : $params['region'];
$params['hostname'] = !isset($params['hostname']) || $params['hostname'] === '' ? 's3.amazonaws.com' : $params['hostname'];
if (!isset($params['port']) || $params['port'] === '') {
$params['port'] = $params['use_ssl'] === 'false' ? 80 : 443;
}
$base_url = $scheme . '://' . $params['hostname'] . ':' . $params['port'] . '/';
$this->connection = S3Client::factory(array('key' => $params['key'], 'secret' => $params['secret'], 'base_url' => $base_url, 'region' => $params['region']));
if (!$this->connection->isValidBucketName($this->bucket)) {
throw new \Exception("The configured bucket name is invalid.");
}
if (!$this->connection->doesBucketExist($this->bucket)) {
try {
$result = $this->connection->createBucket(array('Bucket' => $this->bucket));
$this->connection->waitUntilBucketExists(array('Bucket' => $this->bucket, 'waiter.interval' => 1, 'waiter.max_attempts' => 15));
$this->testTimeout();
} catch (S3Exception $e) {
\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
throw new \Exception("Creation of bucket failed.");
}
}
if (!$this->file_exists('.')) {
$result = $this->connection->putObject(array('Bucket' => $this->bucket, 'Key' => '.', 'Body' => '', 'ContentType' => 'httpd/unix-directory', 'ContentLength' => 0));
$this->testTimeout();
}
}
示例2: getConnection
/**
* Returns the connection
*
* @return S3Client connected client
* @throws \Exception if connection could not be made
*/
public function getConnection() {
if (!is_null($this->connection)) {
return $this->connection;
}
$scheme = ($this->params['use_ssl'] === 'false') ? 'http' : 'https';
$base_url = $scheme . '://' . $this->params['hostname'] . ':' . $this->params['port'] . '/';
$this->connection = S3Client::factory(array(
'key' => $this->params['key'],
'secret' => $this->params['secret'],
'base_url' => $base_url,
'region' => $this->params['region']
));
if (!$this->connection->isValidBucketName($this->bucket)) {
throw new \Exception("The configured bucket name is invalid.");
}
if (!$this->connection->doesBucketExist($this->bucket)) {
try {
$this->connection->createBucket(array(
'Bucket' => $this->bucket
));
$this->connection->waitUntilBucketExists(array(
'Bucket' => $this->bucket,
'waiter.interval' => 1,
'waiter.max_attempts' => 15
));
$this->testTimeout();
} catch (S3Exception $e) {
\OCP\Util::logException('files_external', $e);
throw new \Exception('Creation of bucket failed. '.$e->getMessage());
}
}
return $this->connection;
}
示例3: isValidName
/**
* isValidName
*
* @return boolean
*/
public function isValidName()
{
return S3Client::isValidBucketName($this->name);
}