2015-09-27 09:03:55 +08:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-11 17:58:15 +08:00
|
|
|
* PrivateBin
|
2015-09-27 09:03:55 +08:00
|
|
|
*
|
|
|
|
* a zero-knowledge paste bin
|
|
|
|
*
|
2016-07-11 17:58:15 +08:00
|
|
|
* @link https://github.com/PrivateBin/PrivateBin
|
2015-09-27 09:03:55 +08:00
|
|
|
* @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
|
2016-07-19 19:56:52 +08:00
|
|
|
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
|
2022-04-05 13:29:07 +08:00
|
|
|
* @version 1.4.0
|
2015-09-27 09:03:55 +08:00
|
|
|
*/
|
2016-12-13 01:43:23 +08:00
|
|
|
|
2016-12-13 01:50:00 +08:00
|
|
|
namespace PrivateBin;
|
2016-07-21 23:09:48 +08:00
|
|
|
|
2016-08-09 17:54:42 +08:00
|
|
|
use PrivateBin\Model\Paste;
|
|
|
|
use PrivateBin\Persistence\PurgeLimiter;
|
2016-07-21 23:09:48 +08:00
|
|
|
|
2015-09-27 09:03:55 +08:00
|
|
|
/**
|
2016-08-09 17:54:42 +08:00
|
|
|
* Model
|
2015-09-27 09:03:55 +08:00
|
|
|
*
|
2016-07-11 17:58:15 +08:00
|
|
|
* Factory of PrivateBin instance models.
|
2015-09-27 09:03:55 +08:00
|
|
|
*/
|
2016-08-09 17:54:42 +08:00
|
|
|
class Model
|
2015-09-27 09:03:55 +08:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Configuration.
|
|
|
|
*
|
2016-08-09 17:54:42 +08:00
|
|
|
* @var Configuration
|
2015-09-27 09:03:55 +08:00
|
|
|
*/
|
|
|
|
private $_conf;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data storage.
|
|
|
|
*
|
2018-11-19 20:07:25 +08:00
|
|
|
* @var Data\AbstractData
|
2015-09-27 09:03:55 +08:00
|
|
|
*/
|
|
|
|
private $_store = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Factory constructor.
|
|
|
|
*
|
|
|
|
* @param configuration $conf
|
|
|
|
*/
|
2016-08-09 17:54:42 +08:00
|
|
|
public function __construct(Configuration $conf)
|
2015-09-27 09:03:55 +08:00
|
|
|
{
|
|
|
|
$this->_conf = $conf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a paste, optionally a specific instance.
|
|
|
|
*
|
|
|
|
* @param string $pasteId
|
2016-08-09 17:54:42 +08:00
|
|
|
* @return Paste
|
2015-09-27 09:03:55 +08:00
|
|
|
*/
|
|
|
|
public function getPaste($pasteId = null)
|
|
|
|
{
|
2021-06-08 13:49:22 +08:00
|
|
|
$paste = new Paste($this->_conf, $this->getStore());
|
2016-07-26 14:19:35 +08:00
|
|
|
if ($pasteId !== null) {
|
|
|
|
$paste->setId($pasteId);
|
|
|
|
}
|
2015-09-27 09:03:55 +08:00
|
|
|
return $paste;
|
|
|
|
}
|
|
|
|
|
2016-07-15 23:02:59 +08:00
|
|
|
/**
|
|
|
|
* Checks if a purge is necessary and triggers it if yes.
|
|
|
|
*/
|
|
|
|
public function purge()
|
|
|
|
{
|
2016-08-09 17:54:42 +08:00
|
|
|
PurgeLimiter::setConfiguration($this->_conf);
|
2021-06-08 13:49:22 +08:00
|
|
|
PurgeLimiter::setStore($this->getStore());
|
2016-08-09 17:54:42 +08:00
|
|
|
if (PurgeLimiter::canPurge()) {
|
2021-06-08 13:49:22 +08:00
|
|
|
$this->getStore()->purge($this->_conf->getKey('batchsize', 'purge'));
|
2016-07-15 23:02:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-27 09:03:55 +08:00
|
|
|
/**
|
|
|
|
* Gets, and creates if neccessary, a store object
|
2016-07-15 23:02:59 +08:00
|
|
|
*
|
2018-11-19 20:07:25 +08:00
|
|
|
* @return Data\AbstractData
|
2015-09-27 09:03:55 +08:00
|
|
|
*/
|
2021-06-08 13:49:22 +08:00
|
|
|
public function getStore()
|
2015-09-27 09:03:55 +08:00
|
|
|
{
|
2016-07-26 14:19:35 +08:00
|
|
|
if ($this->_store === null) {
|
2022-11-01 23:38:06 +08:00
|
|
|
$class = 'PrivateBin\\Data\\' . $this->_conf->getKey('class', 'model');
|
2022-10-28 07:01:02 +08:00
|
|
|
$this->_store = new $class($this->_conf->getSection('model_options'));
|
2015-09-27 09:03:55 +08:00
|
|
|
}
|
|
|
|
return $this->_store;
|
|
|
|
}
|
2016-07-11 17:58:15 +08:00
|
|
|
}
|