Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
16 / 16 |
Model | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
7 | |
100.00% |
16 / 16 |
__construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
getPaste | |
100.00% |
1 / 1 |
2 | |
100.00% |
4 / 4 |
|||
purge | |
100.00% |
1 / 1 |
2 | |
100.00% |
5 / 5 |
|||
getStore | |
100.00% |
1 / 1 |
2 | |
100.00% |
5 / 5 |
<?php | |
/** | |
* PrivateBin | |
* | |
* a zero-knowledge paste bin | |
* | |
* @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 | |
* @version 1.4.0 | |
*/ | |
namespace PrivateBin; | |
use PrivateBin\Model\Paste; | |
use PrivateBin\Persistence\PurgeLimiter; | |
/** | |
* Model | |
* | |
* Factory of PrivateBin instance models. | |
*/ | |
class Model | |
{ | |
/** | |
* Configuration. | |
* | |
* @var Configuration | |
*/ | |
private $_conf; | |
/** | |
* Data storage. | |
* | |
* @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 | |
* | |
* @return Data\AbstractData | |
*/ | |
public 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; | |
} | |
} |