PrivateBin/lib/Model.php

95 lines
2.0 KiB
PHP
Raw Normal View History

<?php
/**
2016-07-11 05:58:15 -04:00
* PrivateBin
*
* a zero-knowledge paste bin
*
2016-07-11 05:58:15 -04:00
* @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
2016-08-25 03:53:31 -04:00
* @version 1.0
*/
2016-07-21 11:09:48 -04:00
namespace PrivateBin;
use PrivateBin\Data;
use PrivateBin\Model\Paste;
use PrivateBin\Persistence\PurgeLimiter;
2016-07-21 11:09:48 -04:00
/**
* Model
*
2016-07-11 05:58:15 -04:00
* Factory of PrivateBin instance models.
*/
class Model
{
/**
* Configuration.
*
* @var Configuration
*/
private $_conf;
/**
* Data storage.
*
* @var AbstractData
*/
private $_store = null;
/**
* Factory constructor.
*
* @param configuration $conf
* @return void
*/
public function __construct(Configuration $conf)
{
$this->_conf = $conf;
}
/**
* Get a paste, optionally a specific instance.
*
* @param string $pasteId
* @return Paste
*/
public function getPaste($pasteId = null)
{
$paste = new Paste($this->_conf, $this->_getStore());
if ($pasteId !== null) {
$paste->setId($pasteId);
}
return $paste;
}
/**
* Checks if a purge is necessary and triggers it if yes.
*
* @return void
*/
public function purge()
{
PurgeLimiter::setConfiguration($this->_conf);
if (PurgeLimiter::canPurge()) {
$this->_getStore()->purge($this->_conf->getKey('batchsize', 'purge'));
}
}
/**
* Gets, and creates if neccessary, a store object
*
* @return AbstractData
*/
private function _getStore()
{
if ($this->_store === null) {
$this->_store = forward_static_call(
'PrivateBin\\Data\\' . $this->_conf->getKey('class', 'model') . '::getInstance',
$this->_conf->getSection('model_options')
);
}
return $this->_store;
}
2016-07-11 05:58:15 -04:00
}