Skip to content

Commit 6f9acd1

Browse files
committed
use db class, add cleanup
1 parent 72a1dd0 commit 6f9acd1

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

lib/JtiStore.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
<?php
22
namespace Pdsinterop\PhpSolid;
3-
3+
4+
use Pdsinterop\PhpSolid\Db;
45
class JtiStore {
5-
private static $pdo;
6-
private static function connect() {
7-
if (!isset(self::$pdo)) {
8-
self::$pdo = new \PDO("sqlite:" . DBPATH);
9-
}
10-
}
11-
126
public static function hasJti($jti) {
13-
self::connect();
7+
Db::connect();
148
$now = new \DateTime();
15-
16-
$query = self::$pdo->prepare(
9+
$query = Db::$pdo->prepare(
1710
'SELECT jti FROM jti WHERE jti=:jti AND expires>:now'
1811
);
1912
$query->execute([
@@ -28,8 +21,8 @@ public static function hasJti($jti) {
2821
}
2922

3023
public static function saveJti($jti) {
31-
self::connect();
32-
$query = self::$pdo->prepare(
24+
Db::connect();
25+
$query = Db::$pdo->prepare(
3326
'INSERT INTO jti VALUES(:jti, :expires)'
3427
);
3528
$expires = new \DateTime();
@@ -39,4 +32,15 @@ public static function saveJti($jti) {
3932
':expires' => $expires->getTimestamp()
4033
]);
4134
}
35+
36+
public static function cleanupJti() {
37+
Db::connect();
38+
$now = new \DateTime();
39+
$query = Db::$pdo->prepare(
40+
'DELETE FROM jti WHERE expires < :now'
41+
);
42+
$query->execute([
43+
':now' => $now->getTimestamp()
44+
]);
45+
}
4246
}

0 commit comments

Comments
 (0)