paste.chapril.org-privatebin/lib/Model.php

90 lines
1.9 KiB
PHP
Raw Permalink Normal View History

<?php
/**
2016-07-11 11:58:15 +02:00
* PrivateBin
*
* a zero-knowledge paste bin
*
2016-07-11 11:58:15 +02: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
2024-05-05 20:43:33 +02:00
* @version 1.7.2
*/
2016-12-12 18:43:23 +01:00
2016-12-12 18:50:00 +01:00
namespace PrivateBin;
2016-07-21 17:09:48 +02:00
use PrivateBin\Model\Paste;
use PrivateBin\Persistence\PurgeLimiter;
2016-07-21 17:09:48 +02:00
/**
* Model
*
2016-07-11 11:58:15 +02:00
* Factory of PrivateBin instance models.
*/
class Model
{
/**
* Configuration.
*
* @var Configuration
*/
private $_conf;
/**
* Data storage.
*
2018-11-19 13:07:25 +01:00
* @var Data\AbstractData
*/
private $_store = null;
/**
* Factory constructor.
*
* @param configuration $conf
*/
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.
*/
public function purge()
{
PurgeLimiter::setConfiguration($this->_conf);
PurgeLimiter::setStore($this->getStore());
if (PurgeLimiter::canPurge()) {
$this->getStore()->purge($this->_conf->getKey('batchsize', 'purge'));
}
}
/**
* Gets, and creates if neccessary, a store object
*
2018-11-19 13:07:25 +01:00
* @return Data\AbstractData
*/
public function getStore()
{
if ($this->_store === null) {
2022-11-01 16:38:06 +01:00
$class = 'PrivateBin\\Data\\' . $this->_conf->getKey('class', 'model');
$this->_store = new $class($this->_conf->getSection('model_options'));
}
return $this->_store;
}
2016-07-11 11:58:15 +02:00
}