1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
4
|
|
|
|
5
|
|
|
declare(strict_types=1); |
6
|
|
|
|
7
|
|
|
namespace Chamilo\LtiBundle\Entity; |
8
|
|
|
|
9
|
|
|
use Doctrine\ORM\Mapping as ORM; |
10
|
|
|
|
11
|
|
|
#[ORM\Table(name: 'lti_token')] |
12
|
|
|
#[ORM\Entity] |
13
|
|
|
class Token |
14
|
|
|
{ |
15
|
|
|
public const TOKEN_LIFETIME = 3600; |
16
|
|
|
|
17
|
|
|
#[ORM\Column(name: 'id', type: 'integer')] |
18
|
|
|
#[ORM\Id] |
19
|
|
|
#[ORM\GeneratedValue] |
20
|
|
|
protected ?int $id = null; |
21
|
|
|
#[ORM\ManyToOne(targetEntity: ExternalTool::class)] |
22
|
|
|
#[ORM\JoinColumn(name: 'tool_id', referencedColumnName: 'id', onDelete: 'CASCADE')] |
23
|
|
|
private ExternalTool $tool; |
24
|
|
|
#[ORM\Column(name: 'scope', type: 'json')] |
25
|
|
|
private array $scope; |
26
|
|
|
#[ORM\Column(name: 'hash', type: 'string')] |
27
|
|
|
private string $hash; |
28
|
|
|
#[ORM\Column(name: 'created_at', type: 'integer')] |
29
|
|
|
private int $createdAt; |
30
|
|
|
#[ORM\Column(name: 'expires_at', type: 'integer')] |
31
|
|
|
private int $expiresAt; |
32
|
|
|
|
33
|
|
|
public function getId(): int |
34
|
|
|
{ |
35
|
|
|
return $this->id; |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getTool(): ExternalTool |
39
|
|
|
{ |
40
|
|
|
return $this->tool; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function setTool(ExternalTool $tool): static |
44
|
|
|
{ |
45
|
|
|
$this->tool = $tool; |
46
|
|
|
|
47
|
|
|
return $this; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getScope(): array |
51
|
|
|
{ |
52
|
|
|
return $this->scope; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function setScope(array $scope): static |
56
|
|
|
{ |
57
|
|
|
$this->scope = $scope; |
58
|
|
|
|
59
|
|
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getHash(): string |
63
|
|
|
{ |
64
|
|
|
return $this->hash; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function setHash(string $hash): static |
68
|
|
|
{ |
69
|
|
|
$this->hash = $hash; |
70
|
|
|
|
71
|
|
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getCreatedAt(): int |
75
|
|
|
{ |
76
|
|
|
return $this->createdAt; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function setCreatedAt(int $createdAt): static |
80
|
|
|
{ |
81
|
|
|
$this->createdAt = $createdAt; |
82
|
|
|
|
83
|
|
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function getExpiresAt(): int |
87
|
|
|
{ |
88
|
|
|
return $this->expiresAt; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function setExpiresAt(int $expiresAt): static |
92
|
|
|
{ |
93
|
|
|
$this->expiresAt = $expiresAt; |
94
|
|
|
|
95
|
|
|
return $this; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function getScopeInString(): string |
99
|
|
|
{ |
100
|
|
|
return implode(' ', $this->scope); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function generateHash(): static |
104
|
|
|
{ |
105
|
|
|
$this->hash = sha1(uniqid((string) random_int(0, mt_getrandmax()))); |
106
|
|
|
|
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|