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)
|
|
|
|
* @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
|
2015-11-09 15:39:42 -05:00
|
|
|
* @version 0.22
|
2015-09-26 21:03:55 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* model
|
|
|
|
*
|
2016-07-11 05:58:15 -04:00
|
|
|
* Factory of PrivateBin instance models.
|
2015-09-26 21:03:55 -04:00
|
|
|
*/
|
|
|
|
class model
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Configuration.
|
|
|
|
*
|
|
|
|
* @var configuration
|
|
|
|
*/
|
|
|
|
private $_conf;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data storage.
|
|
|
|
*
|
2016-07-11 05:58:15 -04:00
|
|
|
* @var privatebin_abstract
|
2015-09-26 21:03:55 -04:00
|
|
|
*/
|
|
|
|
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 model_paste
|
|
|
|
*/
|
|
|
|
public function getPaste($pasteId = null)
|
|
|
|
{
|
|
|
|
$paste = new model_paste($this->_conf, $this->_getStore());
|
|
|
|
if ($pasteId !== null) $paste->setId($pasteId);
|
|
|
|
return $paste;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets, and creates if neccessary, a store object
|
|
|
|
*/
|
|
|
|
private function _getStore()
|
|
|
|
{
|
|
|
|
if ($this->_store === null)
|
|
|
|
{
|
2016-07-11 05:58:15 -04:00
|
|
|
// added option to support old config file format
|
|
|
|
$model = str_replace(
|
|
|
|
'zerobin_', 'privatebin_',
|
|
|
|
$this->_conf->getKey('class', 'model')
|
|
|
|
);
|
2015-09-26 21:03:55 -04:00
|
|
|
$this->_store = forward_static_call(
|
2016-07-11 05:58:15 -04:00
|
|
|
array($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
|
|
|
}
|