File tree Expand file tree Collapse file tree 1 file changed +17
-13
lines changed
Expand file tree Collapse file tree 1 file changed +17
-13
lines changed Original file line number Diff line number Diff line change 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 }
You can’t perform that action at this time.
0 commit comments