folding Persistance\PurgeLimiter into Data\Filesystem
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
namespace PrivateBin\Persistence;
|
||||
|
||||
use Exception;
|
||||
use PrivateBin\Data\AbstractData;
|
||||
|
||||
/**
|
||||
* AbstractPersistence
|
||||
@@ -30,6 +31,15 @@ abstract class AbstractPersistence
|
||||
*/
|
||||
private static $_path = 'data';
|
||||
|
||||
/**
|
||||
* data storage to use to persist something
|
||||
*
|
||||
* @access private
|
||||
* @static
|
||||
* @var AbstractData
|
||||
*/
|
||||
protected static $_store;
|
||||
|
||||
/**
|
||||
* set the path
|
||||
*
|
||||
@@ -42,6 +52,18 @@ abstract class AbstractPersistence
|
||||
self::$_path = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the path
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @param AbstractData $store
|
||||
*/
|
||||
public static function setStore(AbstractData $store)
|
||||
{
|
||||
self::$_store = $store;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the path
|
||||
*
|
||||
|
||||
@@ -71,17 +71,11 @@ class PurgeLimiter extends AbstractPersistence
|
||||
}
|
||||
|
||||
$now = time();
|
||||
$file = 'purge_limiter.php';
|
||||
if (self::_exists($file)) {
|
||||
require self::getPath($file);
|
||||
$pl = $GLOBALS['purge_limiter'];
|
||||
if ($pl + self::$_limit >= $now) {
|
||||
return false;
|
||||
}
|
||||
$pl = (int) self::$_store->getValue('purge_limiter');
|
||||
if ($pl + self::$_limit >= $now) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$content = '<?php' . PHP_EOL . '$GLOBALS[\'purge_limiter\'] = ' . $now . ';';
|
||||
self::_store($file, $content);
|
||||
self::$_store->setValue((string) $now, 'purge_limiter');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user