1. Go to this page and download the library: Download rtek/aws-gen library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rtek / aws-gen example snippets
namespace App;
use Rtek\AwsGen\Generator;
use Rtek\AwsGen\Writer\DirWriter;
$gen = new Generator('App\\AwsGen'); //generate classes to the 'App\AwsGen' namespace
$gen->addService('s3', '2006-03-01'); //add the s3 service, version optional
DirWriter::create('src') //set the root directory to write the files
->setPsr4Prefix('App\\') //optionally set a PSR4 prefix
->write($gen); //writes App\AwsGen\S3 to src/AwsGen/S3
namespace App;
use App\AwsGen\S3 as S3;
$config = [
'credentials' => [
'key' => '***',
'secret' => '***',
],
'region' => 'us-east-1',
];
//generated client extends `\Aws\S3Client` with the same config as SDK except
//for `version` which is overridden by the specified generation version
$client = new S3\S3Client($config);
//the operation input create(...) contains S3\PutObjectRequest::create($bucket, $key = 'foo.txt')
->Body('bar baz')->ContentType('text/plain')
);
//`\ArrayAccess` works as usual since output classes extend `\Aws\Result`
echo "Created object {$key} with ETag {$output['ETag']}\n";
//supports setting values via array by constructor
$input = new S3\GetObjectRequest([
'Bucket' => $bucket,
'Key' => $key,
]);
$output = $client->getObject($input);
echo "The object has a body of: {$output->Body()}\n";
//you can bypass AwsGen classes by passing the array argument to the client
$result = $client->getObject([
'Bucket' => $bucket,
'Key' => $key,
]);
echo "The object still has a body of: {$result['Body']}\n";
//`\IteratorAggregate` is implemented for iterable properties
$output = $client->listObjectsV2(S3\ListObjectsV2Request::create($bucket));
foreach ($output->Contents() as $object) {
$client->deleteObject(S3\DeleteObjectRequest::create($bucket, $object->getKey()));
}