forked from ThePhalcons/AmazonWebServicesBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAmazonWebServicesFactory.php
More file actions
89 lines (81 loc) · 2.33 KB
/
AmazonWebServicesFactory.php
File metadata and controls
89 lines (81 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* @package AmazonWebServicesBundle
* @author Mark Badolato <mbadolato@cybernox.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace AmazonWebServicesBundle;
/**
* AmazonWebServicesBundle Factory providing requested AWS objects
*/
class AmazonWebServicesFactory
{
/**
* @var array $validServiceTypes The names of the Amazon Web Services that may be used
*/
private $validServiceTypes = array(
'AS',
'CloudFormation',
'CloudFront',
'CloudSearch',
'CloudWatch',
'DynamoDB',
'EC2',
'ELB',
'EMR',
'ElastiCache',
'ElasticBeanstalk',
'IAM',
'ImportExport',
'RDS',
'S3',
'SDB',
'SES',
'SNS',
'SQS',
'STS',
'SWF',
);
/**
* Constructor
*
* @param array $config The user defined config
*/
public function __construct(array $config)
{
if ($config['disable_auto_config'] && (! defined('AWS_DISABLE_CONFIG_AUTO_DISCOVERY'))) {
define('AWS_DISABLE_CONFIG_AUTO_DISCOVERY', TRUE);
}
if (isset($config['sdk_path']) && file_exists($config['sdk_path'])) {
require_once $config['sdk_path'];
}
}
/**
* Get an Amazon Web Service object
*
* @param AmazonWebServices $aws An AmazonWebServices Service instance
* @param string $serviceType The requested Amazon Web Service type
* @return mixed The requested Amazon Web Service Object
* @throws \RuntimeException
*/
public function get(AmazonWebServices $aws, $serviceType)
{
if (! $this->isValidServiceType($serviceType)) {
throw new \RuntimeException(sprintf('Invalid Amazon Web Service Type requested [%s]', $serviceType));
}
$serviceObject = 'Amazon' . $serviceType;
return new $serviceObject($aws->getParameters());
}
/**
* Determine if a requested Amazon Web Service is valid or not
*
* @param $type string The requested Amazon Web Service type
* @return bool
*/
private function isValidServiceType($type)
{
return (in_array($type, $this->validServiceTypes) ? true : false);
}
}