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