Proxy for AWS PHP library
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
.gitignore
LICENSE
README.md
composer.json

README.md

Aws Proxy Library

Library with proxy classes for AWS SDK PHP library.

For documentation of AWS SDK PHP library see documentation.

Implemented proxies for services

  • S3 storage service
  • DynamoDB
  • SQS queue

Usage

S3 Storage service

$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

Proxy automatically converts php arrays to format required by 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'
	));

Proxy supports primary key consisting with multiple values.

For update, you need to provide array of values for primary key

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

SQS queue management

$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'
	));

The MIT License (MIT)

Copyright (c) 2014 Hotel Quickly Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.