Credentials.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace OSS\Credentials;
  3. use OSS\Core\OssException;
  4. /**
  5. * Basic implementation of the OSS Credentials that allows callers to
  6. * pass in the OSS Access Key and OSS Secret Access Key in the constructor.
  7. */
  8. class Credentials
  9. {
  10. private $key;
  11. private $secret;
  12. private $token;
  13. /**
  14. * Constructor a new BasicOSSCredentials object, with the specified OSS
  15. * access key and OSS secret key
  16. *
  17. * @param string $key OSS access key ID
  18. * @param string $secret OSS secret access key
  19. * @param string $token Security token to use
  20. */
  21. public function __construct($key, $secret, $token = null)
  22. {
  23. if (empty($key)) {
  24. throw new OssException("access key id is empty");
  25. }
  26. if (empty($secret)) {
  27. throw new OssException("access key secret is empty");
  28. }
  29. $this->key = trim($key);
  30. $this->secret = trim($secret);
  31. $this->token = $token;
  32. }
  33. /**
  34. * @return string
  35. */
  36. public function getAccessKeyId()
  37. {
  38. return $this->key;
  39. }
  40. /**
  41. * @return string
  42. */
  43. public function getAccessKeySecret()
  44. {
  45. return $this->secret;
  46. }
  47. /**
  48. * @return string|null
  49. */
  50. public function getSecurityToken()
  51. {
  52. return $this->token;
  53. }
  54. }