Credential.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. class Credential
  21. {
  22. private $dateTimeFormat = 'Y-m-d\TH:i:s\Z';
  23. private $refreshDate;
  24. private $expiredDate;
  25. private $accessKeyId;
  26. private $accessSecret;
  27. private $securityToken;
  28. function __construct($accessKeyId, $accessSecret)
  29. {
  30. $this->accessKeyId = $accessKeyId;
  31. $this->accessSecret = $accessSecret;
  32. $this->refreshDate = date($this->dateTimeFormat);
  33. }
  34. public function isExpired()
  35. {
  36. if($this->expiredDate == null)
  37. {
  38. return false;
  39. }
  40. if(strtotime($this->expiredDate)>date($this->dateTimeFormat))
  41. {
  42. return false;
  43. }
  44. return true;
  45. }
  46. public function getRefreshDate()
  47. {
  48. return $this->refreshDate;
  49. }
  50. public function getExpiredDate()
  51. {
  52. return $this->expiredDate;
  53. }
  54. public function setExpiredDate($expiredHours)
  55. {
  56. if($expiredHours>0)
  57. {
  58. return $this->expiredDate = date($this->dateTimeFormat, strtotime("+".$expiredHours." hour"));
  59. }
  60. }
  61. public function getAccessKeyId()
  62. {
  63. return $this->accessKeyId;
  64. }
  65. public function setAccessKeyId($accessKeyId)
  66. {
  67. $this->accessKeyId = $accessKeyId;
  68. }
  69. public function getAccessSecret()
  70. {
  71. return $this->accessSecret;
  72. }
  73. public function setAccessSecret($accessSecret)
  74. {
  75. $this->accessSecret = $accessSecret;
  76. }
  77. }