<?php
 declare(strict_types=1); namespace Shopify\Auth; use Exception; use DateTime; use Shopify\Context; use Shopify\Utils; class Session { private $scope = null; private $expires = null; private $accessToken = null; private $onlineAccessInfo = null; public function __construct( private string $id, private string $shop, private bool $isOnline, private string $state ) { $this->id = $id; $this->shop = Utils::sanitizeShopDomain($shop); $this->isOnline = $isOnline; $this->state = $state; } public function getId(): string { return $this->id; } public function getShop(): string { return $this->shop; } public function getState(): string { return $this->state; } public function getScope() { return $this->scope; } public function getExpires() { return $this->expires; } public function isOnline(): bool { return $this->isOnline; } public function getAccessToken() { return $this->accessToken; } public function getOnlineAccessInfo() { return $this->onlineAccessInfo; } public function setScope(string $scope): void { $this->scope = $scope; } public function setExpires($expires): void { $date = null; if ($expires) { if (is_string($expires)) { $date = new DateTime($expires); } elseif (is_numeric($expires)) { $date = new DateTime("@$expires"); } else { $date = $expires; } } $this->expires = $date; } public function setAccessToken(string $accessToken): void { $this->accessToken = $accessToken; } public function setOnlineAccessInfo(AccessTokenOnlineUserInfo $onlineAccessInfo): void { $this->onlineAccessInfo = $onlineAccessInfo; } public function clone(string $newSessionId): Session { $newSession = new Session($newSessionId, $this->shop, $this->isOnline, $this->state); $newSession->scope = $this->scope; $newSession->expires = $this->expires; $newSession->accessToken = $this->accessToken; $newSession->onlineAccessInfo = $this->onlineAccessInfo; return $newSession; } public function isValid(): bool { return (Context::$SCOPES->equals($this->scope) && $this->accessToken && (!$this->expires || ($this->expires > new DateTime())) ); } } 