本文整理汇总了PHP中Aws\S3\S3Client::doesBucketExist方法的典型用法代码示例。如果您正苦于以下问题:PHP S3Client::doesBucketExist方法的具体用法?PHP S3Client::doesBucketExist怎么用?PHP S3Client::doesBucketExist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aws\S3\S3Client
的用法示例。
在下文中一共展示了S3Client::doesBucketExist方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: buildBucket
/**
* Attempt to build a bucket (if it doesn't already exist).
*
* @param string $bucketName
*/
protected function buildBucket($bucketName)
{
if (!$this->s3Client->doesBucketExist($bucketName, true)) {
$this->s3Client->createBucket(['ACL' => $this->attachedFile->ACL, 'Bucket' => $bucketName, 'LocationConstraint' => $this->attachedFile->region]);
}
$this->bucketExists = true;
}
示例3: updateContainerProperties
/**
* Update a container with some properties
*
* @param string $container
* @param array $properties
*
* @throws DfException
* @return void
*/
public function updateContainerProperties($container, $properties = [])
{
$this->checkConnection();
try {
if ($this->blobConn->doesBucketExist($container)) {
throw new \Exception("No container named '{$container}'");
}
} catch (\Exception $ex) {
throw new DfException("Failed to update container '{$container}': " . $ex->getMessage());
}
}
示例4: testDeleteTrails
/**
* Execute the DescribeTrails and DeleteTrail operations
*
* @example Aws\CloudTrail\CloudTrailClient::deleteTrail
* @example Aws\CloudTrail\CloudTrailClient::getDescribeTrailsIterator
* @depends testStopLogging
*/
public function testDeleteTrails($bucket)
{
$client = $this->cloudtrail;
// @begin
// List and delete all of the trails
$trails = $client->getDescribeTrailsIterator();
foreach ($trails as $trail) {
$client->deleteTrail(array('Name' => $trail['Name']));
echo "Deleted trail {$trail['Name']}.\n";
}
// @end
$this->assertEquals("Deleted trail test-trail.\n", $this->getActualOutput());
// Clean up test bucket
sleep(5);
if ($this->s3->doesBucketExist($bucket)) {
$this->s3->clearBucket($bucket);
$this->s3->deleteBucket(array('Bucket' => $bucket));
}
}
示例5: saveImage
protected function saveImage(array $file, $subdirectory = '')
{
$s3 = new S3Client(['version' => 'latest', 'region' => 'eu-west-1']);
$subdirectory = trim($subdirectory, '/');
list($name, $extension) = explode('.', trim($file['name'], '/'));
$filename = md5((string) rand()) . '.' . $extension;
$directory = self::$public_image_directory . '/' . $subdirectory . '/';
$bucket_name = 'comp3013';
if (!$s3->doesBucketExist($bucket_name)) {
echo 'Error, bucket didnt exist';
exit(0);
}
while ($s3->doesObjectExist($bucket_name, $directory . $filename)) {
$filename = md5((string) rand()) . '.' . $extension;
}
$parameters = ['ContentType' => $file['type'], 'Bucket' => $bucket_name, 'Key' => $directory . $filename, 'SourceFile' => $file['tmp_name']];
print_r($parameters);
$s3->putObject($parameters);
$s3->waitUntil('ObjectExists', ['Bucket' => $bucket_name, 'Key' => $directory . $filename]);
//exit(0);
return 'http://comp3013.s3-website-eu-west-1.amazonaws.com/' . $directory . $filename;
}
示例6: 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;
}
示例7: validateBucketExists
/**
* Validate that a bucket exists.
*
* Since bucket names are global across all of S3, we can't determine if a
* bucket doesn't exist at all, or if it exists but is owned by another S3
* account.
*
* @param string $bucket
* The name of the bucket to test.
* @param \Aws\S3\S3Client $client
* The S3Client to use.
*
* @throws S3ConnectValidationException
* Thrown when credentials are invalid or the bucket does not exist.
*/
public static function validateBucketExists($bucket, \Aws\S3\S3Client $client)
{
if (!$client->doesBucketExist($bucket, FALSE)) {
throw new S3ConnectValidationException('The S3 access credentials are invalid or the bucket does not exist.');
}
}
示例8: doesBucketExist
/**
* Determines whether or not a bucket exists by name
*
* @param string $bucket The name of the bucket
* @param bool $accept403 Set to true if 403s are acceptable
* @param array $params Additional options to add to the executed command
*
* @return bool
*/
public function doesBucketExist($bucket, $accept403 = true, array $params = [])
{
return $this->instance->doesBucketExist($bucket, $accept403, $params);
}
示例9: exist
/**
* exist
*
* @param boolean $accept403
* @param array $options
*
* @return boolean
*/
public function exist($accept403 = true, array $options = array())
{
return $this->client->doesBucketExist($this->name, $accept403, $options);
}
示例10: verifyBucketExists
protected function verifyBucketExists(S3Client $s3Client)
{
if (!strlen($this->bucketName)) {
throw new Exception("[S3Sync::verifyBucketExists] Unable to verify S3 bucket: bucket name not set");
}
if (!$s3Client->doesBucketExist($this->bucketName)) {
$result = $s3Client->createBucket(array('ACL' => 'private', 'Bucket' => $this->bucketName));
$s3Client->waitUntilBucketExists(array('Bucket' => $this->bucketName));
if (!$s3Client->doesBucketExist($this->bucketName)) {
throw new Exception('[S3Sync::verifyBucketExists] Unable to create S3 bucket ' . $this->bucketName);
}
}
return true;
}
示例11: _createBucket
/**
* _createBucket
* Create the bucket, if not exists, for Amazon S3
*
* @param string $bucketName name of the bucket.
* @return void
*/
protected function _createBucket($bucketName)
{
//TODO: migliorare con un ritorno di qualcosa...
if (!$this->_s3Client->doesBucketExist($bucketName)) {
$this->_s3Client->createBucket(array('Bucket' => $bucketName));
}
// Poll the bucket until it is accessible
$this->_s3Client->waitUntil('BucketExists', array('Bucket' => $bucketName));
}
示例12: doesBucketExist
public function doesBucketExist($bucket)
{
return $this->s3->doesBucketExist($bucket);
}