Skip to content

Commit 79c87cc

Browse files
committed
making the service provider Laravel 5 compatible
1 parent 5047f26 commit 79c87cc

File tree

5 files changed

+60
-41
lines changed

5 files changed

+60
-41
lines changed

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Latest Stable Version](https://poser.pugx.org/aws/aws-sdk-php-laravel/v/stable.png)](https://packagist.org/packages/aws/aws-sdk-php-laravel)
44
[![Total Downloads](https://poser.pugx.org/aws/aws-sdk-php-laravel/downloads.png)](https://packagist.org/packages/aws/aws-sdk-php-laravel)
55

6-
A simple [Laravel 4](http://laravel.com/) service provider for including the [AWS SDK for PHP](https://github.com/aws/aws-sdk-php).
6+
A simple [Laravel 5](http://laravel.com/) service provider for including the [AWS SDK for PHP](https://github.com/aws/aws-sdk-php).
77

88
## Installation
99

@@ -13,7 +13,7 @@ The AWS Service Provider can be installed via [Composer](http://getcomposer.org)
1313
```json
1414
{
1515
"require": {
16-
"aws/aws-sdk-php-laravel": "1.*"
16+
"aws/aws-sdk-php-laravel": "~2.0"
1717
}
1818
}
1919
```
@@ -27,21 +27,29 @@ php composer.phar update
2727

2828
To use the AWS Service Provider, you must register the provider when bootstrapping your Laravel application.
2929

30-
Publish the package configuration using Artisan.
30+
By default, the package uses the following environment variables to auto-configure the plugin without modification:
31+
```
32+
AWS_ACCESS_KEY_ID
33+
AWS_SECRET_ACCESS_KEY
34+
AWS_REGION // default = us-east-1
35+
AWS_CONFIG_FILE // default = null
36+
```
37+
38+
To customize the configuration file, publish the package configuration using Artisan.
3139

3240
```sh
33-
php artisan config:publish aws/aws-sdk-php-laravel
41+
php artisan vendor:publish
3442
```
3543

36-
Update your settings in the generated `app/config/packages/aws/aws-sdk-php-laravel` configuration file.
44+
Update your settings in the generated `app/config/aws.php` configuration file.
3745

3846
```php
39-
return array(
47+
return [
4048
'key' => 'YOUR_AWS_ACCESS_KEY_ID',
4149
'secret' => 'YOUR_AWS_SECRET_KEY',
4250
'region' => 'us-east-1',
4351
'config_file' => null,
44-
);
52+
];
4553
```
4654

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

composer.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "aws/aws-sdk-php-laravel",
33
"homepage": "http://aws.amazon.com/sdkforphp2",
4-
"description": "A simple Laravel 4 service provider for including the AWS SDK for PHP.",
5-
"keywords": ["laravel","laravel 4","aws","amazon","sdk","s3","ec2","dynamodb"],
4+
"description": "A simple Laravel 5 service provider for including the AWS SDK for PHP.",
5+
"keywords": ["laravel", "laravel 5", "aws", "amazon", "sdk", "s3", "ec2", "dynamodb"],
66
"type":"library",
77
"license":"Apache-2.0",
88
"authors":[
@@ -14,13 +14,12 @@
1414
"require": {
1515
"php": ">=5.3.3",
1616
"aws/aws-sdk-php": "~2.2",
17-
"illuminate/foundation": "4.*",
18-
"illuminate/support": "4.*"
17+
"illuminate/support": "~5.0"
1918
},
2019
"require-dev": {
21-
"phpunit/phpunit": "3.7.*"
20+
"phpunit/phpunit": "~4.0"
2221
},
2322
"autoload": {
24-
"psr-0": { "Aws\\Laravel": "src/" }
23+
"psr-4": { "Aws\\Laravel\\": "src/" }
2524
}
2625
}

src/config/config.php renamed to config/config.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* permissions and limitations under the License.
1515
*/
1616

17-
return array(
17+
return [
1818

1919
/*
2020
|--------------------------------------------------------------------------
@@ -30,8 +30,8 @@
3030
| http://docs.aws.amazon.com/aws-sdk-php-2/guide/latest/configuration.html
3131
|
3232
*/
33-
'key' => null, // Your AWS Access Key ID
34-
'secret' => null, // Your AWS Secret Access Key
33+
'key' => env('AWS_ACCESS_KEY_ID'),
34+
'secret' => env('AWS_SECRET_ACCESS_KEY'),
3535

3636
/*
3737
|--------------------------------------------------------------------------
@@ -46,7 +46,7 @@
4646
| eu-west-1, sa-east-1, ap-northeast-1, ap-southeast-1, ap-southeast-2
4747
|
4848
*/
49-
'region' => 'us-east-1',
49+
'region' => env('AWS_REGION', 'us-east-1'),
5050

5151
/*
5252
|--------------------------------------------------------------------------
@@ -61,6 +61,6 @@
6161
| information: http://docs.aws.amazon.com/aws-sdk-php-2/guide/latest/configuration.html#using-a-custom-configuration-file
6262
|
6363
*/
64-
'config_file' => null,
64+
'config_file' => env('AWS_CONFIG_FILE'),
6565

66-
);
66+
];
File renamed without changes.

src/Aws/Laravel/AwsServiceProvider.php renamed to src/AwsServiceProvider.php

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,31 @@
2828
*/
2929
class AwsServiceProvider extends ServiceProvider
3030
{
31-
const VERSION = '1.1.0';
31+
32+
const VERSION = '2.0.0';
33+
34+
/**
35+
* Indicates if loading of the provider is deferred.
36+
*
37+
* @var bool
38+
*/
39+
protected $defer = true;
40+
41+
/**
42+
* Bootstrap the configuration
43+
*
44+
* @return void
45+
*/
46+
public function boot()
47+
{
48+
$config = realpath(__DIR__ . '/../config/config.php');
49+
50+
$this->mergeConfigFrom($config, 'aws');
51+
52+
$this->publishes([
53+
$config => config_path('aws.php'),
54+
], 'config');
55+
}
3256

3357
/**
3458
* Register the service provider.
@@ -37,38 +61,26 @@ class AwsServiceProvider extends ServiceProvider
3761
*/
3862
public function register()
3963
{
40-
$this->app['aws'] = $this->app->share(function ($app) {
41-
// Retrieve the config
42-
$config = $app['config']['aws'] ?: $app['config']['aws::config'];
43-
if (isset($config['config_file'])) {
44-
$config = $config['config_file'];
45-
}
64+
$this->app->singleton('aws', function ($app) {
4665

4766
// Instantiate the AWS service builder
48-
$aws = Aws::factory($config);
67+
$aws = Aws::factory($app['config']->get('aws'));
4968

5069
// Attach an event listener that will append the Laravel and module version numbers to the user agent string
5170
$aws->getEventDispatcher()->addListener('service_builder.create_client', function (Event $event) {
5271
$clientConfig = $event['client']->getConfig();
53-
$commandParams = $clientConfig->get(Client::COMMAND_PARAMS) ?: array();
54-
$userAgentSuffix = 'Laravel/' . Application::VERSION . ' L4MOD/' . AwsServiceProvider::VERSION;
55-
$clientConfig->set(Client::COMMAND_PARAMS, array_merge_recursive($commandParams, array(
72+
$commandParams = $clientConfig->get(Client::COMMAND_PARAMS) ?: [];
73+
$userAgentSuffix = 'Laravel/' . Application::VERSION . ' L5MOD/' . AwsServiceProvider::VERSION;
74+
75+
$clientConfig->set(Client::COMMAND_PARAMS, array_merge_recursive($commandParams, [
5676
UserAgentListener::OPTION => $userAgentSuffix,
57-
)));
77+
]));
5878
});
5979

6080
return $aws;
6181
});
62-
}
6382

64-
/**
65-
* Bootstrap the application events.
66-
*
67-
* @return void
68-
*/
69-
public function boot()
70-
{
71-
$this->package('aws/aws-sdk-php-laravel', 'aws');
83+
$this->app->alias('aws', 'Aws\Common\Aws');
7284
}
7385

7486
/**
@@ -78,6 +90,6 @@ public function boot()
7890
*/
7991
public function provides()
8092
{
81-
return array('aws');
93+
return ['aws'];
8294
}
8395
}

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