Skip to content

Commit 72a1dd0

Browse files
committed
refactor to use Db class
1 parent a03bfea commit 72a1dd0

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

lib/IpAttempts.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
<?php
22
namespace Pdsinterop\PhpSolid;
3-
4-
class IpAttempts {
5-
private static $pdo;
6-
private static function connect() {
7-
if (!isset(self::$pdo)) {
8-
self::$pdo = new \PDO("sqlite:" . DBPATH);
9-
}
10-
}
113

4+
use Pdsinterop\PhpSolid\Db;
5+
6+
class IpAttempts {
127
public static function logFailedAttempt($ip, $type, $expires) {
138
if (in_array($ip, TRUSTED_IPS)) {
149
return;
1510
}
1611

17-
self::connect();
12+
Db::connect();
1813

19-
$query = self::$pdo->prepare(
14+
$query = Db::$pdo->prepare(
2015
'INSERT INTO ipAttempts VALUES(:ip, :type, :expires)'
2116
);
2217
$query->execute([
@@ -31,10 +26,10 @@ public static function getAttemptsCount($ip, $type) {
3126
return 0;
3227
}
3328

34-
self::connect();
29+
Db::connect();
3530

3631
$now = new \DateTime();
37-
$query = self::$pdo->prepare(
32+
$query = Db::$pdo->prepare(
3833
'SELECT count(ip) as count FROM ipAttempts WHERE ip=:ip AND type=:type AND expires > :now'
3934
);
4035
$query->execute([
@@ -49,10 +44,10 @@ public static function getAttemptsCount($ip, $type) {
4944
return 0;
5045
}
5146
public static function cleanupAttempts() {
52-
self::connect();
47+
Db::connect();
5348

5449
$now = new \DateTime();
55-
$query = self::$pdo->prepare(
50+
$query = Db::$pdo->prepare(
5651
'DELETE FROM ipAttempts WHERE expires < :now'
5752
);
5853
$query->execute([

0 commit comments

Comments
 (0)