Abstract.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service
  17. * @subpackage Amazon
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. require_once 'Zend/Service/Abstract.php';
  23. /**
  24. * Abstract Amazon class that handles the credentials for any of the Web Services that
  25. * Amazon offers
  26. *
  27. * @category Zend
  28. * @package Zend_Service
  29. * @subpackage Amazon
  30. * @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. abstract class Zend_Service_Amazon_Abstract extends Zend_Service_Abstract
  34. {
  35. /**
  36. * @var string Amazon Access Key
  37. */
  38. protected static $_defaultAccessKey = null;
  39. /**
  40. * @var string Amazon Secret Key
  41. */
  42. protected static $_defaultSecretKey = null;
  43. /**
  44. * @var string Amazon Secret Key
  45. */
  46. protected $_secretKey;
  47. /**
  48. * @var string Amazon Access Key
  49. */
  50. protected $_accessKey;
  51. /**
  52. * Set the keys to use when accessing SQS.
  53. *
  54. * @param string $access_key Set the default Access Key
  55. * @param string $secret_key Set the default Secret Key
  56. * @return void
  57. */
  58. public static function setKeys($accessKey, $secretKey)
  59. {
  60. self::$_defaultAccessKey = $accessKey;
  61. self::$_defaultSecretKey = $secretKey;
  62. }
  63. /**
  64. * Create Amazon Sqs client.
  65. *
  66. * @param string $access_key Override the default Access Key
  67. * @param string $secret_key Override the default Secret Key
  68. * @return void
  69. */
  70. public function __construct($accessKey=null, $secretKey=null)
  71. {
  72. if(!$accessKey) {
  73. $accessKey = self::$_defaultAccessKey;
  74. }
  75. if(!$secretKey) {
  76. $secretKey = self::$_defaultSecretKey;
  77. }
  78. if(!$accessKey || !$secretKey) {
  79. require_once 'Zend/Service/Amazon/Exception.php';
  80. throw new Zend_Service_Amazon_Exception("AWS keys were not supplied");
  81. }
  82. $this->_accessKey = $accessKey;
  83. $this->_secretKey = $secretKey;
  84. }
  85. /**
  86. * Method to fetch the Access Key
  87. *
  88. * @return string
  89. */
  90. protected function _getAccessKey()
  91. {
  92. return $this->_accessKey;
  93. }
  94. /**
  95. * Method to fetch the Secret AWS Key
  96. *
  97. * @return string
  98. */
  99. protected function _getSecretKey()
  100. {
  101. return $this->_secretKey;
  102. }
  103. }