22
33namespace Magium \AwsFactory ;
44
5- use Aws \ApiGateway \ApiGatewayClient ;
6- use Aws \AutoScaling \AutoScalingClient ;
75use Aws \AwsClient ;
8- use Aws \CloudDirectory \CloudDirectoryClient ;
9- use Aws \CloudFormation \CloudFormationClient ;
10- use Aws \CloudFront \CloudFrontClient ;
11- use Aws \CloudSearch \CloudSearchClient ;
12- use Aws \CloudWatch \CloudWatchClient ;
13- use Aws \CodeDeploy \CodeDeployClient ;
14- use Aws \CognitoIdentity \CognitoIdentityClient ;
15- use Aws \CognitoIdentityProvider \CognitoIdentityProviderClient ;
16- use Aws \DirectoryService \DirectoryServiceClient ;
17- use Aws \DynamoDb \DynamoDbClient ;
18- use Aws \Ec2 \Ec2Client ;
19- use Aws \Ecr \EcrClient ;
20- use Aws \Ecs \EcsClient ;
21- use Aws \Efs \EfsClient ;
22- use Aws \ElastiCache \ElastiCacheClient ;
23- use Aws \ElasticLoadBalancing \ElasticLoadBalancingClient ;
24- use Aws \ElasticLoadBalancingV2 \ElasticLoadBalancingV2Client ;
25- use Aws \ElasticsearchService \ElasticsearchServiceClient ;
26- use Aws \Iam \IamClient ;
27- use Aws \Rds \RdsClient ;
28- use Aws \Route53 \Route53Client ;
29- use Aws \S3 \S3Client ;
30- use Aws \Ses \SesClient ;
31- use Aws \Sms \SmsClient ;
32- use Aws \Sns \SnsClient ;
33- use Aws \Sqs \SqsClient ;
34- use Aws \Sts \StsClient ;
356use Magium \Configuration \Config \Repository \ConfigInterface ;
367
378class AwsFactory
@@ -47,37 +18,7 @@ class AwsFactory
4718 * @var array
4819 */
4920
50- private static $ versions = [
51- Ec2Client::class => '2016-11-15 ' ,
52- ApiGatewayClient::class => '2015-07-09 ' ,
53- AutoScalingClient::class => '2011-01-01 ' ,
54- CloudDirectoryClient::class => '2016-05-10 ' ,
55- CloudFormationClient::class => '2010-05-15 ' ,
56- CloudFrontClient::class => '2017-03-25 ' ,
57- CloudSearchClient::class => '2013-01-01 ' ,
58- CloudWatchClient::class => '2010-08-01 ' ,
59- CodeDeployClient::class => '2014-10-06 ' ,
60- CognitoIdentityClient::class => '2014-06-30 ' ,
61- CognitoIdentityProviderClient::class => '2016-04-18 ' ,
62- DirectoryServiceClient::class => '2015-04-16 ' ,
63- DynamoDbClient::class => '2012-08-10 ' ,
64- EcsClient::class => '2014-11-13 ' ,
65- EcrClient::class => '2015-09-21 ' ,
66- EfsClient::class => '2015-02-01 ' ,
67- ElastiCacheClient::class => '2015-02-02 ' ,
68- ElasticLoadBalancingClient::class => '2012-06-01 ' ,
69- ElasticLoadBalancingV2Client::class => '2015-12-01 ' ,
70- ElasticsearchServiceClient::class => '2015-01-01 ' ,
71- IamClient::class => '2010-05-08 ' ,
72- RdsClient::class => '2014-10-31 ' ,
73- Route53Client::class => '2013-04-01 ' ,
74- S3Client::class => '2006-03-01 ' ,
75- SesClient::class => '2010-12-01 ' ,
76- SmsClient::class => '2016-10-24 ' ,
77- SnsClient::class => '2010-03-31 ' ,
78- SqsClient::class => '2012-11-05 ' ,
79- StsClient::class => '2011-06-15 '
80- ];
21+ private static $ versions = [];
8122
8223 private $ config ;
8324 private static $ self ;
@@ -88,22 +29,46 @@ public function __construct(ConfigInterface $config)
8829 self ::$ self = $ this ;
8930 }
9031
91- public static function setVersion ($ class, $ version )
32+ private static function getDataDir ($ class )
9233 {
93- self ::$ versions [$ class ] = $ version ;
34+ // We use the class to navigate our way to the data directory
35+ $ classParts = explode ('\\' , $ class );
36+ array_pop ($ classParts );
37+ $ reflection = new \ReflectionClass ($ class );
38+ $ dataDirName = dirname ($ reflection ->getFileName ());
39+ $ parts = explode (DIRECTORY_SEPARATOR , $ dataDirName );
40+ do {
41+ $ cwd = array_pop ($ parts );
42+ } while (count ($ parts ) > 0 && $ cwd != 'aws-sdk-php ' );
43+
44+ return implode (DIRECTORY_SEPARATOR , $ parts )
45+ . DIRECTORY_SEPARATOR
46+ . implode (DIRECTORY_SEPARATOR , ['aws-sdk-php ' , 'src ' , 'data ' ]);
9447 }
9548
9649 public static function getVersionFor ($ class )
9750 {
98- if (!isset (self ::$ versions [$ class ])) {
99- throw new UnknownVersionException ('Could not find version for ' . $ class );
51+ $ namespace = explode ('\\' , $ class );
52+ array_pop ($ namespace ); // Get rid of the class name
53+ $ namespace = array_pop ($ namespace ); // Get the highest level namespace
54+
55+ if (!isset (self ::$ versions [$ namespace ])) {
56+ $ manifestFile = self ::getDataDir ($ class ) . DIRECTORY_SEPARATOR . 'manifest.json.php ' ;
57+ $ manifest = include $ manifestFile ;
58+ foreach ($ manifest as $ entry ) {
59+ self ::$ versions [$ entry ['namespace ' ]] = $ entry ['versions ' ]['latest ' ];
60+ }
61+ if (!isset (self ::$ versions [$ namespace ])) {
62+ throw new UnknownVersionException ('Could not find version for ' . $ class );
63+ }
10064 }
101- return self ::$ versions [$ class ];
65+ return self ::$ versions [$ namespace ];
10266 }
10367
10468
10569 /**
106- * @param AwsClient $class
70+ * @param string $class
71+ * @return AwsClient
10772 */
10873
10974 public function factory ($ class = AwsClient::class)
0 commit comments