Skip to content

cryptixcoder/aws-sdk-php-laravel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS Service Provider for Laravel 4

A simple Laravel 4 service provider for including the AWS SDK for PHP.

Installation

The AWS Service Provider can be installed via Composer by requiring the aws/aws-sdk-php-laravel package and setting the minimum-stability to dev (required for Laravel 4) in your project's composer.json.

{
    "require": {
        "laravel/framework": "4.0.*",
        "aws/aws-sdk-php-laravel": "1.*"
    },
    "minimum-stability": "dev"
}

Usage

To use the AWS Service Provider, you must register the provider when bootstrapping your Laravel application. There are essentially two ways to do this.

1. Use Laravel Configuration

Create a new app/config/aws.php configuration file with the following options:

return array(
    'key'    => '<your-aws-access-key-id>',
    'secret' => '<your-aws-secret-access-key>',
    'region' => Aws\Common\Enum\Region::US_WEST_2,
);

Find the providers key in app/config/app.php and register the AWS Service Provider.

    'providers' => array(
        // ...
        'Aws\Laravel\AwsServiceProvider',
    )

Find the aliases key in app/config/app.php and add the AWS Facade alias.

    'aliases' => array(
        // ...
        'AWS' => 'Aws\Laravel\AwsFacade',
    )

2. Manual Instantiation

You can also register the provider and configuration options at runtime. This could be done in your global bootstrapping process in app/start/global.php.

use Aws\Common\Enum\Region;
use Aws\Laravel\AwsServiceProvider;
use Illuminate\Foundation\Application;

// Instantiate a new application. This is normally done by the Laravel framework and the instance is available in
// `app/start/global.php` for you to use.
$app = new Application;

// Register the AWS service provider and provide your configuration
$app->register(new AwsServiceProvider($app), array(
    'config' => array(
        'aws' => array(
            'key'    => '<your-aws-access-key-id>',
            'secret' => '<your-aws-secret-access-key>',
            'region' => Region::US_WEST_2,
        ),
    ),
));

You can alternatively specify the path to an AWS config file (see AWS SDK for PHP for details about how to format this type of file).

$app->register(new AwsServiceProvider($app), array('config' => array('aws' => '/path/to/aws/config/file.php')));

Either way, the value of $app['config']['aws'] is passed directly into Aws\Common\Aws::factory().

Retrieving and Using a Service Client

In order to use the SDK from within your app, you need to retrieve it from the Laravel IoC Container. The following example uses the Amazon S3 client to upload a file.

$s3 = App::make('aws')->get('s3');
$s3->putObject(array(
    'Bucket'     => '<your-bucket>',
    'Key'        => '<the-name-of-your-object>',
    'SourceFile' => '/path/to/the/file/you/are/uploading.ext',
));

If the AWS Facade is registered within the aliases section of the application configuration, you can use the following more expressive method.

$s3 = AWS::get('s3');
$s3->putObject(array(
    'Bucket'     => '<your-bucket>',
    'Key'        => '<the-name-of-your-object>',
    'SourceFile' => '/path/to/the/file/you/are/uploading.ext',
));

Links

About

A Laravel 5 (and 4) service provider for the AWS SDK for PHP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy