You are here

class Token in Janrain Registration 8

The token.

Hierarchy

  • class \Drupal\janrain_capture\Authentication\Token

Expanded class hierarchy of Token

File

src/Authentication/Token.php, line 8

Namespace

Drupal\janrain_capture\Authentication
View source
class Token {

  /**
   * The token itself.
   *
   * @var string
   */
  protected $token;

  /**
   * The expiration of a token.
   *
   * @var \DateTime|null
   */
  protected $expiration;

  /**
   * The token's life in seconds.
   *
   * @var int
   */
  protected $expiresIn = 0;

  /**
   * {@inheritdoc}
   */
  public function __construct(string $token) {
    $this->token = $token;
  }

  /**
   * {@inheritdoc}
   */
  public function __toString() : string {
    return $this
      ->getToken();
  }

  /**
   * {@inheritdoc}
   */
  public function getToken() : string {
    return $this->token;
  }

  /**
   * {@inheritdoc}
   */
  public function setExpiration(int $expiration) : void {
    $this->expiresIn = $expiration;
    $this->expiration = new \DateTime();
    $this->expiration
      ->setTimestamp(\Drupal::time()
      ->getRequestTime() + $expiration);
  }

  /**
   * {@inheritdoc}
   */
  public function getExpiresIn() : int {
    return $this->expiresIn;
  }

  /**
   * {@inheritdoc}
   */
  public function getExpiration() : ?\DateTime {
    return $this->expiration;
  }

  /**
   * {@inheritdoc}
   */
  public function isExpired() : bool {
    $expiration = $this
      ->getExpiration();

    // No expiration - token is permanent.
    if ($expiration === NULL) {
      return FALSE;
    }
    return $expiration
      ->getTimestamp() < \Drupal::time()
      ->getRequestTime();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Token::$expiration protected property The expiration of a token.
Token::$expiresIn protected property The token's life in seconds.
Token::$token protected property The token itself.
Token::getExpiration public function 1
Token::getExpiresIn public function
Token::getToken public function
Token::isExpired public function
Token::setExpiration public function
Token::__construct public function 1
Token::__toString public function