2017 © Pedro Peláez
 

library aws-sdk-php-zf2

Zend Framework 2 Module that allows easy integration the AWS SDK for PHP

image

aws/aws-sdk-php-zf2

Zend Framework 2 Module that allows easy integration the AWS SDK for PHP

  • Tuesday, February 13, 2018
  • by jeremeamia
  • Repository
  • 51 Watchers
  • 94 Stars
  • 364,273 Installations
  • PHP
  • 11 Dependents
  • 3 Suggesters
  • 45 Forks
  • 4 Open issues
  • 17 Versions
  • 5 % Grown

The README.md

AWS SDK ZF2 Module

Latest Stable Version Total Downloads Build Status, (*1)

This module provides a simple wrapper for the AWS SDK for PHP. It registers the AWS service builder as a service in the ZF2 service manager, making it easily accessible anywhere in your application., (*2)

Jump To: * Getting Started * Getting Help * Contributing * Related Modules * More Resources, (*3)

Getting Started

Installation

Install the module using Composer into your application's vendor directory. Add the following line to your composer.json. This will also install the AWS SDK for PHP., (*4)

If you want to use ZF3 and your PHP version >= 5.6, use, (*5)

{
    "require": {
        "aws/aws-sdk-php-zf2": "4.*"
    }
}

Otherwise,, (*6)

{
    "require": {
        "aws/aws-sdk-php-zf2": "3.*"
    }
}

If you are using ZF2 service manager < 2.7, please use the 2.0.* version., (*7)

If you are using AWS SDK v2, please use the 1.2.* version of the ZF2 module., (*8)

Configuration

Add the module name to your project's config/application.config.php or config/modules.config.php:, (*9)

return array(
    /* ... */
    'modules' => array(
        /* ... */
        'AwsModule'
    ),
    /* ... */
);

Copy and paste the aws.local.php.dist file to your config/autoload folder and customize it with your credentials and other configuration settings. Make sure to remove .dist from your file. Your aws.local.php might look something like the following:, (*10)

<?php

return [
    'aws' => [
        'credentials' => [
            'key'    => '<your-aws-access-key-id>',
            'secret' => '<your-aws-secret-access-key>',
        ]
        'region' => 'us-west-2'
    ]
];

NOTE: If you are using IAM Instance Profile credentials (also referred to as IAM Roles for instances), you can omit your key and secret parameters since they will be fetched from the Amazon EC2 instance automatically., (*11)

Usage

You can get the AWS service builder object from anywhere that the ZF2 service locator is available (e.g. controller classes). The following example instantiates an Amazon DynamoDB client and creates a table in DynamoDB., (*12)

use Aws\Sdk;

public function indexAction()
{
    $aws    = $this->getServiceLocator()->get(Sdk::class);
    $client = $aws->createDynamoDb();

    $table = 'posts';

    // Create a "posts" table
    $result = $client->createTable(array(
        'TableName' => $table,
        'KeySchema' => array(
            'HashKeyElement' => array(
                'AttributeName' => 'slug',
                'AttributeType' => 'S'
            )
        ),
        'ProvisionedThroughput' => array(
            'ReadCapacityUnits'  => 10,
            'WriteCapacityUnits' => 5
        )
    ));

    // Wait until the table is created and active
    $client->waitUntilTableExists(array('TableName' => $table));

    echo "The {$table} table has been created.\n";
}

View Helpers

The AWS SDK ZF2 Module now provides two view helpers to generate links for Amazon S3 and Amazon CloudFront resources., (*13)

Note: Starting from v2 of the AWS module, all URLs for both S3 and CloudFront are using HTTPS and this cannot be modified., (*14)

To create a S3 link in your view:, (*15)

<?php echo $this->s3Link('my-object', 'my-bucket');

The default bucket can be set globally by using the setDefaultBucket method:, (*16)

<?php
    $this->plugin('s3Link')->setDefaultBucket('my-bucket');
    echo $this->s3Link('my-object');

You can also create signed URLs for private content by passing a third argument which is the expiration date:, (*17)

<?php echo $this->s3Link('my-object', 'my-bucket', '+10 minutes');

To create CloudFront link in your view:, (*18)

<?php echo $this->cloudFrontLink('my-object', 'my-domain');

The default domain can be set globally by using the setDefaultDomain method:, (*19)

<?php
    $this->plugin('cloudFrontLink')->setDefaultDomain('my-domain');
    echo $this->cloudFrontLink('my-object');

You can also create signed URLs for private content by passing a third argument which is the expiration date:, (*20)

<?php echo $this->cloudFrontLink('my-object', 'my-bucket', time() + 60);

Filters

The AWS SDK ZF2 module provides a simple file filter that allow to directly upload to S3. The S3RenameUpload extends RenameUpload class, so please refer to its documentation for available options., (*21)

This filter only adds one option to set the bucket name (through the setBucket method, or by passing a bucket key to the filter's setOptions method)., (*22)

$request = new Request();
$files   = $request->getFiles();
// e.g., $files['my-upload']['tmp_name'] === '/tmp/php5Wx0aJ'
// e.g., $files['my-upload']['name'] === 'profile-picture.jpg'

// Fetch the filter from the Filter Plugin Manager to automatically handle dependencies
$filter = $serviceLocator->get('FilterManager')->get('S3RenameUpload');

$filter->setOptions(’[
    'bucket'    => 'my-bucket',
    'target'    => 'users/5/profile-picture.jpg',
    'overwrite' => true
]);

$filter->filter($files['my-upload']);

// File has been renamed and moved to 'my-bucket' bucket, inside the 'users/5' path

Session Save Handlers

Read the [session save handler section] (http://zf2.readthedocs.org/en/latest/modules/zend.session.save-handler.html) in the ZF2 documentation for more information., (*23)

DynamoDB

To follow the [ZF2 examples] (http://zf2.readthedocs.org/en/latest/modules/zend.session.save-handler.html), the DynamoDB session save handler might be used like this:, (*24)

use AwsModule\Session\SaveHandler\DynamoDb as DynamoDbSaveHandler;
use Laminas\Session\SessionManager;

// Assume we are in a context where $serviceLocator is a ZF2 service locator.

$saveHandler = $serviceLocator->get(DynamoDbSaveHandler::class);

$manager = new SessionManager();
$manager->setSaveHandler($saveHandler);

You will probably want to further configure the save handler, which you can do in your application. You can copy the config/aws_zf2.local.php.dist file into your project's config/autoload directory (without the .dist of course)., (*25)

See config/aws_zf2.local.php.dist and [the AWS session handler documentation] (http://docs.aws.amazon.com/aws-sdk-php-2/latest/class-Aws.DynamoDb.Session.SessionHandler.html#_factory) for more detailed configuration information., (*26)

Getting Help

Please use these community resources for getting help. We use the GitHub issues for tracking bugs and feature requests and have limited bandwidth to address them., (*27)

This SDK implements AWS service APIs. For general issues regarding the AWS services and their limitations, you may also take a look at the Amazon Web Services Discussion Forums., (*28)

Opening Issues

If you encounter a bug with aws-sdk-php-zf2 we would like to hear about it. Search the existing issues and try to make sure your problem doesn’t already exist before opening a new issue. It’s helpful if you include the version of aws-sdk-php-zf2, PHP version and OS you’re using. Please include a stack trace and reduced repro case when appropriate, too., (*29)

The GitHub issues are intended for bug reports and feature requests. For help and questions with using aws-sdk-php please make use of the resources listed in the Getting Help section. There are limited resources available for handling issues and by keeping the list of open issues lean we can respond in a timely manner., (*30)

Contributing

We work hard to provide a high-quality and useful SDK for our AWS services, and we greatly value feedback and contributions from our community. Please review our contributing guidelines before submitting any issues or pull requests to ensure we have all the necessary information to effectively respond to your bug report or contribution., (*31)

The following are some ZF2 modules that use the AWS SDK for PHP by including this module:, (*32)

  • SlmMail - Module that allow to send emails with various providers (including Amazon SES)
  • SlmQueueSqs – Module that simplifies the use of Amazon SQS

Resources

The Versions

13/02 2018

dev-master

9999999-dev

Zend Framework 2 Module that allows easy integration the AWS SDK for PHP

  Sources   Download

Apache

The Requires

 

The Development Requires

zf2 zend amazon s3 aws sqs dynamodb ec2 cloudfront

13/02 2018

v4.1.0

4.1.0.0

Zend Framework 2 Module that allows easy integration the AWS SDK for PHP

  Sources   Download

Apache

The Requires

 

The Development Requires

zf2 zend amazon s3 aws sqs dynamodb ec2 cloudfront

16/11 2017

dev-s3_url_test_updates

dev-s3_url_test_updates

Zend Framework 2 Module that allows easy integration the AWS SDK for PHP

  Sources   Download

Apache

The Requires

 

The Development Requires

zf2 zend amazon s3 aws sqs dynamodb ec2 cloudfront

14/12 2016

4.0.0

4.0.0.0

Zend Framework 2 Module that allows easy integration the AWS SDK for PHP

  Sources   Download

Apache

The Requires

 

The Development Requires

zf2 zend amazon s3 aws sqs dynamodb ec2 cloudfront

22/07 2016
22/07 2016

dev-fix/zf2-service-manger

dev-fix/zf2-service-manger

Zend Framework 2 Module that allows easy integration the AWS SDK for PHP

  Sources   Download

Apache

The Requires

 

The Development Requires

zf2 zend amazon s3 aws sqs dynamodb ec2 cloudfront

27/06 2016

2.1.0

2.1.0.0

Zend Framework 2 Module that allows easy integration the AWS SDK for PHP

  Sources   Download

Apache

The Requires

 

The Development Requires

zf2 zend amazon s3 aws sqs dynamodb ec2 cloudfront

06/08 2015

2.0.1

2.0.1.0

Zend Framework 2 Module that allows easy integration the AWS SDK for PHP

  Sources   Download

Apache

The Requires

 

The Development Requires

zf2 zend amazon s3 aws sqs dynamodb ec2 cloudfront

22/06 2015

2.0.0

2.0.0.0

Zend Framework 2 Module that allows easy integration the AWS SDK for PHP

  Sources   Download

Apache

The Requires

 

The Development Requires

zf2 zend amazon s3 aws sqs dynamodb ec2 cloudfront

09/01 2014

1.2.x-dev

1.2.9999999.9999999-dev

Zend Framework 2 Module that allows easy integration the AWS SDK for PHP

  Sources   Download

Apache

The Requires

 

The Development Requires

zf2 zend amazon s3 aws dynamodb ec2 cloudfront

09/01 2014

1.2.1

1.2.1.0

Zend Framework 2 Module that allows easy integration the AWS SDK for PHP

  Sources   Download

Apache

The Requires

 

The Development Requires

zf2 zend amazon s3 aws dynamodb ec2 cloudfront

13/12 2013

1.2.0

1.2.0.0

Zend Framework 2 Module that allows easy integration the AWS SDK for PHP

  Sources   Download

Apache

The Requires

 

The Development Requires

zf2 zend amazon s3 aws dynamodb ec2 cloudfront

01/08 2013

1.1.0

1.1.0.0

Zend Framework 2 Module that allows easy integration the AWS SDK for PHP

  Sources   Download

Apache

The Requires

 

The Development Requires

zf2 zend amazon s3 aws dynamodb ec2 cloudfront

21/06 2013

1.0.3

1.0.3.0

Zend Framework 2 Module that allows easy integration the AWS SDK for PHP

  Sources   Download

Apache

The Requires

 

The Development Requires

zf2 zend amazon s3 aws dynamodb ec2 cloudfront

04/06 2013

1.0.2

1.0.2.0

Zend Framework 2 Module that allows easy consumption of the AWS SDK for PHP

  Sources   Download

Apache

The Requires

 

The Development Requires

zf2 zend amazon s3 aws dynamodb ec2

02/04 2013

1.0.1

1.0.1.0

Zend Framework 2 Module that allows easy consumption of the AWS SDK for PHP

  Sources   Download

Apache

The Requires

 

The Development Requires

zf2 zend amazon s3 aws dynamodb ec2

01/03 2013

1.0.0

1.0.0.0

Zend Framework 2 Module that allows easy consumption of the AWS SDK for PHP

  Sources   Download

Apache

The Requires

 

zf2 zend amazon s3 aws dynamodb ec2