Aws.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * Copyright 2010-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. namespace Aws\Common;
  17. use Aws\Common\Facade\Facade;
  18. use Guzzle\Service\Builder\ServiceBuilder;
  19. use Guzzle\Service\Builder\ServiceBuilderLoader;
  20. /**
  21. * Base class for interacting with web service clients
  22. */
  23. class Aws extends ServiceBuilder
  24. {
  25. /**
  26. * @var string Current version of the SDK
  27. */
  28. const VERSION = '2.7.5';
  29. /**
  30. * Create a new service locator for the AWS SDK
  31. *
  32. * You can configure the service locator is four different ways:
  33. *
  34. * 1. Use the default configuration file shipped with the SDK that wires class names with service short names and
  35. * specify global parameters to add to every definition (e.g. key, secret, credentials, etc)
  36. *
  37. * 2. Use a custom configuration file that extends the default config and supplies credentials for each service.
  38. *
  39. * 3. Use a custom config file that wires services to custom short names for services.
  40. *
  41. * 4. If you are on Amazon EC2, you can use the default configuration file and not provide any credentials so that
  42. * you are using InstanceProfile credentials.
  43. *
  44. * @param array|string $config The full path to a .php or .js|.json file, or an associative array of data
  45. * to use as global parameters to pass to each service.
  46. * @param array $globalParameters Global parameters to pass to every service as it is instantiated.
  47. *
  48. * @return Aws
  49. */
  50. public static function factory($config = null, array $globalParameters = array())
  51. {
  52. if (!$config) {
  53. // If nothing is passed in, then use the default configuration file with credentials from the environment
  54. $config = self::getDefaultServiceDefinition();
  55. } elseif (is_array($config)) {
  56. // If an array was passed, then use the default configuration file with parameter overrides
  57. $globalParameters = $config;
  58. $config = self::getDefaultServiceDefinition();
  59. }
  60. $loader = new ServiceBuilderLoader();
  61. $loader->addAlias('_aws', self::getDefaultServiceDefinition())
  62. ->addAlias('_sdk1', __DIR__ . '/Resources/sdk1-config.php');
  63. return $loader->load($config, $globalParameters);
  64. }
  65. /**
  66. * Get the full path to the default service builder definition file
  67. *
  68. * @return string
  69. */
  70. public static function getDefaultServiceDefinition()
  71. {
  72. return __DIR__ . '/Resources/aws-config.php';
  73. }
  74. /**
  75. * Returns the configuration for the service builder
  76. *
  77. * @return array
  78. */
  79. public function getConfig()
  80. {
  81. return $this->builderConfig;
  82. }
  83. /**
  84. * Enables the facades for the clients defined in the service builder
  85. *
  86. * @param string|null $namespace The namespace that the facades should be mounted to. Defaults to global namespace
  87. *
  88. * @return Aws
  89. */
  90. public function enableFacades($namespace = null)
  91. {
  92. Facade::mountFacades($this, $namespace);
  93. return $this;
  94. }
  95. }