Skip to content

Commit 404371b

Browse files
committed
Updating the service provider to work with SDKv3 and Laravel 5.1
1 parent 9a966b3 commit 404371b

File tree

7 files changed

+38
-110
lines changed

7 files changed

+38
-110
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

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
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": {

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: 5 additions & 9 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
/**

tests/Aws/Laravel/Test/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();

tests/Aws/Laravel/Test/test_services.json

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

0 commit comments

Comments
 (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