PrivateBin/lib/Persistence/PurgeLimiter.php

80 lines
1.7 KiB
PHP
Raw Normal View History

<?php
/**
* PrivateBin
*
* a zero-knowledge paste bin
*
* @link https://github.com/PrivateBin/PrivateBin
* @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
2021-04-05 22:44:12 +08:00
* @version 1.3.5
*/
2016-12-13 01:43:23 +08:00
2016-12-13 01:49:08 +08:00
namespace PrivateBin\Persistence;
use PrivateBin\Configuration;
2016-07-21 23:09:48 +08:00
/**
* PurgeLimiter
*
* Handles purge limiting, so purging is not triggered too frequently.
*/
class PurgeLimiter extends AbstractPersistence
{
/**
* time limit in seconds, defaults to 300s
*
* @access private
* @static
* @var int
*/
private static $_limit = 300;
/**
* set the time limit in seconds
*
* @access public
* @static
* @param int $limit
*/
public static function setLimit($limit)
{
self::$_limit = $limit;
}
/**
* set configuration options of the traffic limiter
*
* @access public
* @static
* @param Configuration $conf
*/
public static function setConfiguration(Configuration $conf)
{
self::setLimit($conf->getKey('limit', 'purge'));
}
/**
* check if the purge can be performed
*
* @access public
* @static
* @return bool
*/
public static function canPurge()
{
// disable limits if set to less then 1
if (self::$_limit < 1) {
return true;
}
2018-07-29 22:05:57 +08:00
$now = time();
$pl = (int) self::$_store->getValue('purge_limiter');
if ($pl + self::$_limit >= $now) {
return false;
}
self::$_store->setValue((string) $now, 'purge_limiter');
2018-07-29 22:05:57 +08:00
return true;
}
}