36 lines
1.2 KiB
PHP
36 lines
1.2 KiB
PHP
<?php
|
|
namespace EEPROM\Blacklist;
|
|
|
|
use InvalidArgumentException;
|
|
use Index\Data\DbStatementCache;
|
|
use Index\Data\IDbConnection;
|
|
|
|
class BlacklistData {
|
|
private DbStatementCache $cache;
|
|
|
|
public function __construct(IDbConnection $dbConn) {
|
|
$this->cache = new DbStatementCache($dbConn);
|
|
}
|
|
|
|
public function getBlacklistEntry(string $hash): ?BlacklistInfo {
|
|
$stmt = $this->cache->get('SELECT bl_hash, bl_reason, UNIX_TIMESTAMP(bl_created) FROM prm_blacklist WHERE bl_hash = ?');
|
|
$stmt->addParameter(1, $hash);
|
|
$stmt->execute();
|
|
|
|
$result = $stmt->getResult();
|
|
return $result->next() ? new BlacklistInfo($result) : null;
|
|
}
|
|
|
|
public function createBlacklistEntry(string $hash, string $reason): void {
|
|
if(strlen($hash) !== 32)
|
|
throw new InvalidArgumentException('$hash must be 32 bytes.');
|
|
if(!in_array($reason, BlacklistInfo::REASONS))
|
|
throw new InvalidArgumentException('$reason is not a valid reason.');
|
|
|
|
$stmt = $this->cache->get('INSERT INTO prm_blacklist (bl_hash, bl_reason) VALUES (?, ?)');
|
|
$stmt->addParameter(1, $hash);
|
|
$stmt->addParameter(2, $reason);
|
|
$stmt->execute();
|
|
}
|
|
}
|