Session.php
1.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace Lackoxygen\TiktokShop\Supervisor\Session;
use Carbon\Carbon;
use Lackoxygen\TiktokShop\Contracts\SessionInterface;
class Session implements SessionInterface
{
use Swap;
protected Store $store;
protected string $index = '';
protected string $appKey = '';
public function __construct(string $appKey, Store $store)
{
$this->appKey = $appKey;
$this->store = $store;
$this->index = $this->id();
}
public function id(): string
{
return md5(serialize($this->store));
}
public function unEffective(): bool
{
return !$this->effective();
}
public function effective(): bool
{
return $this->store->getExpiredAt()->gt(Carbon::now());
}
public function discard()
{
$this->store->setExpiredAt(Carbon::now()->subMinutes(30));
}
public function watch(): bool
{
return $this->index !== $this->id();
}
public function appKey(): string
{
return $this->appKey;
}
}