Skip to content

Commit 9a56759

Browse files
AlexStansfieldcjyclaire
authored andcommitted
Added Cilex and Pimple support (#15)
* Added Cilex and Pimple support * Version Bump to 2.1.0
1 parent bfa73d1 commit 9a56759

File tree

7 files changed

+229
-13
lines changed

7 files changed

+229
-13
lines changed

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@
1818
},
1919
"autoload": {
2020
"psr-4": {
21-
"Aws\\Silex\\": "src/"
21+
"Aws\\Cilex\\": "src/Cilex",
22+
"Aws\\Pimple\\": "src/Pimple",
23+
"Aws\\Silex\\": "src/Silex"
2224
}
2325
},
2426
"autoload-dev": {
2527
"psr-4": {
26-
"Aws\\Silex\\": "tests/"
28+
"Aws\\Cilex\\": "tests/Cilex",
29+
"Aws\\Pimple\\": "tests/Pimple",
30+
"Aws\\Silex\\": "tests/Silex"
2731
}
2832
},
2933
"extra": {
@@ -32,6 +36,8 @@
3236
}
3337
},
3438
"require-dev": {
39+
"pimple/pimple": "~1.0",
40+
"cilex/cilex": "~1.0",
3541
"phpunit/phpunit": "~4.7",
3642
"squizlabs/php_codesniffer": "^2.3"
3743
}

src/Cilex/AwsServiceProvider.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright 2012-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\Cilex;
18+
19+
use Aws\Pimple\AwsServiceProvider as PimpleAwsServiceProvider;
20+
use Cilex\Application;
21+
use Cilex\ServiceProviderInterface;
22+
23+
/**
24+
* AWS SDK for PHP service provider for Cilex applications
25+
*/
26+
class AwsServiceProvider implements ServiceProviderInterface
27+
{
28+
public function register(Application $app)
29+
{
30+
$pimpleServiceProvider = new PimpleAwsServiceProvider;
31+
$pimpleServiceProvider->register($app, 'Cilex', Application::VERSION);
32+
}
33+
}

src/Pimple/AwsServiceProvider.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright 2012-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\Pimple;
18+
19+
use Aws\Sdk;
20+
use Guzzle\Common\Event;
21+
use Guzzle\Service\Client;
22+
23+
/**
24+
* AWS SDK for PHP service provider for Pimple based applications
25+
*/
26+
class AwsServiceProvider
27+
{
28+
const VERSION = '2.1.0';
29+
30+
public function register(\Pimple $app, $type = 'Pimple', $version = '0.0.0')
31+
{
32+
$app['aws'] = $app->share(function (\Pimple $app) use ($type, $version) {
33+
$config = isset($app['aws.config']) ? $app['aws.config'] : [];
34+
return new Sdk($config + ['ua_append' => [
35+
$type . '/' . $version,
36+
'SXMOD/' . self::VERSION,
37+
]]);
38+
});
39+
}
40+
}

src/AwsServiceProvider.php renamed to src/Silex/AwsServiceProvider.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace Aws\Silex;
1818

19-
use Aws\Sdk;
19+
use Aws\Pimple\AwsServiceProvider as PimpleAwsServiceProvider;
2020
use Silex\Application;
2121
use Silex\ServiceProviderInterface;
2222

@@ -25,18 +25,10 @@
2525
*/
2626
class AwsServiceProvider implements ServiceProviderInterface
2727
{
28-
const VERSION = '2.0.2';
29-
3028
public function register(Application $app)
3129
{
32-
$app['aws'] = $app->share(function (Application $app) {
33-
$config = isset($app['aws.config']) ? $app['aws.config'] : [];
34-
35-
return new Sdk($config + ['ua_append' => [
36-
'Silex/' . Application::VERSION,
37-
'SXMOD/' . self::VERSION,
38-
]]);
39-
});
30+
$pimpleServiceProvider = new PimpleAwsServiceProvider;
31+
$pimpleServiceProvider->register($app, 'Silex', Application::VERSION);
4032
}
4133

4234
public function boot(Application $app)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Copyright 2012-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\Cilex\Tests;
18+
19+
use Aws\Cilex\AwsServiceProvider;
20+
use Cilex\Application;
21+
22+
/**
23+
* AwsServiceProvider test cases
24+
*/
25+
class AwsServiceProviderTest extends \PHPUnit_Framework_TestCase
26+
{
27+
public function testRegisterAwsServiceProvider()
28+
{
29+
// Setup the Cilex app and AWS service provider
30+
$app = new Application('test');
31+
$provider = new AwsServiceProvider();
32+
$app->register($provider, array(
33+
'aws.config' => array(
34+
'version' => '2006-03-01',
35+
'region' => 'us-east-1',
36+
'credentials' => [
37+
'key' => 'fake-aws-key',
38+
'secret' => 'fake-aws-secret',
39+
],
40+
)
41+
));
42+
43+
// Get an instance of a client (S3) to use for testing
44+
$s3 = $app['aws']->createS3();
45+
46+
// Verify that the app and clients created by the SDK receive the provided credentials
47+
$this->assertEquals('2006-03-01', $app['aws.config']['version']);
48+
$this->assertEquals('us-east-1', $app['aws.config']['region']);
49+
$this->assertEquals('2006-03-01', $s3->getApi()->getApiVersion());
50+
$this->assertEquals('us-east-1', $s3->getRegion());
51+
}
52+
53+
/**
54+
* @expectedException \InvalidArgumentException
55+
*/
56+
public function testNoConfigProvided()
57+
{
58+
// Setup the Cilex app and AWS service provider
59+
$app = new Application('test');
60+
$provider = new AwsServiceProvider();
61+
$app->register($provider, array(
62+
'aws.config' => array(
63+
'credentials' => [
64+
'key' => 'fake-aws-key',
65+
'secret' => 'fake-aws-secret',
66+
],
67+
)
68+
));
69+
70+
// Instantiate a client, which should trigger an exception for missing configs
71+
$s3 = $app['aws']->createS3();
72+
}
73+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright 2012-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\Pimple\Tests;
18+
19+
use Aws\Pimple\AwsServiceProvider;
20+
21+
/**
22+
* AwsServiceProvider test cases
23+
*/
24+
class AwsServiceProviderTest extends \PHPUnit_Framework_TestCase
25+
{
26+
public function testRegisterAwsServiceProvider()
27+
{
28+
// Setup the Pimple app and AWS service provider
29+
$app = new \Pimple(array(
30+
'aws.config' => array(
31+
'version' => '2006-03-01',
32+
'region' => 'us-east-1',
33+
'credentials' => [
34+
'key' => 'fake-aws-key',
35+
'secret' => 'fake-aws-secret',
36+
],
37+
)
38+
));
39+
$provider = new AwsServiceProvider();
40+
$provider->register($app);
41+
42+
// Get an instance of a client (S3) to use for testing
43+
$s3 = $app['aws']->createS3();
44+
45+
// Verify that the app and clients created by the SDK receive the provided credentials
46+
$this->assertEquals('2006-03-01', $app['aws.config']['version']);
47+
$this->assertEquals('us-east-1', $app['aws.config']['region']);
48+
$this->assertEquals('2006-03-01', $s3->getApi()->getApiVersion());
49+
$this->assertEquals('us-east-1', $s3->getRegion());
50+
}
51+
52+
/**
53+
* @expectedException \InvalidArgumentException
54+
*/
55+
public function testNoConfigProvided()
56+
{
57+
// Setup the Pimple app and AWS service provider
58+
$app = new \Pimple(array(
59+
'aws.config' => array(
60+
'credentials' => [
61+
'key' => 'fake-aws-key',
62+
'secret' => 'fake-aws-secret',
63+
],
64+
)
65+
));
66+
$provider = new AwsServiceProvider();
67+
$provider->register($app);
68+
69+
// Instantiate a client, which should trigger an exception for missing configs
70+
$s3 = $app['aws']->createS3();
71+
}
72+
}

0 commit comments

Comments
 (0)