1<?php 2 3namespace OAuth\Common\Token; 4 5/** 6 * Base token implementation for any OAuth version. 7 */ 8abstract class AbstractToken implements TokenInterface 9{ 10 /** 11 * @var string 12 */ 13 protected $accessToken; 14 15 /** 16 * @var string 17 */ 18 protected $refreshToken; 19 20 /** 21 * @var int 22 */ 23 protected $endOfLife; 24 25 /** 26 * @var array 27 */ 28 protected $extraParams = array(); 29 30 /** 31 * @param string $accessToken 32 * @param string $refreshToken 33 * @param int $lifetime 34 * @param array $extraParams 35 */ 36 public function __construct($accessToken = null, $refreshToken = null, $lifetime = null, $extraParams = array()) 37 { 38 $this->accessToken = $accessToken; 39 $this->refreshToken = $refreshToken; 40 $this->setLifetime($lifetime); 41 $this->extraParams = $extraParams; 42 } 43 44 /** 45 * @return string 46 */ 47 public function getAccessToken() 48 { 49 return $this->accessToken; 50 } 51 52 /** 53 * @return string 54 */ 55 public function getRefreshToken() 56 { 57 return $this->refreshToken; 58 } 59 60 /** 61 * @return int 62 */ 63 public function getEndOfLife() 64 { 65 return $this->endOfLife; 66 } 67 68 /** 69 * @param array $extraParams 70 */ 71 public function setExtraParams(array $extraParams) 72 { 73 $this->extraParams = $extraParams; 74 } 75 76 /** 77 * @return array 78 */ 79 public function getExtraParams() 80 { 81 return $this->extraParams; 82 } 83 84 /** 85 * @param string $accessToken 86 */ 87 public function setAccessToken($accessToken) 88 { 89 $this->accessToken = $accessToken; 90 } 91 92 /** 93 * @param int $endOfLife 94 */ 95 public function setEndOfLife($endOfLife) 96 { 97 $this->endOfLife = $endOfLife; 98 } 99 100 /** 101 * @param int $lifetime 102 */ 103 public function setLifetime($lifetime) 104 { 105 if (0 === $lifetime || static::EOL_NEVER_EXPIRES === $lifetime) { 106 $this->endOfLife = static::EOL_NEVER_EXPIRES; 107 } elseif (null !== $lifetime) { 108 $this->endOfLife = intval($lifetime) + time(); 109 } else { 110 $this->endOfLife = static::EOL_UNKNOWN; 111 } 112 } 113 114 /** 115 * @param string $refreshToken 116 */ 117 public function setRefreshToken($refreshToken) 118 { 119 $this->refreshToken = $refreshToken; 120 } 121} 122