1 | <?php |
||
16 | class ApiKey extends AbstractEntity |
||
17 | { |
||
18 | use StringUtilsTrait; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | * @ORM\Column(name="`key`", nullable=false, unique=true) |
||
23 | */ |
||
24 | protected $key; |
||
25 | /** |
||
26 | * @var \DateTime |
||
27 | * @ORM\Column(name="expiration_date", nullable=true, type="datetime") |
||
28 | */ |
||
29 | protected $expirationDate; |
||
30 | /** |
||
31 | * @var bool |
||
32 | * @ORM\Column(type="boolean") |
||
33 | */ |
||
34 | protected $enabled; |
||
35 | |||
36 | 11 | public function __construct() |
|
41 | |||
42 | /** |
||
43 | * @return string |
||
44 | */ |
||
45 | 2 | public function getKey() |
|
49 | |||
50 | /** |
||
51 | * @param string $key |
||
52 | * @return $this |
||
53 | */ |
||
54 | public function setKey($key) |
||
59 | |||
60 | /** |
||
61 | * @return \DateTime |
||
62 | */ |
||
63 | 4 | public function getExpirationDate() |
|
67 | |||
68 | /** |
||
69 | * @param \DateTime $expirationDate |
||
70 | * @return $this |
||
71 | */ |
||
72 | 2 | public function setExpirationDate($expirationDate) |
|
77 | |||
78 | /** |
||
79 | * @return bool |
||
80 | */ |
||
81 | 3 | public function isExpired() |
|
89 | |||
90 | /** |
||
91 | * @return boolean |
||
92 | */ |
||
93 | 7 | public function isEnabled() |
|
97 | |||
98 | /** |
||
99 | * @param boolean $enabled |
||
100 | * @return $this |
||
101 | */ |
||
102 | 3 | public function setEnabled($enabled) |
|
107 | |||
108 | /** |
||
109 | * Disables this API key |
||
110 | * |
||
111 | * @return $this |
||
112 | */ |
||
113 | 2 | public function disable() |
|
117 | |||
118 | /** |
||
119 | * Tells if this api key is enabled and not expired |
||
120 | * |
||
121 | * @return bool |
||
122 | */ |
||
123 | 5 | public function isValid() |
|
127 | |||
128 | /** |
||
129 | * The string repesentation of an API key is the key itself |
||
130 | * |
||
131 | * @return string |
||
132 | */ |
||
133 | public function __toString() |
||
137 | } |
||
138 |