Skip to content

Commit 7e3a914

Browse files
committed
Merge pull request #72 from aws/sdk3
Updating the service provider to work with SDKv3 and Laravel 5.1
2 parents 9a966b3 + 6c30816 commit 7e3a914

File tree

8 files changed

+67
-120
lines changed

8 files changed

+67
-120
lines changed

.travis.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
language: php
22

33
php:
4-
- 5.4
5-
- 5.5
4+
- 5.5.9
65
- 5.6
76
- 7.0
87
- hhvm
@@ -13,8 +12,3 @@ install: travis_retry composer install --no-interaction --prefer-source
1312

1413
script: vendor/bin/phpunit
1514

16-
matrix:
17-
allow_failures:
18-
- php: 7.0
19-
- php: hhvm
20-
fast_finish: true

README.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@
66
[![Total Downloads](https://img.shields.io/packagist/dt/aws/aws-sdk-php-laravel.svg)](https://packagist.org/packages/aws/aws-sdk-php-laravel)
77
[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/aws/aws-sdk-php?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
88

9-
A simple [Laravel 5](http://laravel.com/) service provider for making it easier to include the official [AWS SDK for PHP](https://github.com/aws/aws-sdk-php) into your Laravel application.
9+
This is a simple [Laravel](http://laravel.com/) service provider for making it easy to include the official
10+
[AWS SDK for PHP](https://github.com/aws/aws-sdk-php) in your Laravel and Lumen applications.
1011

11-
_(Looking for the Laravel 4 service provider? It's still available in the [1.0 branch](https://github.com/aws/aws-sdk-php-laravel/tree/1.0).)_
12+
The master branch of this repository and this README are for version 3.x of the service provider, which is implemented
13+
to work with Version 3 of the AWS SDK for PHP and Laravel 5.1+.
14+
15+
Past Versions:
16+
17+
* [2.0 branch](https://github.com/aws/aws-sdk-php-laravel/tree/2.0) - For Laravel 5.0 and Version 2 of the AWS SDK for PHP
18+
* [1.0 branch](https://github.com/aws/aws-sdk-php-laravel/tree/1.0) - For Laravel 4.x and Version 2 of the AWS SDK for PHP
1219

1320
## Installation
1421

@@ -18,7 +25,7 @@ The AWS Service Provider can be installed via [Composer](http://getcomposer.org)
1825
```json
1926
{
2027
"require": {
21-
"aws/aws-sdk-php-laravel": "~2.0"
28+
"aws/aws-sdk-php-laravel": "~3.0"
2229
}
2330
}
2431
```
@@ -54,8 +61,7 @@ By default, the package uses the following environment variables to auto-configu
5461
```
5562
AWS_ACCESS_KEY_ID
5663
AWS_SECRET_ACCESS_KEY
57-
AWS_REGION // default = us-east-1
58-
AWS_CONFIG_FILE // default = null
64+
AWS_REGION (default = us-east-1)
5965
```
6066

6167
To customize the configuration file, publish the package configuration using Artisan.
@@ -68,13 +74,23 @@ Update your settings in the generated `app/config/aws.php` configuration file.
6874

6975
```php
7076
return [
71-
'key' => 'YOUR_AWS_ACCESS_KEY_ID',
72-
'secret' => 'YOUR_AWS_SECRET_KEY',
73-
'region' => 'us-east-1',
74-
'config_file' => null,
77+
'credentials' => [
78+
'key' => 'YOUR_AWS_ACCESS_KEY_ID',
79+
'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY',
80+
],
81+
'region' => 'us-west-2',
82+
'version' => 'latest',
83+
84+
// You can override settings for specific services
85+
'Ses' => [
86+
'region' => 'us-east-1',
87+
],
7588
];
7689
```
7790

91+
Learn more about [configuring the SDK](http://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/configuration.html) on
92+
the SDK's User Guide.
93+
7894
## Usage
7995

8096
In order to use the AWS SDK for PHP within your app, you need to retrieve it from the [Laravel IoC

composer.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@
1212
}
1313
],
1414
"require": {
15-
"php": ">=5.4.0",
16-
"aws/aws-sdk-php": "~2.4",
17-
"illuminate/support": "~5.0"
15+
"php": ">=5.5.9",
16+
"aws/aws-sdk-php": "~3.0",
17+
"illuminate/support": "~5.1"
1818
},
1919
"require-dev": {
20-
"laravel/framework": "~5.0",
20+
"laravel/framework": "~5.1",
2121
"phpunit/phpunit": "~4.0"
2222
},
2323
"autoload": {
2424
"psr-4": { "Aws\\Laravel\\": "src/" }
25+
},
26+
"autoload-dev": {
27+
"psr-4": { "Aws\\Laravel\\Test\\": "tests/" }
2528
}
2629
}

config/aws.php

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,21 @@
44

55
/*
66
|--------------------------------------------------------------------------
7-
| Your AWS Credentials
7+
| AWS SDK Configuration
88
|--------------------------------------------------------------------------
99
|
10-
| In order to communicate with an AWS service, you must provide your AWS
11-
| credentials including your AWS Access Key ID and AWS Secret Access Key.
12-
|
13-
| To use credentials from your credentials file or environment or to use
14-
| IAM Instance Profile credentials, please remove these config settings from
15-
| your config or make sure they are null. For more information, see:
16-
| http://docs.aws.amazon.com/aws-sdk-php-2/guide/latest/configuration.html
17-
|
18-
*/
19-
'key' => env('AWS_ACCESS_KEY_ID'),
20-
'secret' => env('AWS_SECRET_ACCESS_KEY'),
21-
22-
/*
23-
|--------------------------------------------------------------------------
24-
| AWS Region
25-
|--------------------------------------------------------------------------
26-
|
27-
| Many AWS services are available in multiple regions. You should specify
28-
| the AWS region you would like to use, but please remember that not every
29-
| service is available in every region. To see what regions are available,
30-
| see: http://docs.aws.amazon.com/general/latest/gr/rande.html
10+
| The configuration options set in this file will be passed directly to the
11+
| `Aws\Sdk` object, from which all client objects are created. The minimum
12+
| required options are declared here, but the full set of possible options
13+
| are documented at:
14+
| http://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/configuration.html
3115
|
3216
*/
17+
'credentials' => [
18+
'key' => env('AWS_ACCESS_KEY_ID'),
19+
'secret' => env('AWS_SECRET_ACCESS_KEY'),
20+
],
3321
'region' => env('AWS_REGION', 'us-east-1'),
34-
35-
/*
36-
|--------------------------------------------------------------------------
37-
| AWS Config File Location
38-
|--------------------------------------------------------------------------
39-
|
40-
| Instead of specifying your credentials and region here, you can specify
41-
| the location of an AWS SDK for PHP config file to use. These files provide
42-
| more granular control over what credentials and regions you are using for
43-
| each service. If you specify a filepath for this configuration setting,
44-
| the others in this file will be ignored. See the SDK user guide for more
45-
| information: http://docs.aws.amazon.com/aws-sdk-php-2/guide/latest/configuration.html#using-a-custom-configuration-file
46-
|
47-
*/
48-
'config_file' => env('AWS_CONFIG_FILE'),
22+
'version' => 'latest',
4923

5024
];

src/AwsFacade.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<?php namespace Aws\Laravel;
22

3-
use Aws\Common\Client\AwsClientInterface;
3+
use Aws\AwsClientInterface;
44
use Illuminate\Support\Facades\Facade;
55

66
/**
77
* Facade for the AWS service
88
*
9-
* @method static AwsClientInterface get($name, $throwAway = false) Get a client from the service builder
9+
* @method static AwsClientInterface createClient($name, array $args = []) Get a client from the service builder.
1010
*/
11-
class AwsFacade extends Facade {
11+
class AwsFacade extends Facade
12+
{
1213

1314
/**
1415
* Get the registered name of the component.

src/AwsServiceProvider.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php namespace Aws\Laravel;
22

3-
use Aws\Common\Aws;
3+
use Aws\Sdk;
44
use Illuminate\Support\ServiceProvider;
55

66
/**
77
* AWS SDK for PHP service provider for Laravel applications
88
*/
9-
class AwsServiceProvider extends ServiceProvider {
9+
class AwsServiceProvider extends ServiceProvider
10+
{
1011

1112
/**
1213
* Indicates if loading of the provider is deferred.
@@ -39,15 +40,10 @@ public function boot()
3940
public function register()
4041
{
4142
$this->app->singleton('aws', function ($app) {
42-
$config = $app['config']->get('aws');
43-
if (isset($config['config_file'])) {
44-
$config = $config['config_file'];
45-
}
46-
47-
return Aws::factory($config);
43+
return new Sdk($app['config']->get('aws'));
4844
});
4945

50-
$this->app->alias('aws', 'Aws\Common\Aws');
46+
$this->app->alias('aws', 'Aws\Sdk');
5147
}
5248

5349
/**
@@ -57,7 +53,7 @@ public function register()
5753
*/
5854
public function provides()
5955
{
60-
return ['aws', 'Aws\Common\Aws'];
56+
return ['aws', 'Aws\Sdk'];
6157
}
6258

6359
}

tests/Aws/Laravel/Test/test_services.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

tests/Aws/Laravel/Test/AwsServiceProviderTest.php renamed to tests/AwsServiceProviderTest.php

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
use Illuminate\Config\Repository;
66
use Illuminate\Foundation\Application;
77

8-
class AwsServiceProviderTest extends \PHPUnit_Framework_TestCase {
8+
class AwsServiceProviderTest extends \PHPUnit_Framework_TestCase
9+
{
910

1011
public function testFacadeCanBeResolvedToServiceInstance()
1112
{
@@ -15,44 +16,26 @@ public function testFacadeCanBeResolvedToServiceInstance()
1516
// Mount facades
1617
AWS::setFacadeApplication($app);
1718

18-
// Get an instance of a client (S3) via its facade
19-
$s3 = AWS::get('s3');
19+
// Get an instance of a client (S3) via the facade.
20+
$s3 = AWS::createClient('S3');
2021
$this->assertInstanceOf('Aws\S3\S3Client', $s3);
2122
}
2223

23-
public function testRegisterAwsServiceProviderWithConfigFile()
24-
{
25-
$app = $this->setupApplication();
26-
$this->setupServiceProvider($app);
27-
28-
// Simulate global config; specify config file
29-
$app['config']->set('aws', [
30-
'config_file' => __DIR__ . '/test_services.json'
31-
]);
32-
33-
// Get an instance of a client (S3)
34-
/** @var $s3 \Aws\S3\S3Client */
35-
$s3 = $app['aws']->get('s3');
36-
$this->assertInstanceOf('Aws\S3\S3Client', $s3);
37-
38-
// Verify that the client received the credentials from the global config
39-
$this->assertEquals('change_me', $s3->getCredentials()->getAccessKeyId());
40-
$this->assertEquals('change_me', $s3->getCredentials()->getSecretKey());
41-
}
42-
4324
public function testRegisterAwsServiceProviderWithPackageConfigAndEnv()
4425
{
4526
$app = $this->setupApplication();
4627
$this->setupServiceProvider($app);
4728

48-
// Get an instance of a client (S3)
29+
// Get an instance of a client (S3).
4930
/** @var $s3 \Aws\S3\S3Client */
50-
$s3 = $app['aws']->get('s3');
31+
$s3 = $app['aws']->createClient('S3');
5132
$this->assertInstanceOf('Aws\S3\S3Client', $s3);
5233

53-
// Verify that the client received the credentials from the package config
54-
$this->assertEquals('foo', $s3->getCredentials()->getAccessKeyId());
55-
$this->assertEquals('bar', $s3->getCredentials()->getSecretKey());
34+
// Verify that the client received the credentials from the package config.
35+
/** @var \Aws\Credentials\CredentialsInterface $credentials */
36+
$credentials = $s3->getCredentials()->wait();
37+
$this->assertEquals('foo', $credentials->getAccessKeyId());
38+
$this->assertEquals('bar', $credentials->getSecretKey());
5639
$this->assertEquals('baz', $s3->getRegion());
5740
}
5841

@@ -68,7 +51,7 @@ public function testServiceNameIsProvided()
6851
*/
6952
private function setupApplication()
7053
{
71-
// Create the application such that the config is loaded
54+
// Create the application such that the config is loaded.
7255
$app = new Application();
7356
$app->setBasePath(sys_get_temp_dir());
7457
$app->instance('config', new Repository());
@@ -83,7 +66,7 @@ private function setupApplication()
8366
*/
8467
private function setupServiceProvider(Application $app)
8568
{
86-
// Create and register the provider
69+
// Create and register the provider.
8770
$provider = new AwsServiceProvider($app);
8871
$app->register($provider);
8972
$provider->boot();

0 commit comments

Comments
 (0)