Skip to content

Commit cd48c7b

Browse files
committed
Merge remote-tracking branch 'dayle/facade-support' into facade-support
2 parents 99d5efe + 0d9d51e commit cd48c7b

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ Find the `providers` key in `app/config/app.php` and register the AWS Service Pr
4444
)
4545
```
4646

47+
Find the `aliases` key in `app/config/app.php` and add the AWS Facade alias.
48+
49+
```php
50+
'aliases' => array(
51+
// ...
52+
'AWS' => 'Aws\Laravel\AwsFacade',
53+
)
54+
```
55+
56+
4757
### 2. Manual Instantiation
4858

4959
You can also register the provider and configuration options at runtime. This could be done in your global bootstrapping
@@ -93,6 +103,18 @@ $s3->putObject(array(
93103
));
94104
```
95105

106+
If the AWS Facade is registered within the `aliases` section of the application configuration, you can use
107+
the following more expressive method.
108+
109+
```php
110+
$s3 = AWS::get('s3');
111+
$s3->putObject(array(
112+
'Bucket' => '<your-bucket>',
113+
'Key' => '<the-name-of-your-object>',
114+
'SourceFile' => '/path/to/the/file/you/are/uploading.ext',
115+
));
116+
```
117+
96118
## Links
97119

98120
* [AWS SDK for PHP on Github](http://github.com/aws/aws-sdk-php)

src/Aws/Laravel/AwsFacade.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License").
6+
* You may not use this file except in compliance with the License.
7+
* A copy of the License is located at
8+
*
9+
* http://aws.amazon.com/apache2.0
10+
*
11+
* or in the "license" file accompanying this file. This file is distributed
12+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
* express or implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
17+
namespace Aws\Laravel;
18+
19+
use Illuminate\Support\Facades\Facade;
20+
21+
/**
22+
* AWS SDK for PHP service provider for Laravel applications
23+
*/
24+
class AwsFacade extends Facade
25+
{
26+
/**
27+
* Get the registered name of the component.
28+
*
29+
* @return string
30+
*/
31+
protected static function getFacadeAccessor() { return 'aws'; }
32+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License").
6+
* You may not use this file except in compliance with the License.
7+
* A copy of the License is located at
8+
*
9+
* http://aws.amazon.com/apache2.0
10+
*
11+
* or in the "license" file accompanying this file. This file is distributed
12+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
* express or implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
17+
namespace Aws\Laravel\Tests;
18+
19+
use Aws\Laravel\AwsFacade as AWS;
20+
use Aws\Laravel\AwsServiceProvider;
21+
use Illuminate\Foundation\Application;
22+
23+
/**
24+
* AwsFacade test cases
25+
*/
26+
class AwsFacadeTest extends \PHPUnit_Framework_TestCase
27+
{
28+
public function testFacadeCanBeResolvedToServiceInstance()
29+
{
30+
// Setup the Laravel app and AWS service provider
31+
$app = new Application();
32+
$provider = new AwsServiceProvider($app);
33+
$app->register($provider, array(
34+
'config' => array(
35+
'aws' => array(
36+
'key' => 'your-aws-access-key-id',
37+
'secret' => 'your-aws-secret-access-key',
38+
),
39+
),
40+
));
41+
$provider->boot();
42+
43+
AWS::setFacadeApplication($app);
44+
45+
// Get an instance of a client (S3) to use for testing
46+
/** @var $s3 \Aws\S3\S3Client */
47+
$s3 = AWS::get('s3');
48+
$this->assertInstanceOf('Aws\S3\S3Client', $s3);
49+
}
50+
}

0 commit comments

Comments
 (0)