hotel-quickly/aws-proxy

AWS PHP库的代理

v1.5.2 2016-01-25 16:07 UTC

This package is not auto-updated.

Last update: 2024-09-25 12:31:06 UTC


README

包含代理类的库,用于AWS SDK PHP库

有关AWS SDK PHP库的文档,请参阅文档

实现的服务代理

  • S3存储服务
  • DynamoDB
  • SQS队列

用法

S3存储服务

$config = array(
  accessKeyId => xxx,
  secretAccessKeyId => xxx,
  region => 'ap-southeast-1',
  bucket => 'test-bucket' // you can modify later by calling $s3Client->setBucket('another-bucket')
);

$s3Client = new \HQ\Aws\S3Proxy($config);

// $s3FilePath is in format {bucket-name}/{item-key}
$s3Client->downloadFile($s3FilePath, $localFilePath);

// optional 3rd parameter declaring if file should be publicaly accessible (default is false)
// optional 4rd parameter declaring if file should be rewriten when exists on s3 (default is false)
$s3Client->uploadFile($sourcePath, $s3FilePath, true, false);

// determines if given file exists in s3 storage
$s3Client->isFile($s3FilePath);


$s3Client->copyFile($origFilePath, $targetFilePath, true);
$s3Client->moveFile($origFilePath, $targetFilePath);

// returns all files within specified bucket
// optional $prefix parameter specifies path for search
$s3Client->getFiles('/exceptions/');

// saves all files to specified directory
// optional second $prefix parameter to specify path in s3 storage
$s3Client->downloadAllFiles($localDirectoryPath);


$s3Client->deleteFile($filePath);

// return publicly accessible URL for given object
// optional second parameter specify how long should be URL valid
$s3Client->getObjectUrl($key);

// return whole s3 object
// optional second parameter for configuration
$s3Client->getObject($key);

DynamoDB

代理自动将PHP数组转换为DynamoDB所需格式

$config = array(
  accessKeyId => xxx,
  secretAccessKeyId => xxx,
  region => 'ap-southeast-1'
);

$dynamoDbClient = new \HQ\Aws\DynamoDbProxy($config);

// insert data
$this->dynamoDbProxy->setTableName('tableName')
	->insert(array(
		'id' => 23,
		'name' => 'Test name',
		'purpose' => 'To show how'
	));

// update data
$this->dynamoDbProxy
	->setTableName('tableName')
	->update(array('id' => 23), array(
		'name' => 'Correct name',
		'description' => 'New description'
	));

代理支持由多个值组成的键

更新时,您需要提供键值数组

$this->dynamoDbProxy
	->setTableName('tableName')
	->update(array(
		'id' => 23,
		'secondaryKey' => 'secondaryValue'
	), array(
		'name' => 'Correct name',
		'description' => 'New description'
	));

SQS队列管理

$config = array(
  accessKeyId => xxx,
  secretAccessKeyId => xxx,
  region => 'ap-southeast-1'
);

$sqsClient = new \HQ\Aws\SqsProxy($config);

// insert data
$this->sqsClient->setQeueuUrl('xxx')
	->insert(array(
		'id' => 23,
		'name' => 'Test name',
		'purpose' => 'To show how'
	));

MIT许可证(MIT)

版权所有(c)2014 Hotel Quickly Ltd.

特此授予任何人无限制地使用本软件及其相关文档文件(以下简称“软件”)的权利,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本,并允许提供软件的人士进行上述行为,前提是遵守以下条件:

上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。

本软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、特定用途的适用性和非侵权性。在任何情况下,作者或版权所有者不对任何索赔、损害或其他责任(无论因合同、侵权或其他原因而产生)负责,也不对软件或其使用或任何其他方式中的软件或其使用或其他方式产生或导致的任何损失或损害负责。